Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4a13cc0
a tester for the linegroup class
ssshah9 Jul 5, 2017
a2c407a
tests added for linegroup
Jul 6, 2017
b7767ac
Rectified issues in linegroup
ssshah9 Jul 7, 2017
5b667de
Added tests for matrix transformations
ssshah9 Jul 10, 2017
1e3fdb0
Tests for outline
ssshah9 Jul 11, 2017
e461a19
Additional tests for outline
ssshah9 Jul 12, 2017
2fb3e02
Added tests for point
ssshah9 Jul 18, 2017
91ada28
variable names changed for outline
ssshah9 Jul 21, 2017
a33e67b
added tests for infill
Jul 24, 2017
9d971dd
made changes to addInternalShape
ssshah9 Jul 25, 2017
b320dd6
corrected test for addInternalShape
ssshah9 Jul 25, 2017
3e206f6
added tests for false cases
ssshah9 Jul 25, 2017
41a52fd
added test for arcToLines
ssshah9 Jul 25, 2017
72f0767
changed file name, indicates specific module for which tests are written
ssshah9 Jul 31, 2017
48dc41d
changed file name
ssshah9 Jul 31, 2017
45bf39c
changed file name
ssshah9 Jul 31, 2017
4481bea
changed file name
ssshah9 Jul 31, 2017
52cf352
changed file name
ssshah9 Jul 31, 2017
52efe4f
Delete pointtest.py
ssshah9 Jul 31, 2017
437d341
Rename unittest.py to unittest_point_line.py
ssshah9 Aug 2, 2017
0b51b78
Rename unittest2.py to unittest2_linegroup.py
ssshah9 Aug 2, 2017
e9d0f90
Rename unittest3.py to unittest3_arc_matrix.py
ssshah9 Aug 2, 2017
6e75cdb
Rename unittest4.py to unittest4_outline.py
ssshah9 Aug 2, 2017
73e0555
Rename unittest5.py to unittest5_infill.py
ssshah9 Aug 2, 2017
26e35e5
Delete unittest5(infill).py
ssshah9 Aug 2, 2017
119bfb6
Delete unittest4(outline).py
ssshah9 Aug 2, 2017
3111581
Delete unittest3(arc,matrix).py
ssshah9 Aug 2, 2017
485eae0
Delete unittest2(linegroup).py
ssshah9 Aug 2, 2017
6588c9a
Delete unittest(point,line).py
ssshah9 Aug 2, 2017
038ef4d
Rename unittest_point_line.py to unittest1_point_line.py
ssshah9 Aug 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions infill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
Expand Down
9 changes: 4 additions & 5 deletions outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 0 additions & 34 deletions pointtest.py

This file was deleted.

19 changes: 15 additions & 4 deletions unittest.py → unittest1_point_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -91,6 +89,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):
Expand Down Expand Up @@ -157,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) """
Expand Down Expand Up @@ -200,4 +211,4 @@ def main():
unittest.main()

if __name__ == '__main__':
main()
main()
200 changes: 200 additions & 0 deletions unittest2_linegroup.py
Original file line number Diff line number Diff line change
@@ -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()
Loading