Ejemplo n.º 1
0
 def B(self, value):
     if not _isNum(value):
         raise TypeError
     if isZero(self._A) and isZero(value):
         raise ValueError
     self._B = value
     self._modify = True
Ejemplo n.º 2
0
 def __init__(self, A, B, C):
     if not (_isNum(A) and _isNum(B) and _isNum(C)):
         raise TypeError
     if isZero(A) and isZero(B):
         raise ValueError
     self._A = A
     self._B = B
     self._C = C
     self._slope = None
     self._modify = True
Ejemplo n.º 3
0
 def slope(self):
     if self._modify:
         if isZero(self._B):
             self._slope = MATH.NaN
         else:
             self._slope = -self._A / self._B
         self._modify = False
     return self._slope
Ejemplo n.º 4
0
 def slope(self):
     if self._modify_s:
         if isZero(self._p1.x - self._p2.x):
             self._slope = None
         else:
             self._slope = math.atan(
                 ((self._p2.y - self._p1.y) / (self._p2.x - self._p1.x)))
         self._modify_s = False
     return self._slope
Ejemplo n.º 5
0
 def toSegment(self, x1, x2):
     if isZero(self._B):
         y1, y2 = x1, x2
         _x = -(self._C / self._A)
         return Segment(Point(_x, y1), Point(_x, y2))
     else:
         p1 = Point(x1, -(self._A * x1 + self._C) / self._B)
         p2 = Point(x2, -(self._A * x2 + self._C) / self._B)
         return Segment(p1, p2)
Ejemplo n.º 6
0
 def __eq__(self, other):
     return isZero(self._x - other.x) and isZero(self._y - other.y)
Ejemplo n.º 7
0
    p1 = Point(1, 2)
    p2 = Point(3, 4)
    p3 = Point(5, 6)
    p4 = Point(7, 8)
    p5 = Point(0, 0)
    p6 = Point(1, 0)
    p7 = Point(1, 1)
    p8 = Point(0, 1)
    s1 = Segment(p1, p2)
    s2 = Segment(p2, p3)
    l1 = Line([p1, p2, p3])
    l2 = Line([p1, p2, p3, p4])
    poly1 = Polygon([p5, p6, p7, p8])
    poly2 = Polygon([p5, p6, p7, p8, p5])
    assert (str(p1) == 'Point(1, 2)')
    assert (str(p1 + p2) == 'Point(4, 6)')
    assert (str(p1 - p2) == 'Point(-2, -2)')
    assert (str(p1 * 2) == 'Point(2, 4)')
    assert (isZero(s1.length - math.sqrt(8)))
    assert (isZero(l1.length - math.sqrt(8) * 2))
    assert (l1.size() == 3)
    assert (l2.toSegments()[0].length == s1.length)
    assert (poly1.perimeter == 4)
    assert (poly2.length() == 4)
    assert (poly1.area == 1)
    assert (poly2.area == 1)
    print(l1)
    print(l2)
    print(poly1)
    print(poly2)