Ejemplo n.º 1
0
    def test_ccw_returns_zero_when_points_are_collinear(self):
        # Act.
        expected_ccw_value = sign(np.cross(self.p1_to_p2, self.p1_to_p3))
        actual_ccw_value = sign(geom.ccw(self.p1, self.p2, self.p3))

        # Assert.
        self.assertEqual(expected_ccw_value, actual_ccw_value)
Ejemplo n.º 2
0
    def test_ccw_returns_negative_value_when_angle_formed_has_negative_orientation(
            self):
        # Act.
        expected_sign = sign(np.cross(self.p1_to_p4, self.p1_to_p2))
        actual_sign = sign(geom.ccw(self.p4, self.p1, self.p2))

        # Assert.
        self.assertEqual(expected_sign, actual_sign)
Ejemplo n.º 3
0
 def mouse_over(self, x, y):
     from geometry import ccw
     # to check if cursor is pointing at one of the switch-buttons,
     # we just test if cursor position is inside polygon, by checking if
     # all segments are in counter-clockwise order to cursor position:
     for j, element in enumerate(self.points):
         for i, point in enumerate(element):
             if i == len(element) - 1:
                 edge = (point, element[0], (x, y))
             else:
                 edge = (point, element[i + 1], (x, y))
             if ccw(edge):
                 break
         else:
             self.active_button = j
             return True
     self.active_button = None
     return False
Ejemplo n.º 4
0
 def contains_wn(self, point):
     size = len(self.vertices)
     if size == 0:
         return False
     s = 0.0
     for i in range(0, size - 1):
         v1 = self.vertices[i].p
         if point == v1:
             return True
         v2 = self.vertices[i + 1].p
         if point == v2:
             return True
         if ccw(point, v1, v2):
             s += angle(v1, point, v2)
         else:
             s -= angle(v1, point, v2)
     s = s.real
     print(s)
     print(fabs(fabs(s) - 2 * PI))
     return fabs(fabs(s) - 2 * PI) < EPS