Beispiel #1
0
 def test_y_axis_line(self):
     p1 = Point(0, 0)
     p2 = Point(0, 5)
     l = Line(p1, p2)
     result = l.length()
     expected = 5
     self.assertEqual(result, expected)
Beispiel #2
0
 def test_same_point_len(self):
     p1 = Point(1, 1)
     p2 = Point(1, 1)
     l = Line(p1, p2)
     result = l.length()
     expected = 0
     self.assertEqual(result, expected)
Beispiel #3
0
 def read(self, path):
     with open(path, 'rb') as f:
         file = f.read()
         head = str(file).split('$$HEADEREND')
         head = head[0].split('\\n')
         #print(head)
         for line in head:
             if '$$UNITS' in line:
                 self.unit = float(line.split('/')[1])
             if '$$DIMENSION' in line:
                 bound = line.split('/')[1]
                 Xmin, Ymin, Zmin, Xmax, Ymax, Zmax = bound.split(',')
                 self.Xmin = float(Xmin)
                 self.Ymin = float(Ymin)
                 self.Zmin = float(Zmin)
                 self.Xmax = float(Xmax)
                 self.Ymax = float(Ymax)
                 self.Zmax = float(Zmax)
             if '$$LAYERS' in line:
                 self.layer = int(line.split('/')[1])
         #print(head[0])
         f.seek(226, 0)
         ty = struct.unpack('<H', f.read(2))
         #print("type:",ty)
         try:
             while True:
                 layer = struct.unpack('<H', f.read(2))
                 #print("layer:",layer)
                 Mypoint = []
                 while True:
                     mypoint = []
                     readtpye = struct.unpack('<H', f.read(2))
                     #print("readtype:",readtpye)
                     if readtpye[0] == 128:
                         break
                     ID, Direction, Point_Num = struct.unpack(
                         '<HHH', f.read(6))
                     '''print("ID:",ID)
                     print("Direction:",Direction)
                     print("Point_Num:",Point_Num)'''
                     for i in range(Point_Num):
                         x, y = struct.unpack('<HH', f.read(4))
                         mypoint.append(Point(x * self.unit, y * self.unit))
                     Mypoint.append(mypoint)
                 self.UsePoint.append(Mypoint)
         except:
             self.UsePoint.append(Mypoint)
Beispiel #4
0
 def addCoordinatePoint(self, x: float, y: float):
     self.points.append(Point(x, y))
     self.addLine((x, 0), (x, y)).linewidth(0.5).linestyle('--')
     self.addLine((0, y), (x, y)).linewidth(0.5).linestyle('--')
Beispiel #5
0
 def addPoint(self, x: float, y: float):
     self.points.append(Point(x, y))
Beispiel #6
0
def line_inter_test(p1x, p1y,
                    p2x, p2y,
                    p3x, p3y,
                    p4x, p4y):
    print 'test if line ((' + str(p1x) + ', ' + str(p1y) + '), (' +\
          str(p2x) + ', ' + str(p2y) + ')), ((' + str(p3x) + ', ' + str(p3y) + '), (' + \
          str(p4x) + ', ' + str(p4y) + ')) intersects'
    pa = Point()
    pb = Point()
    pc = Point()
    pd = Point()
    l1 = Line()
    l2 = Line()
    pa.set_coord(p1x, p1y)
    pb.set_coord(p2x, p2y)
    pc.set_coord(p3x, p3y)
    pd.set_coord(p4x, p4y)
    l1.set_line_by_point(pa, pb)
    l2.set_line_by_point(pc,pd)
    return l1.do_lines_intersect(l2)
Beispiel #7
0
from line import Line
from line import Point

print 'testing line'

print 'testing line is set...'
l = Line()
print 'test not set'
assert not l.line_is_set()
l.set_line_by_coord(0, 0, 1, 1)
print 'test set'
assert l.line_is_set()
l = Line()
p1 = Point()
p2 = Point()
l.set_line_by_point(p1, p2)
print 'test setting by point not set'
assert not l.line_is_set()
p1.set_coord(0, 0)
p2.set_coord(1, 1)
assert l.line_is_set()
print 'test line with same start and end'
p2.set_coord(0, 0)
assert not l.line_is_set()

print 'testing get line...'
l = Line()
p1 = Point()
p1.set_coord(0, 0)
p2 = Point()
p2.set_coord(1, 1)
 def setUp(self):
     # y = x
     self.line_yx = Line([Point(0, 0), Point(7, 7)])
     # x = 1
     self.line_x = Line([Point(1, -3), Point(1, 20)])
 def test_intersect6(self):
     point = self.line_yx.intersect(Line([Point(1, -1), Point(-100, 100)]))
     self.assertEqual((Point(0, 0).x, Point(0, 0).y), (point.x, point.y))
 def test_intersect5(self):
     self.assertEqual(
         self.line_yx,
         self.line_yx.intersect(Line([Point(1, 1),
                                      Point(-2, -2)])))
 def test_intersect4(self):
     self.assertEqual(
         None, self.line_yx.intersect(Line([Point(-1, -3),
                                            Point(3, 1)])))
 def test_intersect3(self):
     point = self.line_x.intersect(self.line_yx)
     self.assertEqual((Point(1, 1).x, Point(1, 1).y), (point.x, point.y))
 def test_intersect2(self):
     self.assertEqual(
         self.line_x, self.line_x.intersect(Line([Point(1, 1),
                                                  Point(1, 4)])))
 def test_intersect1(self):
     self.assertEqual(
         None, self.line_x.intersect(Line([Point(3, 1),
                                           Point(3, 4)])))