From 4a13cc0173d26390dabbe01b7fc4988b8096ca65 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 5 Jul 2017 16:51:34 -0500 Subject: [PATCH 01/30] a tester for the linegroup class --- unittest2.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 unittest2.py diff --git a/unittest2.py b/unittest2.py new file mode 100644 index 0000000..b1ec28b --- /dev/null +++ b/unittest2.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Jul 5 15:50:23 2017 + +@author: siddhant +""" + +import unittest +from point import Point +from line import Line +from linegroup import LineGroup +#import constants as c +import numpy as np + +p1 = Point(1.0, 2.0, 3.0) +p2 = Point(2.0, 4.0, 6.0) +p3 = Point(6.0, 12.0, 18.0) +p4 = Point(8.0, 12.0, 14.0) + +l1 = Line(p1, p2) +l2 = Line(p1, p3) +l4 = Line(Point(0,0), Point(0, 8, 0)) +l5 = Line(Point(4, 0, 0), Point(0, 6, 0)) + +lg1 = LineGroup() +lg2 = LineGroup() +lg2.append(l1) + + +class LineGroupTestCase(unittest.TestCase): + + def test_linegroup_getitem(self): + """ checks if correct line in linegroup is returned """ + self.assertTrue(lg2[0] == l1) + + def test_linegroup_append(self): + """ checks if correct line is appended to linegroup """ + lg2.append(l2) + self.assertTrue(lg2[1] == l2) + + #print(lg2) + + def test_linegroup_remove(self): + lg2.append(l2) + lg2.remove(l1) + self.assertTrue(lg2[0] == l2) + +# def test_linegroup_length(self): +# self.assertTrue(lg2.__len__ == 1) + + def test_linegroup_pop(self): + """ checks if correct line returned when linegroup popped """ + lg2.append(l2) + self.assertTrue(lg2.pop() == l2) + + #print(lg2) + + def test_linegroup_midpoint(self): + """ checks if correct midpoint of linegroup returned """ + self.assertTrue(lg2.getMidPoint() == Point(3.5, 7.0, 0.0)) + + #print(lg2) + #print(lg1) + + def test_linegroup_add_linegroup(self): + """ checks if linegroup is correctly added """ + lg1.append(l2) + lg2.addLineGroup(lg1) + self.assertTrue(lg2[1] == l2) + + #print(lg2) + print(lg2) + #vectors + #starts (numpy.ndarray issue) + +# def test_linegroup_add_linesfrompoints(self): +# """ checks if line is correctly added """ +# lg2.addLinesFromPoints([Point(-4, -6, 8), Point(2, 4, 6)]) +# print(lg2) +# self.assertTrue(lg2[2] == Line(Point(-4, -6, 8), Point(2, 4, 6))) + + # def test_linegroup_pop(self): +# """ checks if correct line is returned when popped """ +# self.assertTrue(lg1.pop() == l1) + + + +def main(): + unittest.main() + +if __name__ == '__main__': + main() \ No newline at end of file From a2c407aa5c97a1aff5f8ab73f522335c0ccf9008 Mon Sep 17 00:00:00 2001 From: "ENGR\\siddhant" Date: Thu, 6 Jul 2017 16:55:22 -0500 Subject: [PATCH 02/30] tests added for linegroup --- unittest2.py | 148 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 119 insertions(+), 29 deletions(-) diff --git a/unittest2.py b/unittest2.py index b1ec28b..057aabe 100644 --- a/unittest2.py +++ b/unittest2.py @@ -9,7 +9,7 @@ from point import Point from line import Line from linegroup import LineGroup -#import constants as c +import constants as c import numpy as np p1 = Point(1.0, 2.0, 3.0) @@ -30,58 +30,148 @@ class LineGroupTestCase(unittest.TestCase): def test_linegroup_getitem(self): - """ checks if correct line in linegroup is returned """ + """ checks if correct line in linegroup is returned (__getitem__) """ + lg1.append(l1) self.assertTrue(lg2[0] == l1) def test_linegroup_append(self): - """ checks if correct line is appended to linegroup """ + """ checks if correct line is appended to linegroup (append) """ lg2.append(l2) + #print(lg1) self.assertTrue(lg2[1] == l2) - - #print(lg2) def test_linegroup_remove(self): + """ checks if line is correctly removed from group (remove) """ lg2.append(l2) lg2.remove(l1) + #print(lg2) self.assertTrue(lg2[0] == l2) -# def test_linegroup_length(self): -# self.assertTrue(lg2.__len__ == 1) - + def test_linegroup_length(self): + """ checks if linegroup contains expected number of lines (__len__) """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + ltest.append(l4) + count = 0 + for l in ltest: + count = count + 1 + self.assertEqual(count, 3) + def test_linegroup_pop(self): - """ checks if correct line returned when linegroup popped """ + """ checks if correct line returned when linegroup popped (pop) """ lg2.append(l2) self.assertTrue(lg2.pop() == l2) - #print(lg2) - def test_linegroup_midpoint(self): - """ checks if correct midpoint of linegroup returned """ + """ checks if correct midpoint of linegroup returned (getMidPoint) """ + #print(lg2) self.assertTrue(lg2.getMidPoint() == Point(3.5, 7.0, 0.0)) - - #print(lg2) - #print(lg1) - + def test_linegroup_add_linegroup(self): - """ checks if linegroup is correctly added """ + """ checks if linegroup is correctly added (addLineGroup) """ lg1.append(l2) lg2.addLineGroup(lg1) self.assertTrue(lg2[1] == l2) - #print(lg2) - print(lg2) + def test_linegroup_mirror(self): + """ checks if linegroup is correctly mirrored (mirror) """ + ltest = LineGroup() + ltest.append(l1) + + ltest1 = LineGroup() + ltest1.append(Line(Point(1,-2,3), Point(2,-4,6))) + + self.assertTrue(ltest.mirror(c.X)[0] == ltest1[0]) + + def test_linegroup_sort(self): + """ checks if linegroup is sorted correctly (sort) """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l4) + ltest.sort() + self.assertTrue(ltest[0] == l4) + + def test_linegroup_fourcorners(self): + """ checks if the four corners correspond to the correct points """ + ltest = LineGroup() + ltest.append(l4) + ltest.append(l5) + self.assertTrue(ltest.fourCorners()[0] == Point(0,0,0)) + self.assertTrue(ltest.fourCorners()[1] == Point(4,0,0)) + self.assertTrue(ltest.fourCorners()[2] == Point(4,8,0)) + self.assertTrue(ltest.fourCorners()[3] == Point(0,8,0)) + + def test_linegroup_scale(self): + """ checks if start and end points of lines are scaled correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + + self.assertTrue(ltest.scale(2,3)[0] == + Line(Point(2,6,3), Point(4,12,6))) + self.assertTrue(ltest.scale(2,3)[1] == + Line(Point(2,6,3), Point(12,36,18))) + + def test_linegroup_rotate(self): + """ checks if linegroup is rotated correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest.rotate(np.pi/2)[0] == + Line(Point(-2,1,3), Point(-4,2,6))) + self.assertTrue(ltest.rotate(np.pi/2)[1] == + Line(Point(-2,1,3), Point(-12,6,18))) + + def test_linegroup_translate(self): + """ checks if linegroup is translated correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest.translate(2,4)[0] == + Line(Point(3,6,3), Point(4,8,6))) + self.assertTrue(ltest.translate(2,4)[1] == + Line(Point(3,6,3), Point(8,16,18))) + + def test_linegroup_line_outside_boundingbox(self): + """ checks if the given line is outside the bounding box """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest.lineOutsideBoundingBox(l4) == True) + + def test_linegroup_line_add_points(self): + """ checks if line from given points is added to linegroup """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + p = [Point(1,1,0), Point(4,5,0)] + ltest.addLinesFromPoints(p) + self.assertTrue(ltest[2] == Line(Point(1,1,0), Point(4,5,0))) + + def test_linegroup_update_min_max(self): + """ checks if the max & min x and y values are updated correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + l = Line(Point(10,20,0), Point(14,-16,0)) + ltest.append(l) + self.assertTrue(ltest.maxY == 20) + self.assertTrue(ltest.maxX == 14) + self.assertTrue(ltest.minY == -16) + self.assertTrue(ltest.minX == 1) + + def test_linegroup_line_add_coordlist(self): + """ checks if points from coordinate list added to linegroup """ + ltest = LineGroup() + ltest.append(l1) + k = [[3,4], [-6,7]] + ltest.addLinesFromCoordinateList(k) + self.assertTrue(ltest[1] == Line(Point(3,4,0), Point(-6,7,0))) + #vectors #starts (numpy.ndarray issue) - -# def test_linegroup_add_linesfrompoints(self): -# """ checks if line is correctly added """ -# lg2.addLinesFromPoints([Point(-4, -6, 8), Point(2, 4, 6)]) -# print(lg2) -# self.assertTrue(lg2[2] == Line(Point(-4, -6, 8), Point(2, 4, 6))) - - # def test_linegroup_pop(self): -# """ checks if correct line is returned when popped """ -# self.assertTrue(lg1.pop() == l1) + From b7767ac6fc26f2a9a02012417dc94f97da232a1a Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Fri, 7 Jul 2017 16:51:40 -0500 Subject: [PATCH 03/30] Rectified issues in linegroup --- unittest2.py | 63 ++++++++++++++++++++++++++++++++-------------------- unittest3.py | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 24 deletions(-) create mode 100644 unittest3.py diff --git a/unittest2.py b/unittest2.py index 057aabe..297d825 100644 --- a/unittest2.py +++ b/unittest2.py @@ -22,30 +22,33 @@ l4 = Line(Point(0,0), Point(0, 8, 0)) l5 = Line(Point(4, 0, 0), Point(0, 6, 0)) -lg1 = LineGroup() -lg2 = LineGroup() -lg2.append(l1) +#lg1 = LineGroup() +#lg2 = LineGroup() +#lg2.append(l1) class LineGroupTestCase(unittest.TestCase): def test_linegroup_getitem(self): """ checks if correct line in linegroup is returned (__getitem__) """ - lg1.append(l1) - self.assertTrue(lg2[0] == l1) + ltest = LineGroup() + ltest.append(l1) + self.assertTrue(ltest[0] == l1) def test_linegroup_append(self): """ checks if correct line is appended to linegroup (append) """ - lg2.append(l2) - #print(lg1) - self.assertTrue(lg2[1] == l2) + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest[1] == l2) def test_linegroup_remove(self): """ checks if line is correctly removed from group (remove) """ - lg2.append(l2) - lg2.remove(l1) - #print(lg2) - self.assertTrue(lg2[0] == l2) + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + ltest.remove(l1) + self.assertTrue(ltest[0] == l2) def test_linegroup_length(self): """ checks if linegroup contains expected number of lines (__len__) """ @@ -60,19 +63,27 @@ def test_linegroup_length(self): def test_linegroup_pop(self): """ checks if correct line returned when linegroup popped (pop) """ - lg2.append(l2) - self.assertTrue(lg2.pop() == l2) + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest.pop() == l2) def test_linegroup_midpoint(self): """ checks if correct midpoint of linegroup returned (getMidPoint) """ #print(lg2) - self.assertTrue(lg2.getMidPoint() == Point(3.5, 7.0, 0.0)) + ltest = LineGroup() + ltest.append(l1) + self.assertTrue(ltest.getMidPoint() == Point(1.5, 3.0, 0.0)) def test_linegroup_add_linegroup(self): """ checks if linegroup is correctly added (addLineGroup) """ - lg1.append(l2) - lg2.addLineGroup(lg1) - self.assertTrue(lg2[1] == l2) + ltest = LineGroup() + ltest.append(l1) + + ltest1 = LineGroup() + ltest1.append(l2) + ltest.addLineGroup(ltest1) + self.assertTrue(ltest[1] == l2) def test_linegroup_mirror(self): """ checks if linegroup is correctly mirrored (mirror) """ @@ -168,12 +179,16 @@ def test_linegroup_line_add_coordlist(self): k = [[3,4], [-6,7]] ltest.addLinesFromCoordinateList(k) self.assertTrue(ltest[1] == Line(Point(3,4,0), Point(-6,7,0))) - - #vectors - #starts (numpy.ndarray issue) - - - + + def test_linegroup_transform(self): + """ checks if lines within group are transfromed correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + matr = [[0,0,0,1], [1,4,6,8], [0,6,7,9], [3,4,5,6]] + ltest = ltest.transform(matr) + self.assertTrue(ltest[0] == Line(Point(1,35,42),Point(1,62,75))) + self.assertTrue(ltest[1] == Line(Point(1,35,42), Point(1,170,207))) def main(): unittest.main() diff --git a/unittest3.py b/unittest3.py new file mode 100644 index 0000000..ff4fd29 --- /dev/null +++ b/unittest3.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Jul 7 14:33:12 2017 + +@author: siddhant +""" + +import unittest +from point import Point +from line import Line +from linegroup import LineGroup +from arc import Arc +import matrixTrans as mt +import constants as c +import math +import numpy as np +#from shapely.geometry.polygon import Polygon +#from shapely.ops import cascaded_union +#from outline import Outline + +class ArcTestCase(unittest.TestCase): + + def test_arc_calc_inner_angle(self): + """ checks if inner angle between given points is correct """ + a = Arc(Point(1,1,0), Point(4,4,0), c.X, Point(1,3,0)) + ang = a.calcIncludedAngle(Point(1,1,0), Point(4,4,0)) + self.assertAlmostEqual(ang, 4.2426, 4) + +# def test_ok(self): +# pass +#class MatrixTestCase(unittest.TestCase): +# +# def test_matrix_translate(self): +# +# m = np.arange(1,17).reshape(4,4) +# print(m.t) + +def main(): + unittest.main() + +if __name__ == '__main__': + main() + + + From 5b667de4fa82ae54611b016ef0b67890cedf10f3 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Mon, 10 Jul 2017 16:26:01 -0500 Subject: [PATCH 04/30] Added tests for matrix transformations --- unittest3.py | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/unittest3.py b/unittest3.py index ff4fd29..903dad1 100644 --- a/unittest3.py +++ b/unittest3.py @@ -7,13 +7,13 @@ import unittest from point import Point -from line import Line -from linegroup import LineGroup +#from line import Line +#from linegroup import LineGroup from arc import Arc import matrixTrans as mt import constants as c -import math -import numpy as np +#import math +#import numpy as np #from shapely.geometry.polygon import Polygon #from shapely.ops import cascaded_union #from outline import Outline @@ -26,14 +26,40 @@ def test_arc_calc_inner_angle(self): ang = a.calcIncludedAngle(Point(1,1,0), Point(4,4,0)) self.assertAlmostEqual(ang, 4.2426, 4) -# def test_ok(self): -# pass -#class MatrixTestCase(unittest.TestCase): -# -# def test_matrix_translate(self): -# -# m = np.arange(1,17).reshape(4,4) -# print(m.t) +class MatrixTestCase(unittest.TestCase): + + def test_matrix_mirror(self): + """ checks if the matrix is mirrored correctly about given axis """ + self.assertTrue(tuple(mt.mirrorMatrix(c.X)[0]) == (1,0,0,0)) + self.assertTrue(tuple(mt.mirrorMatrix(c.X)[1]) == (0,-1,0,0)) + self.assertTrue(tuple(mt.mirrorMatrix(c.X)[2]) == (0,0,1,0)) + self.assertTrue(tuple(mt.mirrorMatrix(c.X)[3]) == (0,0,0,1)) + + def test_matrix_translate(self): + """ checks if the matrix is translated correctly """ + self.assertTrue(tuple(mt.translateMatrix(2,3)[0]) == (1,0,0,2)) + self.assertTrue(tuple(mt.translateMatrix(2,3)[1]) == (0,1,0,3)) + self.assertTrue(tuple(mt.translateMatrix(2,3)[2]) == (0,0,1,0)) + self.assertTrue(tuple(mt.translateMatrix(2,3)[3]) == (0,0,0,1)) + + def test_matrix_rotate(self): + """ checks if the matrix is rotated correctly """ + self.assertTrue(tuple(mt.rotateMatrix(0)[0]) == (1,0,0,0)) + self.assertTrue(tuple(mt.rotateMatrix(0)[1]) == (0,1,0,0)) + self.assertTrue(tuple(mt.rotateMatrix(0)[2]) == (0,0,1,0)) + self.assertTrue(tuple(mt.rotateMatrix(0)[3]) == (0,0,0,1)) + + def test_matrix_scale(self): + """ checks if the matrix is scaled accordingly """ + self.assertTrue(tuple(mt.scale(5,4)[0]) == (5,0,0,0)) + self.assertTrue(tuple(mt.scale(5,4)[1]) == (0,4,0,0)) + self.assertTrue(tuple(mt.scale(5,4)[2]) == (0,0,1,0)) + self.assertTrue(tuple(mt.scale(5,4)[3]) == (0,0,0,1)) + + def test_matrix_combine_transformations(self): + """ checks if dot product with matrix list is correct """ + ml = [[1,2,3,4],[5,6,7,8]] + self.assertTrue(mt.combineTransformations(ml) == 70) def main(): unittest.main() From 1e3fdb034855522932df5e0dfab77e19b0f950e5 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Tue, 11 Jul 2017 16:24:58 -0500 Subject: [PATCH 05/30] Tests for outline --- unittest4.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 unittest4.py diff --git a/unittest4.py b/unittest4.py new file mode 100644 index 0000000..ca2cae9 --- /dev/null +++ b/unittest4.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Jul 11 14:20:51 2017 + +@author: siddhant +""" + +import unittest +from point import Point +from line import Line +from linegroup import LineGroup +#import constants as c +#import numpy as np +#import matrixTrans as mt +from outline import Outline + +p1 = Point(1.0, 2.0, 3.0) +p2 = Point(2.0, 4.0, 6.0) +p3 = Point(6.0, 12.0, 18.0) +p4 = Point(8.0, 12.0, 14.0) + +l1 = Line(p1, p2) +l2 = Line(p1, p3) +l4 = Line(Point(0,0), Point(0, 8, 0)) +l5 = Line(Point(4, 0, 0), Point(0, 6, 0)) + +l = LineGroup() +l.append(l1) +l.append(l2) + +o = Outline() +o.addLineGroup(l) + +class OutlineTestCase(unittest.TestCase): + + def test_outline_add_linegroup(self): + """ checks if linegroup correctly added to outline """ +# o = Outline() +## l = LineGroup() +## l.append(l1) +## l.append(l2) +# o.addLineGroup(l) + self.assertTrue(o[1] == l2) + + def test_outline_is_inside(self): + """ checks if the given point is contained within the outline """ +# o = Outline() +# o.addLineGroup(l) + p = Point(2,2) + self.assertTrue(o.isInside(p) == 0) + + def test_outline_offset(self): + """ checks if outline is offset correctly in given direction """ + + + + + +def main(): + unittest.main() + +if __name__ == '__main__': + main() + \ No newline at end of file From e461a19b81f4c573756cd969710eecaf6c00ca6a Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 12 Jul 2017 16:30:27 -0500 Subject: [PATCH 06/30] Additional tests for outline --- unittest4.py | 126 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 102 insertions(+), 24 deletions(-) diff --git a/unittest4.py b/unittest4.py index ca2cae9..ad9882c 100644 --- a/unittest4.py +++ b/unittest4.py @@ -9,53 +9,131 @@ from point import Point from line import Line from linegroup import LineGroup -#import constants as c +import constants as c +#from outline import _sidedpolygon #import numpy as np #import matrixTrans as mt from outline import Outline -p1 = Point(1.0, 2.0, 3.0) -p2 = Point(2.0, 4.0, 6.0) -p3 = Point(6.0, 12.0, 18.0) -p4 = Point(8.0, 12.0, 14.0) +p1 = Point(0.0, 0.0, 0.0) +p2 = Point(6.0, 0.0, 0.0) +p3 = Point(6.0, 6.0, 0.0) +p4 = Point(0.0, 6.0, 0.0) l1 = Line(p1, p2) -l2 = Line(p1, p3) -l4 = Line(Point(0,0), Point(0, 8, 0)) -l5 = Line(Point(4, 0, 0), Point(0, 6, 0)) +l2 = Line(p2, p3) +l3 = Line(p3, p4) +l4 = Line(p4, p1) -l = LineGroup() -l.append(l1) -l.append(l2) +p5 = Point(2.0, 2.0, 0.0) +p6 = Point(2.0, 4.0, 0.0) +p7 = Point(4.0, 4.0, 0.0) +p8 = Point(2.0, 4.0, 0.0) -o = Outline() -o.addLineGroup(l) +l5 = Line(p5, p6) +l6 = Line(p6, p7) +l7 = Line(p7, p8) +l8 = Line(p8, p5) + +p9 = Point(8.0, 0.0, 0.0) +p10 = Point(8.0, 6.0, 0.0) + +l9 = Line(p1, p9) +l10 = Line(p9, p10) +l11 = Line(p10, p4) +l12 = Line(p10, p1) class OutlineTestCase(unittest.TestCase): def test_outline_add_linegroup(self): - """ checks if linegroup correctly added to outline """ -# o = Outline() -## l = LineGroup() -## l.append(l1) -## l.append(l2) -# o.addLineGroup(l) - self.assertTrue(o[1] == l2) + """ checks if linegroup correctly added to outline (addLineGroup) """ + o = Outline() + lg = LineGroup() + lg.append(l1) + o.addLineGroup(lg) + self.assertTrue(o[0] == l1) def test_outline_is_inside(self): """ checks if the given point is contained within the outline """ -# o = Outline() -# o.addLineGroup(l) - p = Point(2,2) - self.assertTrue(o.isInside(p) == 0) + o = Outline() + o.append(l1) + o.append(l2) + o.append(l3) + o.append(l4) + p_in = Point(2,2) + p_out = Point(8,6,0) + self.assertTrue(o.isInside(p_in) == 1) + self.assertFalse(o.isInside(p_out) == 1) def test_outline_offset(self): """ checks if outline is offset correctly in given direction """ + o = Outline() + o.append(l1) + o.append(l2) + o.append(l3) + o.append(l4) + o1 = o.offset(2, c.OUTSIDE) + self.assertTrue(o1[0] == + Line(Point(-2.0,0.0,0.0), Point(-2.0, 6.0, 0.0))) + + def test_outline_do_intersect(self): + """ checks if two given outlines intersect (doOutlinesIntersect) """ + o = Outline() + o.append(l1) + o.append(l2) + o.append(l3) + o.append(l4) + + o1 = Outline() + o1.append(l5) + o1.append(l6) + o1.append(l7) + o1.append(l8) + o2 = Outline() + o2.append(l9) + o2.append(l10) + o2.append(l11) + o2.append(l12) + self.assertTrue(o.doOutlinesIntersect(o1) == False) + self.assertTrue(o.doOutlinesIntersect(o2) == True) + + def test_outline_add_internal_shape(self): + """ checks if given shape is added to outline (addInternalShape) """ + o = Outline() + o.append(l1) + o.append(l2) + o.append(l3) + o.append(l4) + + o1 = Outline() + o1.append(l5) + o1.append(l6) + o1.append(l7) + o1.append(l8) + + o.addInternalShape(o1) + self.assertTrue(o[4] == l5) + def test_outline_close_shape(self): + """ checks if the given outline is closed (closeShape) """ + o = Outline() + o.append(l1) + o.append(l2) + o.closeShape() + self.assertTrue(o[2] == Line(Point(6.0,6.0,0.0), Point(0.0,0.0,0.0))) + def test_outline_finish(self): + """ checks if the given outline is finished (finishOutline) """ + o = Outline() + o.append(l1) + o.append(l2) + o.append(l3) + o.append(l4) + self.assertTrue(o.finishOutline() == None) + def main(): unittest.main() From 2fb3e028d0cb8c099be0a1f50b031f29b44ead33 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Tue, 18 Jul 2017 14:03:33 -0500 Subject: [PATCH 07/30] Added tests for point --- unittest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/unittest.py b/unittest.py index 725cffb..6274442 100644 --- a/unittest.py +++ b/unittest.py @@ -91,6 +91,19 @@ def test_point_rotate(self): """ check if point rotates as expected (rotate) """ self.assertTrue(p1.rotate(0) == Point(1.0, 2.0, 3.0)) + def test_point_normal_vector(self): + """ checks if a normal vector is correctly returned (normalVector) """ + self.assertTrue(p1.normalVector[3] == 1.0) + + def test_point_point(self): + """ checks if sliced correctly to return first three elements (point) """ + self.assertTrue(tuple(p1.point) == (1.0, 2.0, 3.0)) + + def test_point_transform(self): + """ checks if the point is transformed correctly by matrix (transform) """ + mtr = [[1,2,3,1],[4,0,3,6],[2,7,0,4],[0,0,0,1]] + self.assertTrue(p1.transform(mtr) == Point(15,19,20)) + class LineTestCase(unittest.TestCase): def test_length(self): From 91ada284d42b6bbefe4ae94b488c147d9f9148d9 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Fri, 21 Jul 2017 15:42:47 -0500 Subject: [PATCH 08/30] variable names changed for outline --- unittest4.py | 128 +++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 59 deletions(-) diff --git a/unittest4.py b/unittest4.py index ad9882c..90463e8 100644 --- a/unittest4.py +++ b/unittest4.py @@ -14,34 +14,35 @@ #import numpy as np #import matrixTrans as mt from outline import Outline +#from infill import Infill -p1 = Point(0.0, 0.0, 0.0) -p2 = Point(6.0, 0.0, 0.0) -p3 = Point(6.0, 6.0, 0.0) -p4 = Point(0.0, 6.0, 0.0) +pt1 = Point(0.0, 0.0, 0.0) +pt2 = Point(6.0, 0.0, 0.0) +pt3 = Point(6.0, 6.0, 0.0) +pt4 = Point(0.0, 6.0, 0.0) -l1 = Line(p1, p2) -l2 = Line(p2, p3) -l3 = Line(p3, p4) -l4 = Line(p4, p1) +ln1 = Line(pt1, pt2) +ln2 = Line(pt2, pt3) +ln3 = Line(pt3, pt4) +ln4 = Line(pt4, pt1) -p5 = Point(2.0, 2.0, 0.0) -p6 = Point(2.0, 4.0, 0.0) -p7 = Point(4.0, 4.0, 0.0) -p8 = Point(2.0, 4.0, 0.0) +pt5 = Point(2.0, 2.0, 0.0) +pt6 = Point(2.0, 4.0, 0.0) +pt7 = Point(4.0, 4.0, 0.0) +pt8 = Point(2.0, 4.0, 0.0) -l5 = Line(p5, p6) -l6 = Line(p6, p7) -l7 = Line(p7, p8) -l8 = Line(p8, p5) +ln5 = Line(pt5, pt6) +ln6 = Line(pt6, pt7) +ln7 = Line(pt7, pt8) +ln8 = Line(pt8, pt5) -p9 = Point(8.0, 0.0, 0.0) -p10 = Point(8.0, 6.0, 0.0) +pt9 = Point(8.0, 0.0, 0.0) +pt10 = Point(8.0, 6.0, 0.0) -l9 = Line(p1, p9) -l10 = Line(p9, p10) -l11 = Line(p10, p4) -l12 = Line(p10, p1) +ln9 = Line(pt1, pt9) +ln10 = Line(pt9, pt10) +ln11 = Line(pt10, pt4) +ln12 = Line(pt10, pt1) class OutlineTestCase(unittest.TestCase): @@ -49,17 +50,17 @@ def test_outline_add_linegroup(self): """ checks if linegroup correctly added to outline (addLineGroup) """ o = Outline() lg = LineGroup() - lg.append(l1) + lg.append(ln1) o.addLineGroup(lg) - self.assertTrue(o[0] == l1) + self.assertTrue(o[0] == ln1) def test_outline_is_inside(self): """ checks if the given point is contained within the outline """ o = Outline() - o.append(l1) - o.append(l2) - o.append(l3) - o.append(l4) + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) p_in = Point(2,2) p_out = Point(8,6,0) self.assertTrue(o.isInside(p_in) == 1) @@ -68,10 +69,10 @@ def test_outline_is_inside(self): def test_outline_offset(self): """ checks if outline is offset correctly in given direction """ o = Outline() - o.append(l1) - o.append(l2) - o.append(l3) - o.append(l4) + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) o1 = o.offset(2, c.OUTSIDE) self.assertTrue(o1[0] == Line(Point(-2.0,0.0,0.0), Point(-2.0, 6.0, 0.0))) @@ -79,22 +80,22 @@ def test_outline_offset(self): def test_outline_do_intersect(self): """ checks if two given outlines intersect (doOutlinesIntersect) """ o = Outline() - o.append(l1) - o.append(l2) - o.append(l3) - o.append(l4) + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) o1 = Outline() - o1.append(l5) - o1.append(l6) - o1.append(l7) - o1.append(l8) + o1.append(ln5) + o1.append(ln6) + o1.append(ln7) + o1.append(ln8) o2 = Outline() - o2.append(l9) - o2.append(l10) - o2.append(l11) - o2.append(l12) + o2.append(ln9) + o2.append(ln10) + o2.append(ln11) + o2.append(ln12) self.assertTrue(o.doOutlinesIntersect(o1) == False) self.assertTrue(o.doOutlinesIntersect(o2) == True) @@ -102,37 +103,46 @@ def test_outline_do_intersect(self): def test_outline_add_internal_shape(self): """ checks if given shape is added to outline (addInternalShape) """ o = Outline() - o.append(l1) - o.append(l2) - o.append(l3) - o.append(l4) + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) o1 = Outline() - o1.append(l5) - o1.append(l6) - o1.append(l7) - o1.append(l8) + o1.append(ln5) + o1.append(ln6) + o1.append(ln7) + o1.append(ln8) o.addInternalShape(o1) - self.assertTrue(o[4] == l5) + self.assertTrue(o[4] == ln5) def test_outline_close_shape(self): """ checks if the given outline is closed (closeShape) """ o = Outline() - o.append(l1) - o.append(l2) + o.append(ln1) + o.append(ln2) o.closeShape() self.assertTrue(o[2] == Line(Point(6.0,6.0,0.0), Point(0.0,0.0,0.0))) def test_outline_finish(self): """ checks if the given outline is finished (finishOutline) """ o = Outline() - o.append(l1) - o.append(l2) - o.append(l3) - o.append(l4) + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) self.assertTrue(o.finishOutline() == None) +#class InfillTestCase(unittest.Testcase): + + # i1 = Infill(o, 0, 0, design = lgr, designType = c.FULL_FIELD) + + # def test_infill_trim(self): + + # issues encountered while attempting to test infill + + def main(): unittest.main() From a33e67bb5d50dff701d9e34613977ff6fdde3d7b Mon Sep 17 00:00:00 2001 From: "ENGR\\siddhant" Date: Mon, 24 Jul 2017 16:19:55 -0500 Subject: [PATCH 09/30] added tests for infill --- infill.py | 11 +++++--- unittest.py | 2 -- unittest3.py | 5 ---- unittest4.py | 43 +++++++++++----------------- unittest5.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 38 deletions(-) create mode 100644 unittest5.py diff --git a/infill.py b/infill.py index 5e211fe..70a1d11 100644 --- a/infill.py +++ b/infill.py @@ -57,7 +57,7 @@ class Infill(LineGroup): def __init__(self, trimOutline, pathWidth, angleDegrees, shiftX=0, shiftY=0, - design=None, designType=c.PARTIAL_ROW): + design=None, designType=c.PARTIAL_ROW, testMode = False): LineGroup.__init__(self, None) self.shiftX = shiftX self.shiftY = shiftY @@ -82,9 +82,12 @@ def __init__(self, trimOutline, pathWidth, angleDegrees, shiftX=0, shiftY=0, self.design = LineGroup(design) # print('\nInfill times:') - for i in range(self.designType, c.TRIMMED_FIELD): - startTime = time.time() - self.operations[i](); + if(not testMode): + for i in range(self.designType, c.TRIMMED_FIELD): + startTime = time.time() + self.operations[i](); + + testMode = False # print((self.operations[i].__name__ + # ''.ljust(maxLength - len(self.operations[i].__name__)) + # '%.2f sec' %(time.time()-startTime))) diff --git a/unittest.py b/unittest.py index 6274442..aeb79de 100644 --- a/unittest.py +++ b/unittest.py @@ -25,8 +25,6 @@ class PointTestCase (unittest.TestCase): - #def test_point_valid(self): - def test_point_equal(self): """ check if point is equal to given point (__eq__) """ self.assertTrue(p1 == Point(1.0, 2.0, 3.0)) diff --git a/unittest3.py b/unittest3.py index 903dad1..5616f1b 100644 --- a/unittest3.py +++ b/unittest3.py @@ -12,11 +12,6 @@ from arc import Arc import matrixTrans as mt import constants as c -#import math -#import numpy as np -#from shapely.geometry.polygon import Polygon -#from shapely.ops import cascaded_union -#from outline import Outline class ArcTestCase(unittest.TestCase): diff --git a/unittest4.py b/unittest4.py index 90463e8..ca0fab5 100644 --- a/unittest4.py +++ b/unittest4.py @@ -10,7 +10,6 @@ from line import Line from linegroup import LineGroup import constants as c -#from outline import _sidedpolygon #import numpy as np #import matrixTrans as mt from outline import Outline @@ -100,22 +99,22 @@ def test_outline_do_intersect(self): self.assertTrue(o.doOutlinesIntersect(o1) == False) self.assertTrue(o.doOutlinesIntersect(o2) == True) - def test_outline_add_internal_shape(self): - """ checks if given shape is added to outline (addInternalShape) """ - o = Outline() - o.append(ln1) - o.append(ln2) - o.append(ln3) - o.append(ln4) - - o1 = Outline() - o1.append(ln5) - o1.append(ln6) - o1.append(ln7) - o1.append(ln8) - - o.addInternalShape(o1) - self.assertTrue(o[4] == ln5) +# def test_outline_add_internal_shape(self): +# """ checks if given shape is added to outline (addInternalShape) """ +# o = Outline() +# o.append(ln1) +# o.append(ln2) +# o.append(ln3) +# o.append(ln4) +# +# o1 = Outline() +# o1.append(ln5) +# o1.append(ln6) +# o1.append(ln7) +# o1.append(ln8) +# +# o.addInternalShape(o1) +# self.assertTrue(o[4] == ln5) def test_outline_close_shape(self): """ checks if the given outline is closed (closeShape) """ @@ -133,17 +132,7 @@ def test_outline_finish(self): o.append(ln3) o.append(ln4) self.assertTrue(o.finishOutline() == None) - -#class InfillTestCase(unittest.Testcase): - - # i1 = Infill(o, 0, 0, design = lgr, designType = c.FULL_FIELD) - - # def test_infill_trim(self): - - # issues encountered while attempting to test infill - - def main(): unittest.main() diff --git a/unittest5.py b/unittest5.py new file mode 100644 index 0000000..bc76e31 --- /dev/null +++ b/unittest5.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Jul 24 15:35:34 2017 + +@author: siddhant +""" + +import unittest +from point import Point +from line import Line +from outline import Outline +from infill import Infill + +class InfillTestCase(unittest.TestCase): + + def test_infill_extend_design(self): + + outline1 = Outline() + outline1.append(Line(Point(0,0), Point(4,0))) + outline1.append(Line(Point(4,0), Point(4,4))) + outline1.append(Line(Point(4,4), Point(0,4))) + outline1.append(Line(Point(0,4), Point(0,0))) + + d = [Line(Point(0,0), Point(2,0))] + + i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) + #print(i1.design) + i1.extendDesign() + #print(i1.design[3]) + self.assertTrue(i1.design[1] == Line(Point(2,0), Point(4,0))) + + def test_infill_create_design(self): + """ checks if resulting infill design has expected modified path width """ + outline1 = Outline() + outline1.append(Line(Point(0,0), Point(4,0))) + outline1.append(Line(Point(4,0), Point(4,4))) + outline1.append(Line(Point(4,4), Point(0,4))) + outline1.append(Line(Point(0,4), Point(0,0))) + + d = [Line(Point(0,0), Point(2,0))] + + i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) + i1.createField() + self.assertTrue(i1.design[1] == Line(Point(0,0.5), Point(2,0.5))) + + def test_infill_centre_and_rotate(self): + + outline1 = Outline() + outline1.append(Line(Point(0,0), Point(4,0))) + outline1.append(Line(Point(4,0), Point(4,4))) + outline1.append(Line(Point(4,4), Point(0,4))) + outline1.append(Line(Point(0,4), Point(0,0))) + + d = [Line(Point(0,0), Point(2,0))] + + i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) + i1.centerAndRotateField() + self.assertTrue(i1.design[0] == Line(Point(1,2), Point(3,2))) + + def test_infill_trim(self): + + outline1 = Outline() + outline1.append(Line(Point(0,0), Point(4,0))) + outline1.append(Line(Point(4,0), Point(4,4))) + outline1.append(Line(Point(4,4), Point(0,4))) + outline1.append(Line(Point(0,4), Point(0,0))) + + d = [Line(Point(0,0), Point(2,0))] + + i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) + i1.trimField() + self.assertTrue(i1.design[0] == d[0]) + +def main(): + unittest.main() + +if __name__ == '__main__': + main() + \ No newline at end of file From 9d971dd0e3ed6b3edfc041b242520bb915772558 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Tue, 25 Jul 2017 14:57:20 -0500 Subject: [PATCH 10/30] made changes to addInternalShape --- outline.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/outline.py b/outline.py index 9999f77..aa5b03f 100644 --- a/outline.py +++ b/outline.py @@ -60,12 +60,11 @@ def fromMeshSection(self, m_section): @finishedOutline def addInternalShape(self, inShape): - if(not inShape.outlineFinished): - print('********** Your internal shape was not a finished outline **********') + inShape.finishOutline() if(not self.isInside(inShape.lines[0].start)): - print('********** The internal shape is not inside the main outline. **********') - if(self.doShapesIntersect(inShape)): - print('********** Internal shape is not completely inside main outline. **********') + raise Exception('********** The internal shape is not inside the main outline. **********') + if(self.doOutlinesIntersect(inShape)): + raise Exception('********** Internal shape is not completely inside main outline. **********') for line in inShape: self.append(line) From b320dd68228098852b0bd35b05ba636d444e7761 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Tue, 25 Jul 2017 14:58:00 -0500 Subject: [PATCH 11/30] corrected test for addInternalShape --- unittest4.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/unittest4.py b/unittest4.py index ca0fab5..11bad26 100644 --- a/unittest4.py +++ b/unittest4.py @@ -99,22 +99,26 @@ def test_outline_do_intersect(self): self.assertTrue(o.doOutlinesIntersect(o1) == False) self.assertTrue(o.doOutlinesIntersect(o2) == True) -# def test_outline_add_internal_shape(self): -# """ checks if given shape is added to outline (addInternalShape) """ -# o = Outline() -# o.append(ln1) -# o.append(ln2) -# o.append(ln3) -# o.append(ln4) -# -# o1 = Outline() -# o1.append(ln5) -# o1.append(ln6) -# o1.append(ln7) -# o1.append(ln8) -# -# o.addInternalShape(o1) -# self.assertTrue(o[4] == ln5) + def test_outline_add_internal_shape(self): + """ checks if given shape is added to outline (addInternalShape) """ + o = Outline() + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) + + o1 = Outline() + o1.append(ln5) + o1.append(ln6) + o1.append(ln7) + o1.append(ln8) + #print(o1) + + o.addInternalShape(o1) + #print(o) + #print(o1) + self.assertTrue(o[4] == ln8) + #adds lines in strange order def test_outline_close_shape(self): """ checks if the given outline is closed (closeShape) """ From 3e206f6badb06e246f970cad2d28ad979e5ceef4 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Tue, 25 Jul 2017 14:58:26 -0500 Subject: [PATCH 12/30] added tests for false cases --- unittest.py | 2 +- unittest2.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/unittest.py b/unittest.py index aeb79de..2eccfcb 100644 --- a/unittest.py +++ b/unittest.py @@ -168,7 +168,7 @@ def test_line_rotate(self): def test_line_bounding_boxes(self): """ checks if bounding boxes of two lines intersect """ self.assertTrue(l1.doBoundingBoxesIntersect(l2) == True) - self.assertFalse(l1.doBoundingBoxesIntersect(l2) != True) + self.assertFalse(l1.doBoundingBoxesIntersect(l2) == False) def test_line_point_to_line_distance(self): """ checks the distance between point and line (pointToLineDist) """ diff --git a/unittest2.py b/unittest2.py index 297d825..5694b0f 100644 --- a/unittest2.py +++ b/unittest2.py @@ -90,10 +90,11 @@ def test_linegroup_mirror(self): ltest = LineGroup() ltest.append(l1) - ltest1 = LineGroup() - ltest1.append(Line(Point(1,-2,3), Point(2,-4,6))) + #ltest1 = LineGroup() + #ltest1.append(Line(Point(1,-2,3), Point(2,-4,6))) - self.assertTrue(ltest.mirror(c.X)[0] == ltest1[0]) + self.assertTrue(ltest.mirror(c.X)[0] == + Line(Point(1,-2,3), Point(2,-4,6))) def test_linegroup_sort(self): """ checks if linegroup is sorted correctly (sort) """ @@ -150,6 +151,8 @@ def test_linegroup_line_outside_boundingbox(self): ltest.append(l1) ltest.append(l2) self.assertTrue(ltest.lineOutsideBoundingBox(l4) == True) + self.assertTrue(ltest.lineOutsideBoundingBox(l5) == False) + def test_linegroup_line_add_points(self): """ checks if line from given points is added to linegroup """ From 41a52fd505cb38b4e5b42565d4044624d7ed008a Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Tue, 25 Jul 2017 15:19:23 -0500 Subject: [PATCH 13/30] added test for arcToLines --- unittest3.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/unittest3.py b/unittest3.py index 5616f1b..1f838a3 100644 --- a/unittest3.py +++ b/unittest3.py @@ -21,6 +21,16 @@ def test_arc_calc_inner_angle(self): ang = a.calcIncludedAngle(Point(1,1,0), Point(4,4,0)) self.assertAlmostEqual(ang, 4.2426, 4) + def test_arc_to_lines(self): + """ checks if line segments double when function called (arcToLines) """ + a = Arc(Point(1,1,0), Point(4,4,0), c.X, Point(1,3,0)) + len1 = len(a) + + a.arcToLines() + len2 = len(a) + + self.assertTrue(len2 == 2*len1) + class MatrixTestCase(unittest.TestCase): def test_matrix_mirror(self): From 72f0767c517be7debd4f9198c7fe3e726bdd58c2 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Mon, 31 Jul 2017 14:04:29 -0500 Subject: [PATCH 14/30] changed file name, indicates specific module for which tests are written --- unittest2(linegroup).py | 200 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 unittest2(linegroup).py diff --git a/unittest2(linegroup).py b/unittest2(linegroup).py new file mode 100644 index 0000000..5694b0f --- /dev/null +++ b/unittest2(linegroup).py @@ -0,0 +1,200 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Jul 5 15:50:23 2017 + +@author: siddhant +""" + +import unittest +from point import Point +from line import Line +from linegroup import LineGroup +import constants as c +import numpy as np + +p1 = Point(1.0, 2.0, 3.0) +p2 = Point(2.0, 4.0, 6.0) +p3 = Point(6.0, 12.0, 18.0) +p4 = Point(8.0, 12.0, 14.0) + +l1 = Line(p1, p2) +l2 = Line(p1, p3) +l4 = Line(Point(0,0), Point(0, 8, 0)) +l5 = Line(Point(4, 0, 0), Point(0, 6, 0)) + +#lg1 = LineGroup() +#lg2 = LineGroup() +#lg2.append(l1) + + +class LineGroupTestCase(unittest.TestCase): + + def test_linegroup_getitem(self): + """ checks if correct line in linegroup is returned (__getitem__) """ + ltest = LineGroup() + ltest.append(l1) + self.assertTrue(ltest[0] == l1) + + def test_linegroup_append(self): + """ checks if correct line is appended to linegroup (append) """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest[1] == l2) + + def test_linegroup_remove(self): + """ checks if line is correctly removed from group (remove) """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + ltest.remove(l1) + self.assertTrue(ltest[0] == l2) + + def test_linegroup_length(self): + """ checks if linegroup contains expected number of lines (__len__) """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + ltest.append(l4) + count = 0 + for l in ltest: + count = count + 1 + self.assertEqual(count, 3) + + def test_linegroup_pop(self): + """ checks if correct line returned when linegroup popped (pop) """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest.pop() == l2) + + def test_linegroup_midpoint(self): + """ checks if correct midpoint of linegroup returned (getMidPoint) """ + #print(lg2) + ltest = LineGroup() + ltest.append(l1) + self.assertTrue(ltest.getMidPoint() == Point(1.5, 3.0, 0.0)) + + def test_linegroup_add_linegroup(self): + """ checks if linegroup is correctly added (addLineGroup) """ + ltest = LineGroup() + ltest.append(l1) + + ltest1 = LineGroup() + ltest1.append(l2) + ltest.addLineGroup(ltest1) + self.assertTrue(ltest[1] == l2) + + def test_linegroup_mirror(self): + """ checks if linegroup is correctly mirrored (mirror) """ + ltest = LineGroup() + ltest.append(l1) + + #ltest1 = LineGroup() + #ltest1.append(Line(Point(1,-2,3), Point(2,-4,6))) + + self.assertTrue(ltest.mirror(c.X)[0] == + Line(Point(1,-2,3), Point(2,-4,6))) + + def test_linegroup_sort(self): + """ checks if linegroup is sorted correctly (sort) """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l4) + ltest.sort() + self.assertTrue(ltest[0] == l4) + + def test_linegroup_fourcorners(self): + """ checks if the four corners correspond to the correct points """ + ltest = LineGroup() + ltest.append(l4) + ltest.append(l5) + self.assertTrue(ltest.fourCorners()[0] == Point(0,0,0)) + self.assertTrue(ltest.fourCorners()[1] == Point(4,0,0)) + self.assertTrue(ltest.fourCorners()[2] == Point(4,8,0)) + self.assertTrue(ltest.fourCorners()[3] == Point(0,8,0)) + + def test_linegroup_scale(self): + """ checks if start and end points of lines are scaled correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + + self.assertTrue(ltest.scale(2,3)[0] == + Line(Point(2,6,3), Point(4,12,6))) + self.assertTrue(ltest.scale(2,3)[1] == + Line(Point(2,6,3), Point(12,36,18))) + + def test_linegroup_rotate(self): + """ checks if linegroup is rotated correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest.rotate(np.pi/2)[0] == + Line(Point(-2,1,3), Point(-4,2,6))) + self.assertTrue(ltest.rotate(np.pi/2)[1] == + Line(Point(-2,1,3), Point(-12,6,18))) + + def test_linegroup_translate(self): + """ checks if linegroup is translated correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest.translate(2,4)[0] == + Line(Point(3,6,3), Point(4,8,6))) + self.assertTrue(ltest.translate(2,4)[1] == + Line(Point(3,6,3), Point(8,16,18))) + + def test_linegroup_line_outside_boundingbox(self): + """ checks if the given line is outside the bounding box """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + self.assertTrue(ltest.lineOutsideBoundingBox(l4) == True) + self.assertTrue(ltest.lineOutsideBoundingBox(l5) == False) + + + def test_linegroup_line_add_points(self): + """ checks if line from given points is added to linegroup """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + p = [Point(1,1,0), Point(4,5,0)] + ltest.addLinesFromPoints(p) + self.assertTrue(ltest[2] == Line(Point(1,1,0), Point(4,5,0))) + + def test_linegroup_update_min_max(self): + """ checks if the max & min x and y values are updated correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + l = Line(Point(10,20,0), Point(14,-16,0)) + ltest.append(l) + self.assertTrue(ltest.maxY == 20) + self.assertTrue(ltest.maxX == 14) + self.assertTrue(ltest.minY == -16) + self.assertTrue(ltest.minX == 1) + + def test_linegroup_line_add_coordlist(self): + """ checks if points from coordinate list added to linegroup """ + ltest = LineGroup() + ltest.append(l1) + k = [[3,4], [-6,7]] + ltest.addLinesFromCoordinateList(k) + self.assertTrue(ltest[1] == Line(Point(3,4,0), Point(-6,7,0))) + + def test_linegroup_transform(self): + """ checks if lines within group are transfromed correctly """ + ltest = LineGroup() + ltest.append(l1) + ltest.append(l2) + matr = [[0,0,0,1], [1,4,6,8], [0,6,7,9], [3,4,5,6]] + ltest = ltest.transform(matr) + self.assertTrue(ltest[0] == Line(Point(1,35,42),Point(1,62,75))) + self.assertTrue(ltest[1] == Line(Point(1,35,42), Point(1,170,207))) + +def main(): + unittest.main() + +if __name__ == '__main__': + main() \ No newline at end of file From 48dc41dfc70416fd418c0946ca57a1997b54f517 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Mon, 31 Jul 2017 14:05:10 -0500 Subject: [PATCH 15/30] changed file name --- unittest3(arc,matrix).py | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 unittest3(arc,matrix).py diff --git a/unittest3(arc,matrix).py b/unittest3(arc,matrix).py new file mode 100644 index 0000000..1f838a3 --- /dev/null +++ b/unittest3(arc,matrix).py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Jul 7 14:33:12 2017 + +@author: siddhant +""" + +import unittest +from point import Point +#from line import Line +#from linegroup import LineGroup +from arc import Arc +import matrixTrans as mt +import constants as c + +class ArcTestCase(unittest.TestCase): + + def test_arc_calc_inner_angle(self): + """ checks if inner angle between given points is correct """ + a = Arc(Point(1,1,0), Point(4,4,0), c.X, Point(1,3,0)) + ang = a.calcIncludedAngle(Point(1,1,0), Point(4,4,0)) + self.assertAlmostEqual(ang, 4.2426, 4) + + def test_arc_to_lines(self): + """ checks if line segments double when function called (arcToLines) """ + a = Arc(Point(1,1,0), Point(4,4,0), c.X, Point(1,3,0)) + len1 = len(a) + + a.arcToLines() + len2 = len(a) + + self.assertTrue(len2 == 2*len1) + +class MatrixTestCase(unittest.TestCase): + + def test_matrix_mirror(self): + """ checks if the matrix is mirrored correctly about given axis """ + self.assertTrue(tuple(mt.mirrorMatrix(c.X)[0]) == (1,0,0,0)) + self.assertTrue(tuple(mt.mirrorMatrix(c.X)[1]) == (0,-1,0,0)) + self.assertTrue(tuple(mt.mirrorMatrix(c.X)[2]) == (0,0,1,0)) + self.assertTrue(tuple(mt.mirrorMatrix(c.X)[3]) == (0,0,0,1)) + + def test_matrix_translate(self): + """ checks if the matrix is translated correctly """ + self.assertTrue(tuple(mt.translateMatrix(2,3)[0]) == (1,0,0,2)) + self.assertTrue(tuple(mt.translateMatrix(2,3)[1]) == (0,1,0,3)) + self.assertTrue(tuple(mt.translateMatrix(2,3)[2]) == (0,0,1,0)) + self.assertTrue(tuple(mt.translateMatrix(2,3)[3]) == (0,0,0,1)) + + def test_matrix_rotate(self): + """ checks if the matrix is rotated correctly """ + self.assertTrue(tuple(mt.rotateMatrix(0)[0]) == (1,0,0,0)) + self.assertTrue(tuple(mt.rotateMatrix(0)[1]) == (0,1,0,0)) + self.assertTrue(tuple(mt.rotateMatrix(0)[2]) == (0,0,1,0)) + self.assertTrue(tuple(mt.rotateMatrix(0)[3]) == (0,0,0,1)) + + def test_matrix_scale(self): + """ checks if the matrix is scaled accordingly """ + self.assertTrue(tuple(mt.scale(5,4)[0]) == (5,0,0,0)) + self.assertTrue(tuple(mt.scale(5,4)[1]) == (0,4,0,0)) + self.assertTrue(tuple(mt.scale(5,4)[2]) == (0,0,1,0)) + self.assertTrue(tuple(mt.scale(5,4)[3]) == (0,0,0,1)) + + def test_matrix_combine_transformations(self): + """ checks if dot product with matrix list is correct """ + ml = [[1,2,3,4],[5,6,7,8]] + self.assertTrue(mt.combineTransformations(ml) == 70) + +def main(): + unittest.main() + +if __name__ == '__main__': + main() + + + From 45bf39c6f8182974987c07fdfd25b38c035ceb9e Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Mon, 31 Jul 2017 14:05:26 -0500 Subject: [PATCH 16/30] changed file name --- unittest4(outline).py | 145 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 unittest4(outline).py diff --git a/unittest4(outline).py b/unittest4(outline).py new file mode 100644 index 0000000..11bad26 --- /dev/null +++ b/unittest4(outline).py @@ -0,0 +1,145 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Jul 11 14:20:51 2017 + +@author: siddhant +""" + +import unittest +from point import Point +from line import Line +from linegroup import LineGroup +import constants as c +#import numpy as np +#import matrixTrans as mt +from outline import Outline +#from infill import Infill + +pt1 = Point(0.0, 0.0, 0.0) +pt2 = Point(6.0, 0.0, 0.0) +pt3 = Point(6.0, 6.0, 0.0) +pt4 = Point(0.0, 6.0, 0.0) + +ln1 = Line(pt1, pt2) +ln2 = Line(pt2, pt3) +ln3 = Line(pt3, pt4) +ln4 = Line(pt4, pt1) + +pt5 = Point(2.0, 2.0, 0.0) +pt6 = Point(2.0, 4.0, 0.0) +pt7 = Point(4.0, 4.0, 0.0) +pt8 = Point(2.0, 4.0, 0.0) + +ln5 = Line(pt5, pt6) +ln6 = Line(pt6, pt7) +ln7 = Line(pt7, pt8) +ln8 = Line(pt8, pt5) + +pt9 = Point(8.0, 0.0, 0.0) +pt10 = Point(8.0, 6.0, 0.0) + +ln9 = Line(pt1, pt9) +ln10 = Line(pt9, pt10) +ln11 = Line(pt10, pt4) +ln12 = Line(pt10, pt1) + +class OutlineTestCase(unittest.TestCase): + + def test_outline_add_linegroup(self): + """ checks if linegroup correctly added to outline (addLineGroup) """ + o = Outline() + lg = LineGroup() + lg.append(ln1) + o.addLineGroup(lg) + self.assertTrue(o[0] == ln1) + + def test_outline_is_inside(self): + """ checks if the given point is contained within the outline """ + o = Outline() + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) + p_in = Point(2,2) + p_out = Point(8,6,0) + self.assertTrue(o.isInside(p_in) == 1) + self.assertFalse(o.isInside(p_out) == 1) + + def test_outline_offset(self): + """ checks if outline is offset correctly in given direction """ + o = Outline() + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) + o1 = o.offset(2, c.OUTSIDE) + self.assertTrue(o1[0] == + Line(Point(-2.0,0.0,0.0), Point(-2.0, 6.0, 0.0))) + + def test_outline_do_intersect(self): + """ checks if two given outlines intersect (doOutlinesIntersect) """ + o = Outline() + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) + + o1 = Outline() + o1.append(ln5) + o1.append(ln6) + o1.append(ln7) + o1.append(ln8) + + o2 = Outline() + o2.append(ln9) + o2.append(ln10) + o2.append(ln11) + o2.append(ln12) + + self.assertTrue(o.doOutlinesIntersect(o1) == False) + self.assertTrue(o.doOutlinesIntersect(o2) == True) + + def test_outline_add_internal_shape(self): + """ checks if given shape is added to outline (addInternalShape) """ + o = Outline() + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) + + o1 = Outline() + o1.append(ln5) + o1.append(ln6) + o1.append(ln7) + o1.append(ln8) + #print(o1) + + o.addInternalShape(o1) + #print(o) + #print(o1) + self.assertTrue(o[4] == ln8) + #adds lines in strange order + + def test_outline_close_shape(self): + """ checks if the given outline is closed (closeShape) """ + o = Outline() + o.append(ln1) + o.append(ln2) + o.closeShape() + self.assertTrue(o[2] == Line(Point(6.0,6.0,0.0), Point(0.0,0.0,0.0))) + + def test_outline_finish(self): + """ checks if the given outline is finished (finishOutline) """ + o = Outline() + o.append(ln1) + o.append(ln2) + o.append(ln3) + o.append(ln4) + self.assertTrue(o.finishOutline() == None) + +def main(): + unittest.main() + +if __name__ == '__main__': + main() + \ No newline at end of file From 4481bea80bb4ddd4f319a950394a02dafd261700 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Mon, 31 Jul 2017 14:05:54 -0500 Subject: [PATCH 17/30] changed file name --- unittest5(infill).py | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 unittest5(infill).py diff --git a/unittest5(infill).py b/unittest5(infill).py new file mode 100644 index 0000000..bc76e31 --- /dev/null +++ b/unittest5(infill).py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Jul 24 15:35:34 2017 + +@author: siddhant +""" + +import unittest +from point import Point +from line import Line +from outline import Outline +from infill import Infill + +class InfillTestCase(unittest.TestCase): + + def test_infill_extend_design(self): + + outline1 = Outline() + outline1.append(Line(Point(0,0), Point(4,0))) + outline1.append(Line(Point(4,0), Point(4,4))) + outline1.append(Line(Point(4,4), Point(0,4))) + outline1.append(Line(Point(0,4), Point(0,0))) + + d = [Line(Point(0,0), Point(2,0))] + + i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) + #print(i1.design) + i1.extendDesign() + #print(i1.design[3]) + self.assertTrue(i1.design[1] == Line(Point(2,0), Point(4,0))) + + def test_infill_create_design(self): + """ checks if resulting infill design has expected modified path width """ + outline1 = Outline() + outline1.append(Line(Point(0,0), Point(4,0))) + outline1.append(Line(Point(4,0), Point(4,4))) + outline1.append(Line(Point(4,4), Point(0,4))) + outline1.append(Line(Point(0,4), Point(0,0))) + + d = [Line(Point(0,0), Point(2,0))] + + i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) + i1.createField() + self.assertTrue(i1.design[1] == Line(Point(0,0.5), Point(2,0.5))) + + def test_infill_centre_and_rotate(self): + + outline1 = Outline() + outline1.append(Line(Point(0,0), Point(4,0))) + outline1.append(Line(Point(4,0), Point(4,4))) + outline1.append(Line(Point(4,4), Point(0,4))) + outline1.append(Line(Point(0,4), Point(0,0))) + + d = [Line(Point(0,0), Point(2,0))] + + i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) + i1.centerAndRotateField() + self.assertTrue(i1.design[0] == Line(Point(1,2), Point(3,2))) + + def test_infill_trim(self): + + outline1 = Outline() + outline1.append(Line(Point(0,0), Point(4,0))) + outline1.append(Line(Point(4,0), Point(4,4))) + outline1.append(Line(Point(4,4), Point(0,4))) + outline1.append(Line(Point(0,4), Point(0,0))) + + d = [Line(Point(0,0), Point(2,0))] + + i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) + i1.trimField() + self.assertTrue(i1.design[0] == d[0]) + +def main(): + unittest.main() + +if __name__ == '__main__': + main() + \ No newline at end of file From 52cf3524e366ee78bef866f447be33b6efebba59 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Mon, 31 Jul 2017 14:06:14 -0500 Subject: [PATCH 18/30] changed file name --- unittest(point,line).py | 214 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 unittest(point,line).py diff --git a/unittest(point,line).py b/unittest(point,line).py new file mode 100644 index 0000000..2eccfcb --- /dev/null +++ b/unittest(point,line).py @@ -0,0 +1,214 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Jun 26 13:53:41 2017 + +@author: siddhant +""" + +import unittest +from point import Point +import constants as c +from line import Line +import numpy as np + + +p1 = Point(1.0, 2.0, 3.0) +p2 = Point(2.0, 4.0, 6.0) +p3 = Point(6.0, 12.0, 18.0) +p4 = Point(8.0, 12.0, 14.0) + +l1 = Line(p1, p2) +l2 = Line(p1, p3) +l3 = Line(p1, p2) +l4 = Line(Point(0,0), Point(0, 8, 0)) +l5 = Line(Point(4, 0, 0), Point(0, 6, 0)) + +class PointTestCase (unittest.TestCase): + + def test_point_equal(self): + """ check if point is equal to given point (__eq__) """ + self.assertTrue(p1 == Point(1.0, 2.0, 3.0)) + self.assertFalse(p1 == Point(1.0, 3.0, 4.0)) + + def test_point_notequal(self): + """ check points are not equal (__ne__) """ + self.assertTrue(p1 != Point(1.0, 2.0, 8.0)) + self.assertFalse(p1 != Point(1.0, 2.0, 3.0)) + + def test_point_negative(self): + """ check if point negative is correct (__neg_) """ + self.assertTrue(-p1 == Point(-1.0, -2.0, 3.0)) + + def test_point_lesser(self): + """ compare two points to check lesser (__lt__) """ + self.assertTrue(p1 < Point(2.0, 4.0, 6.0)) + self.assertFalse(p1 < Point(1.0, 2.0, 2.0)) + + def test_point_greater(self): + """ compare two points to check greater (__gt__) """ + self.assertTrue(p1 > Point(1.0, 2.0, 2.0)) + self.assertFalse(p1 > Point(1.0, 2.0, 6.0)) + + def test_point_sub(self): + """ check distance between two points (__sub__) """ + self.assertAlmostEqual(p2-p1, 3.7417, places = 4) + + def test_initial_x_property(self): + """ check if x-coordinate matches """ + self.assertTrue(p1.x == 1.0) + + def test_initial_y_propert(self): + """ check if y-coordinate matches """ + self.assertTrue(p1.y == 2.0) + + def test_initial_z_property(self): + """ check if z-coordinate matches """ + self.assertTrue(p1.z == 3.0) + + def test_get_item(self): + """ check if correct coordinate is returned and slice correctly""" + self.assertTrue(p1[0] == 1.0) + + def test_get_point2D(self): + """ check if x and y coordinates of point are correct """ + self.assertTrue(tuple(p1[0:2]) == (1.0, 2.0)) + + def test_squaredistance(self): + """ check squared distance between two points (squaredDistance) """ + self.assertTrue(((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) == 5.0) + + def test_point_mirror(self): + """ check if point correctly mirrored about axis (mirror) """ + self.assertTrue(p1.mirror(c.X) == Point(1.0, -2.0, 3.0)) + + def test_point_translate(self): + """ check if point translates correctly (translate) """ + self.assertTrue(p1.translate(1.0, 2.0) == Point(2.0, 4.0, 3.0)) + + def test_point_rotate(self): + """ check if point rotates as expected (rotate) """ + self.assertTrue(p1.rotate(0) == Point(1.0, 2.0, 3.0)) + + def test_point_normal_vector(self): + """ checks if a normal vector is correctly returned (normalVector) """ + self.assertTrue(p1.normalVector[3] == 1.0) + + def test_point_point(self): + """ checks if sliced correctly to return first three elements (point) """ + self.assertTrue(tuple(p1.point) == (1.0, 2.0, 3.0)) + + def test_point_transform(self): + """ checks if the point is transformed correctly by matrix (transform) """ + mtr = [[1,2,3,1],[4,0,3,6],[2,7,0,4],[0,0,0,1]] + self.assertTrue(p1.transform(mtr) == Point(15,19,20)) + +class LineTestCase(unittest.TestCase): + + def test_length(self): + """ checks length of the line (length) """ + self.assertAlmostEqual(p2 - p1, 3.7417, places = 4) + + def test_fliped(self): + """ check if line flips direction as expected (fliped) """ + self.assertEqual(l1.fliped(), Line(p2, p1)) + + def test_on_line(self): + """ checks if given point is on line (isOnLine) """ + self.assertTrue(l1.isOnLine(p2) == True) + + def test_mirror_line(self): + """ check if line mirrored correctly about given axis (mirror) """ + self.assertTrue(l1.mirror(c.X) == + Line(Point(1.0, -2.0, 3.0), Point(2.0, -4.0, 6.0))) + + def test_lines_parallel(self): + """ checks if the lines are parallel (areParallel) """ + self.assertTrue(l1.areParallel(l2) == True) + + def test_line_start(self): + """ checks if starting point of line is correct """ + self.assertTrue(l1.start == p1) + + def test_line_end(self): + """ checks if end point of line is correct """ + self.assertTrue(l1.end == p2) + + def test_line_angle(self): + """ checks if line is oriented correctly by way of angle """ + self.assertAlmostEqual(l1.angle, 1.1071, places = 4) + + def test_line_midpoint(self): + """ checks if midpoint of line is correct (getMidPoint) """ + self.assertTrue(l1.getMidPoint() == Point(1.5, 3.0, 4.5)) + + def test_line_equal(self): + ' checks if lines with same start and end points are equal (__eq__) ' + self.assertTrue(l1 == l3) + self.assertFalse(l1 != l3) + + def test_line_lesser(self): + """ checks if line is less than other (__lt__) """ + self.assertTrue(l1 < l2) + self.assertFalse(l2 < l1) + + def test_line_calcT(self): + """ checks if point located at correct distance from start (calcT) """ + self.assertTrue(l1.calcT(p2) == 1.0) + + def test_line_translate(self): + """ checks if line is translated correctly (translate) """ + self.assertTrue(l1.translate(1.0, 2.0, 1.0) == + Line(Point(2.0, 4.0, 4.0), Point(3.0, 6.0, 7.0))) + + def test_line_rotate(self): + """ checks if line is rotated correctly (rotate) """ + self.assertTrue(l1.rotate(np.pi/2, Point(0,0)) == + Line(Point(-2.0, 1.0, 3.0), Point(-4.0, 2.0, 6.0))) + + def test_line_bounding_boxes(self): + """ checks if bounding boxes of two lines intersect """ + self.assertTrue(l1.doBoundingBoxesIntersect(l2) == True) + self.assertFalse(l1.doBoundingBoxesIntersect(l2) == False) + + def test_line_point_to_line_distance(self): + """ checks the distance between point and line (pointToLineDist) """ + self.assertAlmostEqual(l1.pointToLineDist(p4), 1.7889, places = 4) + + def test_get_offset_line(self): + """ checks if correct offset line returned (getOffsetLine) """ + self.assertTrue(l4.getOffsetLine(4) == + Line(Point(-4.0, 0.0, 0.0), Point(-4.0, 8.0, 0.0))) + + def test_get_area(self): + """ checks if area of triangle is correct (getArea) """ + self.assertAlmostEqual(l1.getArea(p1, p2, p4), 1.0000, places = 4) + + def test_are_colinear(self): + """ checks if two lines are colinear (areColinear) """ + self.assertTrue(l1.areColinear(l2) == True) + self.assertFalse(l1.areColinear(l2) != True) + + def test__side_of_line(self): + """ unsure about precise description """ + self.assertTrue(l1.sideOfLine(p4) == 1) + + def test_do_lines_intersect(self): + """ checks if lines intersect and returns nature of intersection """ + self.assertTrue(l4.segmentsIntersect(l5) == + (1, Point(0, 6, 0))) + + def test_line_upper_left(self): + """ checks if upper left point of line is correct """ + self.assertTrue(l4.upperLeft == Point(0.0, 8.0, 0.0)) + + def test_line_lower_right(self): + """ checks if lower right point of line is correct """ + self.assertTrue(l4.lowerRight == Point(0.0, 0.0)) + + + +def main(): + unittest.main() + +if __name__ == '__main__': + main() \ No newline at end of file From 52efe4f56673af546118247f75197bb276fae800 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Mon, 31 Jul 2017 14:08:26 -0500 Subject: [PATCH 19/30] Delete pointtest.py --- pointtest.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 pointtest.py diff --git a/pointtest.py b/pointtest.py deleted file mode 100644 index d0e974b..0000000 --- a/pointtest.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Mon Jun 26 13:53:41 2017 - -@author: siddhant -""" - -import unittest -from point import Point -#from point import __lt__ -#from point import __gt__ -#from point import __neg__ -from point import __eq__ - -p1 = Point(1.0, 2.0, 3.0) - -class PointTestCase (unittest.TestCase): - # p1 = Point(1.0, 2.0, 0.0) - - def test_point_negative(self): - self.assertTrue(__neg__(p1) == Point(-1.0, -2.0, 3.0)) - #self.assertTrue(p1.__neg__ == Point(-1.0, -2.0, 3.0)) - - #def test_point_greater(self): - # self.assertFalse(__gt__((7, 8, 9)) == False) - - def test_point_equal(self): - self.assertEqual(__eq__(p1, (1.0, 2.0, 3.0))) - -def main(): - unittest.main() - -if __name__ == '__main__': - main() \ No newline at end of file From 437d341b519132de0fbebe6f5fdc422900308859 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:54:02 -0500 Subject: [PATCH 20/30] Rename unittest.py to unittest_point_line.py --- unittest.py => unittest_point_line.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename unittest.py => unittest_point_line.py (99%) diff --git a/unittest.py b/unittest_point_line.py similarity index 99% rename from unittest.py rename to unittest_point_line.py index 2eccfcb..d89d50d 100644 --- a/unittest.py +++ b/unittest_point_line.py @@ -211,4 +211,4 @@ def main(): unittest.main() if __name__ == '__main__': - main() \ No newline at end of file + main() From 0b51b78a51e1a65520ec07b6c84c391d2d1a5f52 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:54:46 -0500 Subject: [PATCH 21/30] Rename unittest2.py to unittest2_linegroup.py --- unittest2.py => unittest2_linegroup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename unittest2.py => unittest2_linegroup.py (99%) diff --git a/unittest2.py b/unittest2_linegroup.py similarity index 99% rename from unittest2.py rename to unittest2_linegroup.py index 5694b0f..b6f1a2e 100644 --- a/unittest2.py +++ b/unittest2_linegroup.py @@ -197,4 +197,4 @@ def main(): unittest.main() if __name__ == '__main__': - main() \ No newline at end of file + main() From e9d0f90405c55d2e7a86216719b6abce98098cf1 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:55:19 -0500 Subject: [PATCH 22/30] Rename unittest3.py to unittest3_arc_matrix.py --- unittest3.py => unittest3_arc_matrix.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename unittest3.py => unittest3_arc_matrix.py (100%) diff --git a/unittest3.py b/unittest3_arc_matrix.py similarity index 100% rename from unittest3.py rename to unittest3_arc_matrix.py From 6e75cdbdf0686ab6bf63fc4a0fb76ad2009e3e86 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:55:47 -0500 Subject: [PATCH 23/30] Rename unittest4.py to unittest4_outline.py --- unittest4.py => unittest4_outline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename unittest4.py => unittest4_outline.py (99%) diff --git a/unittest4.py b/unittest4_outline.py similarity index 99% rename from unittest4.py rename to unittest4_outline.py index 11bad26..7d291aa 100644 --- a/unittest4.py +++ b/unittest4_outline.py @@ -142,4 +142,4 @@ def main(): if __name__ == '__main__': main() - \ No newline at end of file + From 73e0555ed7b335a0dfd14ac1167620d6a32491ca Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:56:11 -0500 Subject: [PATCH 24/30] Rename unittest5.py to unittest5_infill.py --- unittest5.py => unittest5_infill.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename unittest5.py => unittest5_infill.py (99%) diff --git a/unittest5.py b/unittest5_infill.py similarity index 99% rename from unittest5.py rename to unittest5_infill.py index bc76e31..4f0673a 100644 --- a/unittest5.py +++ b/unittest5_infill.py @@ -76,4 +76,4 @@ def main(): if __name__ == '__main__': main() - \ No newline at end of file + From 26e35e529486d157d67a6efe649824aab04c62ab Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:56:33 -0500 Subject: [PATCH 25/30] Delete unittest5(infill).py --- unittest5(infill).py | 79 -------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 unittest5(infill).py diff --git a/unittest5(infill).py b/unittest5(infill).py deleted file mode 100644 index bc76e31..0000000 --- a/unittest5(infill).py +++ /dev/null @@ -1,79 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Mon Jul 24 15:35:34 2017 - -@author: siddhant -""" - -import unittest -from point import Point -from line import Line -from outline import Outline -from infill import Infill - -class InfillTestCase(unittest.TestCase): - - def test_infill_extend_design(self): - - outline1 = Outline() - outline1.append(Line(Point(0,0), Point(4,0))) - outline1.append(Line(Point(4,0), Point(4,4))) - outline1.append(Line(Point(4,4), Point(0,4))) - outline1.append(Line(Point(0,4), Point(0,0))) - - d = [Line(Point(0,0), Point(2,0))] - - i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) - #print(i1.design) - i1.extendDesign() - #print(i1.design[3]) - self.assertTrue(i1.design[1] == Line(Point(2,0), Point(4,0))) - - def test_infill_create_design(self): - """ checks if resulting infill design has expected modified path width """ - outline1 = Outline() - outline1.append(Line(Point(0,0), Point(4,0))) - outline1.append(Line(Point(4,0), Point(4,4))) - outline1.append(Line(Point(4,4), Point(0,4))) - outline1.append(Line(Point(0,4), Point(0,0))) - - d = [Line(Point(0,0), Point(2,0))] - - i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) - i1.createField() - self.assertTrue(i1.design[1] == Line(Point(0,0.5), Point(2,0.5))) - - def test_infill_centre_and_rotate(self): - - outline1 = Outline() - outline1.append(Line(Point(0,0), Point(4,0))) - outline1.append(Line(Point(4,0), Point(4,4))) - outline1.append(Line(Point(4,4), Point(0,4))) - outline1.append(Line(Point(0,4), Point(0,0))) - - d = [Line(Point(0,0), Point(2,0))] - - i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) - i1.centerAndRotateField() - self.assertTrue(i1.design[0] == Line(Point(1,2), Point(3,2))) - - def test_infill_trim(self): - - outline1 = Outline() - outline1.append(Line(Point(0,0), Point(4,0))) - outline1.append(Line(Point(4,0), Point(4,4))) - outline1.append(Line(Point(4,4), Point(0,4))) - outline1.append(Line(Point(0,4), Point(0,0))) - - d = [Line(Point(0,0), Point(2,0))] - - i1 = Infill(outline1, 0.5, 0, design = d, testMode = True) - i1.trimField() - self.assertTrue(i1.design[0] == d[0]) - -def main(): - unittest.main() - -if __name__ == '__main__': - main() - \ No newline at end of file From 119bfb600bfdbf66a3361a69760ea4cbddc5dede Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:56:52 -0500 Subject: [PATCH 26/30] Delete unittest4(outline).py --- unittest4(outline).py | 145 ------------------------------------------ 1 file changed, 145 deletions(-) delete mode 100644 unittest4(outline).py diff --git a/unittest4(outline).py b/unittest4(outline).py deleted file mode 100644 index 11bad26..0000000 --- a/unittest4(outline).py +++ /dev/null @@ -1,145 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Tue Jul 11 14:20:51 2017 - -@author: siddhant -""" - -import unittest -from point import Point -from line import Line -from linegroup import LineGroup -import constants as c -#import numpy as np -#import matrixTrans as mt -from outline import Outline -#from infill import Infill - -pt1 = Point(0.0, 0.0, 0.0) -pt2 = Point(6.0, 0.0, 0.0) -pt3 = Point(6.0, 6.0, 0.0) -pt4 = Point(0.0, 6.0, 0.0) - -ln1 = Line(pt1, pt2) -ln2 = Line(pt2, pt3) -ln3 = Line(pt3, pt4) -ln4 = Line(pt4, pt1) - -pt5 = Point(2.0, 2.0, 0.0) -pt6 = Point(2.0, 4.0, 0.0) -pt7 = Point(4.0, 4.0, 0.0) -pt8 = Point(2.0, 4.0, 0.0) - -ln5 = Line(pt5, pt6) -ln6 = Line(pt6, pt7) -ln7 = Line(pt7, pt8) -ln8 = Line(pt8, pt5) - -pt9 = Point(8.0, 0.0, 0.0) -pt10 = Point(8.0, 6.0, 0.0) - -ln9 = Line(pt1, pt9) -ln10 = Line(pt9, pt10) -ln11 = Line(pt10, pt4) -ln12 = Line(pt10, pt1) - -class OutlineTestCase(unittest.TestCase): - - def test_outline_add_linegroup(self): - """ checks if linegroup correctly added to outline (addLineGroup) """ - o = Outline() - lg = LineGroup() - lg.append(ln1) - o.addLineGroup(lg) - self.assertTrue(o[0] == ln1) - - def test_outline_is_inside(self): - """ checks if the given point is contained within the outline """ - o = Outline() - o.append(ln1) - o.append(ln2) - o.append(ln3) - o.append(ln4) - p_in = Point(2,2) - p_out = Point(8,6,0) - self.assertTrue(o.isInside(p_in) == 1) - self.assertFalse(o.isInside(p_out) == 1) - - def test_outline_offset(self): - """ checks if outline is offset correctly in given direction """ - o = Outline() - o.append(ln1) - o.append(ln2) - o.append(ln3) - o.append(ln4) - o1 = o.offset(2, c.OUTSIDE) - self.assertTrue(o1[0] == - Line(Point(-2.0,0.0,0.0), Point(-2.0, 6.0, 0.0))) - - def test_outline_do_intersect(self): - """ checks if two given outlines intersect (doOutlinesIntersect) """ - o = Outline() - o.append(ln1) - o.append(ln2) - o.append(ln3) - o.append(ln4) - - o1 = Outline() - o1.append(ln5) - o1.append(ln6) - o1.append(ln7) - o1.append(ln8) - - o2 = Outline() - o2.append(ln9) - o2.append(ln10) - o2.append(ln11) - o2.append(ln12) - - self.assertTrue(o.doOutlinesIntersect(o1) == False) - self.assertTrue(o.doOutlinesIntersect(o2) == True) - - def test_outline_add_internal_shape(self): - """ checks if given shape is added to outline (addInternalShape) """ - o = Outline() - o.append(ln1) - o.append(ln2) - o.append(ln3) - o.append(ln4) - - o1 = Outline() - o1.append(ln5) - o1.append(ln6) - o1.append(ln7) - o1.append(ln8) - #print(o1) - - o.addInternalShape(o1) - #print(o) - #print(o1) - self.assertTrue(o[4] == ln8) - #adds lines in strange order - - def test_outline_close_shape(self): - """ checks if the given outline is closed (closeShape) """ - o = Outline() - o.append(ln1) - o.append(ln2) - o.closeShape() - self.assertTrue(o[2] == Line(Point(6.0,6.0,0.0), Point(0.0,0.0,0.0))) - - def test_outline_finish(self): - """ checks if the given outline is finished (finishOutline) """ - o = Outline() - o.append(ln1) - o.append(ln2) - o.append(ln3) - o.append(ln4) - self.assertTrue(o.finishOutline() == None) - -def main(): - unittest.main() - -if __name__ == '__main__': - main() - \ No newline at end of file From 311158163274115ebc2ba8a832e42bd388bb964d Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:57:05 -0500 Subject: [PATCH 27/30] Delete unittest3(arc,matrix).py --- unittest3(arc,matrix).py | 76 ---------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 unittest3(arc,matrix).py diff --git a/unittest3(arc,matrix).py b/unittest3(arc,matrix).py deleted file mode 100644 index 1f838a3..0000000 --- a/unittest3(arc,matrix).py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Jul 7 14:33:12 2017 - -@author: siddhant -""" - -import unittest -from point import Point -#from line import Line -#from linegroup import LineGroup -from arc import Arc -import matrixTrans as mt -import constants as c - -class ArcTestCase(unittest.TestCase): - - def test_arc_calc_inner_angle(self): - """ checks if inner angle between given points is correct """ - a = Arc(Point(1,1,0), Point(4,4,0), c.X, Point(1,3,0)) - ang = a.calcIncludedAngle(Point(1,1,0), Point(4,4,0)) - self.assertAlmostEqual(ang, 4.2426, 4) - - def test_arc_to_lines(self): - """ checks if line segments double when function called (arcToLines) """ - a = Arc(Point(1,1,0), Point(4,4,0), c.X, Point(1,3,0)) - len1 = len(a) - - a.arcToLines() - len2 = len(a) - - self.assertTrue(len2 == 2*len1) - -class MatrixTestCase(unittest.TestCase): - - def test_matrix_mirror(self): - """ checks if the matrix is mirrored correctly about given axis """ - self.assertTrue(tuple(mt.mirrorMatrix(c.X)[0]) == (1,0,0,0)) - self.assertTrue(tuple(mt.mirrorMatrix(c.X)[1]) == (0,-1,0,0)) - self.assertTrue(tuple(mt.mirrorMatrix(c.X)[2]) == (0,0,1,0)) - self.assertTrue(tuple(mt.mirrorMatrix(c.X)[3]) == (0,0,0,1)) - - def test_matrix_translate(self): - """ checks if the matrix is translated correctly """ - self.assertTrue(tuple(mt.translateMatrix(2,3)[0]) == (1,0,0,2)) - self.assertTrue(tuple(mt.translateMatrix(2,3)[1]) == (0,1,0,3)) - self.assertTrue(tuple(mt.translateMatrix(2,3)[2]) == (0,0,1,0)) - self.assertTrue(tuple(mt.translateMatrix(2,3)[3]) == (0,0,0,1)) - - def test_matrix_rotate(self): - """ checks if the matrix is rotated correctly """ - self.assertTrue(tuple(mt.rotateMatrix(0)[0]) == (1,0,0,0)) - self.assertTrue(tuple(mt.rotateMatrix(0)[1]) == (0,1,0,0)) - self.assertTrue(tuple(mt.rotateMatrix(0)[2]) == (0,0,1,0)) - self.assertTrue(tuple(mt.rotateMatrix(0)[3]) == (0,0,0,1)) - - def test_matrix_scale(self): - """ checks if the matrix is scaled accordingly """ - self.assertTrue(tuple(mt.scale(5,4)[0]) == (5,0,0,0)) - self.assertTrue(tuple(mt.scale(5,4)[1]) == (0,4,0,0)) - self.assertTrue(tuple(mt.scale(5,4)[2]) == (0,0,1,0)) - self.assertTrue(tuple(mt.scale(5,4)[3]) == (0,0,0,1)) - - def test_matrix_combine_transformations(self): - """ checks if dot product with matrix list is correct """ - ml = [[1,2,3,4],[5,6,7,8]] - self.assertTrue(mt.combineTransformations(ml) == 70) - -def main(): - unittest.main() - -if __name__ == '__main__': - main() - - - From 485eae069d78b2ca0f901a223f9c346d8e2990a0 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:57:18 -0500 Subject: [PATCH 28/30] Delete unittest2(linegroup).py --- unittest2(linegroup).py | 200 ---------------------------------------- 1 file changed, 200 deletions(-) delete mode 100644 unittest2(linegroup).py diff --git a/unittest2(linegroup).py b/unittest2(linegroup).py deleted file mode 100644 index 5694b0f..0000000 --- a/unittest2(linegroup).py +++ /dev/null @@ -1,200 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Jul 5 15:50:23 2017 - -@author: siddhant -""" - -import unittest -from point import Point -from line import Line -from linegroup import LineGroup -import constants as c -import numpy as np - -p1 = Point(1.0, 2.0, 3.0) -p2 = Point(2.0, 4.0, 6.0) -p3 = Point(6.0, 12.0, 18.0) -p4 = Point(8.0, 12.0, 14.0) - -l1 = Line(p1, p2) -l2 = Line(p1, p3) -l4 = Line(Point(0,0), Point(0, 8, 0)) -l5 = Line(Point(4, 0, 0), Point(0, 6, 0)) - -#lg1 = LineGroup() -#lg2 = LineGroup() -#lg2.append(l1) - - -class LineGroupTestCase(unittest.TestCase): - - def test_linegroup_getitem(self): - """ checks if correct line in linegroup is returned (__getitem__) """ - ltest = LineGroup() - ltest.append(l1) - self.assertTrue(ltest[0] == l1) - - def test_linegroup_append(self): - """ checks if correct line is appended to linegroup (append) """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - self.assertTrue(ltest[1] == l2) - - def test_linegroup_remove(self): - """ checks if line is correctly removed from group (remove) """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - ltest.remove(l1) - self.assertTrue(ltest[0] == l2) - - def test_linegroup_length(self): - """ checks if linegroup contains expected number of lines (__len__) """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - ltest.append(l4) - count = 0 - for l in ltest: - count = count + 1 - self.assertEqual(count, 3) - - def test_linegroup_pop(self): - """ checks if correct line returned when linegroup popped (pop) """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - self.assertTrue(ltest.pop() == l2) - - def test_linegroup_midpoint(self): - """ checks if correct midpoint of linegroup returned (getMidPoint) """ - #print(lg2) - ltest = LineGroup() - ltest.append(l1) - self.assertTrue(ltest.getMidPoint() == Point(1.5, 3.0, 0.0)) - - def test_linegroup_add_linegroup(self): - """ checks if linegroup is correctly added (addLineGroup) """ - ltest = LineGroup() - ltest.append(l1) - - ltest1 = LineGroup() - ltest1.append(l2) - ltest.addLineGroup(ltest1) - self.assertTrue(ltest[1] == l2) - - def test_linegroup_mirror(self): - """ checks if linegroup is correctly mirrored (mirror) """ - ltest = LineGroup() - ltest.append(l1) - - #ltest1 = LineGroup() - #ltest1.append(Line(Point(1,-2,3), Point(2,-4,6))) - - self.assertTrue(ltest.mirror(c.X)[0] == - Line(Point(1,-2,3), Point(2,-4,6))) - - def test_linegroup_sort(self): - """ checks if linegroup is sorted correctly (sort) """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l4) - ltest.sort() - self.assertTrue(ltest[0] == l4) - - def test_linegroup_fourcorners(self): - """ checks if the four corners correspond to the correct points """ - ltest = LineGroup() - ltest.append(l4) - ltest.append(l5) - self.assertTrue(ltest.fourCorners()[0] == Point(0,0,0)) - self.assertTrue(ltest.fourCorners()[1] == Point(4,0,0)) - self.assertTrue(ltest.fourCorners()[2] == Point(4,8,0)) - self.assertTrue(ltest.fourCorners()[3] == Point(0,8,0)) - - def test_linegroup_scale(self): - """ checks if start and end points of lines are scaled correctly """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - - self.assertTrue(ltest.scale(2,3)[0] == - Line(Point(2,6,3), Point(4,12,6))) - self.assertTrue(ltest.scale(2,3)[1] == - Line(Point(2,6,3), Point(12,36,18))) - - def test_linegroup_rotate(self): - """ checks if linegroup is rotated correctly """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - self.assertTrue(ltest.rotate(np.pi/2)[0] == - Line(Point(-2,1,3), Point(-4,2,6))) - self.assertTrue(ltest.rotate(np.pi/2)[1] == - Line(Point(-2,1,3), Point(-12,6,18))) - - def test_linegroup_translate(self): - """ checks if linegroup is translated correctly """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - self.assertTrue(ltest.translate(2,4)[0] == - Line(Point(3,6,3), Point(4,8,6))) - self.assertTrue(ltest.translate(2,4)[1] == - Line(Point(3,6,3), Point(8,16,18))) - - def test_linegroup_line_outside_boundingbox(self): - """ checks if the given line is outside the bounding box """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - self.assertTrue(ltest.lineOutsideBoundingBox(l4) == True) - self.assertTrue(ltest.lineOutsideBoundingBox(l5) == False) - - - def test_linegroup_line_add_points(self): - """ checks if line from given points is added to linegroup """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - p = [Point(1,1,0), Point(4,5,0)] - ltest.addLinesFromPoints(p) - self.assertTrue(ltest[2] == Line(Point(1,1,0), Point(4,5,0))) - - def test_linegroup_update_min_max(self): - """ checks if the max & min x and y values are updated correctly """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - l = Line(Point(10,20,0), Point(14,-16,0)) - ltest.append(l) - self.assertTrue(ltest.maxY == 20) - self.assertTrue(ltest.maxX == 14) - self.assertTrue(ltest.minY == -16) - self.assertTrue(ltest.minX == 1) - - def test_linegroup_line_add_coordlist(self): - """ checks if points from coordinate list added to linegroup """ - ltest = LineGroup() - ltest.append(l1) - k = [[3,4], [-6,7]] - ltest.addLinesFromCoordinateList(k) - self.assertTrue(ltest[1] == Line(Point(3,4,0), Point(-6,7,0))) - - def test_linegroup_transform(self): - """ checks if lines within group are transfromed correctly """ - ltest = LineGroup() - ltest.append(l1) - ltest.append(l2) - matr = [[0,0,0,1], [1,4,6,8], [0,6,7,9], [3,4,5,6]] - ltest = ltest.transform(matr) - self.assertTrue(ltest[0] == Line(Point(1,35,42),Point(1,62,75))) - self.assertTrue(ltest[1] == Line(Point(1,35,42), Point(1,170,207))) - -def main(): - unittest.main() - -if __name__ == '__main__': - main() \ No newline at end of file From 6588c9ad4f731641cae323c04808fc5b68c5a82d Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:57:32 -0500 Subject: [PATCH 29/30] Delete unittest(point,line).py --- unittest(point,line).py | 214 ---------------------------------------- 1 file changed, 214 deletions(-) delete mode 100644 unittest(point,line).py diff --git a/unittest(point,line).py b/unittest(point,line).py deleted file mode 100644 index 2eccfcb..0000000 --- a/unittest(point,line).py +++ /dev/null @@ -1,214 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Mon Jun 26 13:53:41 2017 - -@author: siddhant -""" - -import unittest -from point import Point -import constants as c -from line import Line -import numpy as np - - -p1 = Point(1.0, 2.0, 3.0) -p2 = Point(2.0, 4.0, 6.0) -p3 = Point(6.0, 12.0, 18.0) -p4 = Point(8.0, 12.0, 14.0) - -l1 = Line(p1, p2) -l2 = Line(p1, p3) -l3 = Line(p1, p2) -l4 = Line(Point(0,0), Point(0, 8, 0)) -l5 = Line(Point(4, 0, 0), Point(0, 6, 0)) - -class PointTestCase (unittest.TestCase): - - def test_point_equal(self): - """ check if point is equal to given point (__eq__) """ - self.assertTrue(p1 == Point(1.0, 2.0, 3.0)) - self.assertFalse(p1 == Point(1.0, 3.0, 4.0)) - - def test_point_notequal(self): - """ check points are not equal (__ne__) """ - self.assertTrue(p1 != Point(1.0, 2.0, 8.0)) - self.assertFalse(p1 != Point(1.0, 2.0, 3.0)) - - def test_point_negative(self): - """ check if point negative is correct (__neg_) """ - self.assertTrue(-p1 == Point(-1.0, -2.0, 3.0)) - - def test_point_lesser(self): - """ compare two points to check lesser (__lt__) """ - self.assertTrue(p1 < Point(2.0, 4.0, 6.0)) - self.assertFalse(p1 < Point(1.0, 2.0, 2.0)) - - def test_point_greater(self): - """ compare two points to check greater (__gt__) """ - self.assertTrue(p1 > Point(1.0, 2.0, 2.0)) - self.assertFalse(p1 > Point(1.0, 2.0, 6.0)) - - def test_point_sub(self): - """ check distance between two points (__sub__) """ - self.assertAlmostEqual(p2-p1, 3.7417, places = 4) - - def test_initial_x_property(self): - """ check if x-coordinate matches """ - self.assertTrue(p1.x == 1.0) - - def test_initial_y_propert(self): - """ check if y-coordinate matches """ - self.assertTrue(p1.y == 2.0) - - def test_initial_z_property(self): - """ check if z-coordinate matches """ - self.assertTrue(p1.z == 3.0) - - def test_get_item(self): - """ check if correct coordinate is returned and slice correctly""" - self.assertTrue(p1[0] == 1.0) - - def test_get_point2D(self): - """ check if x and y coordinates of point are correct """ - self.assertTrue(tuple(p1[0:2]) == (1.0, 2.0)) - - def test_squaredistance(self): - """ check squared distance between two points (squaredDistance) """ - self.assertTrue(((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2) == 5.0) - - def test_point_mirror(self): - """ check if point correctly mirrored about axis (mirror) """ - self.assertTrue(p1.mirror(c.X) == Point(1.0, -2.0, 3.0)) - - def test_point_translate(self): - """ check if point translates correctly (translate) """ - self.assertTrue(p1.translate(1.0, 2.0) == Point(2.0, 4.0, 3.0)) - - def test_point_rotate(self): - """ check if point rotates as expected (rotate) """ - self.assertTrue(p1.rotate(0) == Point(1.0, 2.0, 3.0)) - - def test_point_normal_vector(self): - """ checks if a normal vector is correctly returned (normalVector) """ - self.assertTrue(p1.normalVector[3] == 1.0) - - def test_point_point(self): - """ checks if sliced correctly to return first three elements (point) """ - self.assertTrue(tuple(p1.point) == (1.0, 2.0, 3.0)) - - def test_point_transform(self): - """ checks if the point is transformed correctly by matrix (transform) """ - mtr = [[1,2,3,1],[4,0,3,6],[2,7,0,4],[0,0,0,1]] - self.assertTrue(p1.transform(mtr) == Point(15,19,20)) - -class LineTestCase(unittest.TestCase): - - def test_length(self): - """ checks length of the line (length) """ - self.assertAlmostEqual(p2 - p1, 3.7417, places = 4) - - def test_fliped(self): - """ check if line flips direction as expected (fliped) """ - self.assertEqual(l1.fliped(), Line(p2, p1)) - - def test_on_line(self): - """ checks if given point is on line (isOnLine) """ - self.assertTrue(l1.isOnLine(p2) == True) - - def test_mirror_line(self): - """ check if line mirrored correctly about given axis (mirror) """ - self.assertTrue(l1.mirror(c.X) == - Line(Point(1.0, -2.0, 3.0), Point(2.0, -4.0, 6.0))) - - def test_lines_parallel(self): - """ checks if the lines are parallel (areParallel) """ - self.assertTrue(l1.areParallel(l2) == True) - - def test_line_start(self): - """ checks if starting point of line is correct """ - self.assertTrue(l1.start == p1) - - def test_line_end(self): - """ checks if end point of line is correct """ - self.assertTrue(l1.end == p2) - - def test_line_angle(self): - """ checks if line is oriented correctly by way of angle """ - self.assertAlmostEqual(l1.angle, 1.1071, places = 4) - - def test_line_midpoint(self): - """ checks if midpoint of line is correct (getMidPoint) """ - self.assertTrue(l1.getMidPoint() == Point(1.5, 3.0, 4.5)) - - def test_line_equal(self): - ' checks if lines with same start and end points are equal (__eq__) ' - self.assertTrue(l1 == l3) - self.assertFalse(l1 != l3) - - def test_line_lesser(self): - """ checks if line is less than other (__lt__) """ - self.assertTrue(l1 < l2) - self.assertFalse(l2 < l1) - - def test_line_calcT(self): - """ checks if point located at correct distance from start (calcT) """ - self.assertTrue(l1.calcT(p2) == 1.0) - - def test_line_translate(self): - """ checks if line is translated correctly (translate) """ - self.assertTrue(l1.translate(1.0, 2.0, 1.0) == - Line(Point(2.0, 4.0, 4.0), Point(3.0, 6.0, 7.0))) - - def test_line_rotate(self): - """ checks if line is rotated correctly (rotate) """ - self.assertTrue(l1.rotate(np.pi/2, Point(0,0)) == - Line(Point(-2.0, 1.0, 3.0), Point(-4.0, 2.0, 6.0))) - - def test_line_bounding_boxes(self): - """ checks if bounding boxes of two lines intersect """ - self.assertTrue(l1.doBoundingBoxesIntersect(l2) == True) - self.assertFalse(l1.doBoundingBoxesIntersect(l2) == False) - - def test_line_point_to_line_distance(self): - """ checks the distance between point and line (pointToLineDist) """ - self.assertAlmostEqual(l1.pointToLineDist(p4), 1.7889, places = 4) - - def test_get_offset_line(self): - """ checks if correct offset line returned (getOffsetLine) """ - self.assertTrue(l4.getOffsetLine(4) == - Line(Point(-4.0, 0.0, 0.0), Point(-4.0, 8.0, 0.0))) - - def test_get_area(self): - """ checks if area of triangle is correct (getArea) """ - self.assertAlmostEqual(l1.getArea(p1, p2, p4), 1.0000, places = 4) - - def test_are_colinear(self): - """ checks if two lines are colinear (areColinear) """ - self.assertTrue(l1.areColinear(l2) == True) - self.assertFalse(l1.areColinear(l2) != True) - - def test__side_of_line(self): - """ unsure about precise description """ - self.assertTrue(l1.sideOfLine(p4) == 1) - - def test_do_lines_intersect(self): - """ checks if lines intersect and returns nature of intersection """ - self.assertTrue(l4.segmentsIntersect(l5) == - (1, Point(0, 6, 0))) - - def test_line_upper_left(self): - """ checks if upper left point of line is correct """ - self.assertTrue(l4.upperLeft == Point(0.0, 8.0, 0.0)) - - def test_line_lower_right(self): - """ checks if lower right point of line is correct """ - self.assertTrue(l4.lowerRight == Point(0.0, 0.0)) - - - -def main(): - unittest.main() - -if __name__ == '__main__': - main() \ No newline at end of file From 038ef4d66e9eed07c21c8fd5dc7d047af1204073 Mon Sep 17 00:00:00 2001 From: Siddhant Shah Date: Wed, 2 Aug 2017 13:57:46 -0500 Subject: [PATCH 30/30] Rename unittest_point_line.py to unittest1_point_line.py --- unittest_point_line.py => unittest1_point_line.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename unittest_point_line.py => unittest1_point_line.py (100%) diff --git a/unittest_point_line.py b/unittest1_point_line.py similarity index 100% rename from unittest_point_line.py rename to unittest1_point_line.py