def test_construction(self): polyline = Polyline(name="test line") with self.assertRaises(IndexError): polyline.isClosed() self.assertEqual(polyline.getName(), "test line") self.assertEqual(len(polyline), 0) polyline.addPoint(0, 0, 0) self.assertEqual(len(polyline), 1) polyline.addPoint(1, 1, 0) self.assertEqual(len(polyline), 2) polyline.addPoint(1, 1.5) self.assertEqual(len(polyline), 3) self.assertEqual(polyline[0], (0, 0, 0)) self.assertEqual(polyline[1], (1, 1, 0)) self.assertEqual(polyline[2], (1, 1.5)) polyline.addPoint(0, 1, 0) self.assertFalse(polyline.isClosed()) polyline.addPoint(0, 0, 0) self.assertTrue(polyline.isClosed())
def getEdgePolygon(self): x_list = DoubleVector() y_list = DoubleVector() cell_list = IntVector() self._trace_edge(x_list, y_list, cell_list) p = Polyline() for (x, y) in zip(x_list, y_list): p.addPoint(x, y) return p
def test_iteration(self): values = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 1)] polyline = Polyline(name="iteration line") for p in values: polyline.addPoint(*p) for index, point in enumerate(polyline): self.assertEqual(point, values[index])
def test_closed(self): pl = Polyline(init_points=[(1, 0), (1, 1), (0, 2)]) self.assertFalse(pl.isClosed()) pl.addPoint(1, 0) self.assertEqual(4, len(pl)) self.assertTrue(pl.isClosed()) pl = Polyline(init_points=[(1, 0), (1, 1), (0, 2)]) self.assertFalse(pl.isClosed()) pl.assertClosed() self.assertEqual(4, len(pl)) self.assertTrue(pl.isClosed())