def translate(self, other): """Return a new vector that is this vector translated by the other vector (parallelogram rule) """ coords = [] for i in range(max(len(self), len(other))): coords.append(self[i] + Point._get_coord(other, i)) return Vector(*coords)
def point(self, center=()): """Return the point that is the specified center point translated by this vector """ coords = [] for i in range(max(len(self), len(center))): coords.append(self[i] - Point._get_coord(center, i)) return Point(*coords)
def test_bounding_box_with_origin_not_at_0_0(self): ground_plane = GroundPlane(20, Point(-5, 30)) expected_box = BoundingBox(Point(-15, 20), Point(5, 40))
def ignore(point): return (Point.turn(boundary.a, boundary.b, point) == Point.CW_TURN or funnel.position_of(point) != good_position)
def jarvis_march(polygon: Polygon, start_index: int, end_index: int, direction: int, good_turn: int, predicate: Callable[[Point], T], ignore: Callable[[Point], bool]=lambda x: False ) -> Iterable[Point]: """Do a Jarvis march on the given polygon. We start at start_index going into direction stopping at end_index. For every vertex we consider appropriate predicate is applied. If it yields something which not evaluates to False we immediately stop the march and return the predicate result together with the vertex and a list of all points visited beforehand. Args: ignore: A function which is called for every vertex and should return True iff this vertex is to be ignored during the jarvis march. polygon: A polygon. start_index: The index of the starting vertex. end_index: The index of the last vertex to consider. direction: The direction in which we walk along the polygon edge. Needs to be either 1 or -1. good_turn: If the current, the next and a third vertex form a turn that is the same as good_turn, the third will be chosen over the next. predicate: A function that takes a vertex as an argument and decides whether to continue the march or stop. Returns: A 3-tuple (result, point, visited) in which result is the result of the predicate function, point is the point which fulfils the predicate and visited is a list of vertices visited in between. Raises: AssertionError: a) A type check fails. b) None of the vertices in the specified range fulfilled the predicate. """ # ========================================================================== # Type checking. # ========================================================================== assert isinstance(polygon, Polygon) assert isinstance(start_index, int) assert isinstance(end_index, int) assert isinstance(direction, int) assert isinstance(good_turn, int) first = polygon.point(start_index) while True: shortest_path.properties['predicates'] += 1 result = predicate(first) # If the result does not evaluate to False return if result: return result, first # If this assertion fails none of the vertices fulfilled the predicate assert first.index != end_index second = polygon.point(first.index + direction) if second.index != end_index: for index in polygon.indices(second.index + direction, end_index, direction): point = polygon.point(index) shortest_path.properties['ignores_theo'] += 1 if Point.turn(first, second, point) == good_turn: shortest_path.properties['ignores'] += 1 if not ignore(point): second = polygon.point(index) yield first first = second
def exportAsPoint(self): return Point(self.x, self.y)
def exportPrefFncY(self): return PrefFncY([Point(0, 0), Point(1, self.iy), Point(0, 1)])
def test_center_point(self): null_arc = Arc(Point(0, 0), 90, 10, 0.0) self.assertAlmostEqual(null_arc.center_point(), Point(-10, 0)) arc = Arc(Point(0, 0), 30, 10, 1) self.assertAlmostEqual(arc.center_point(), Point(-5, 8.660254037)) arc = Arc(Point(0, 0), 30, 10, -1) self.assertAlmostEqual(arc.center_point(), Point(5, -8.660254038)) arc = Arc(Point(0, 0), -60, 10, 1) self.assertAlmostEqual(arc.center_point(), Point(8.660254038, 5)) arc = Arc(Point(0, 0), -60, 10, -1) self.assertAlmostEqual(arc.center_point(), Point(-8.660254038, -5)) arc = Arc(Point(1, 0), 90, 1, 180).counter_clockwise() self.assertAlmostEqual(arc.center_point(), Point(0, 0))
def to_game_coordinates(self, pos: QPoint) -> Point: x = pos.x() // (self.width() // self.game_state.width) y = pos.y() // (self.height() // self.game_state.height) return Point(x, y)
def test_from_points_in_circle(self): # with start_point = end_point circle = Circle(Point(0, 0), 1) point = Point(1, 0) arc = Arc.from_points_in_circle(point, point, circle) self.assertEqual(arc, Arc(point, 90, 1, 0)) # with start point different to end point circle = Circle(Point(5, 5), 1) start_point = Point(6, 5) end_point = Point(5, 6) arc = Arc.from_points_in_circle(start_point, end_point, circle) self.assertEqual(arc, Arc(start_point, 90, 1, 90)) # in the lower half-plane circle = Circle(Point(0, 0), 1) start_point = Point(0, -1) end_point = Point(1, 0) expected_arc = Arc(Point(0, -1), 0, 1, 90) self.assertEqual( Arc.from_points_in_circle(start_point, end_point, circle), expected_arc) # with angular length greater than 180 circle = Circle(Point(0, 0), 1) start_point = Point(1, 0) end_point = Point(0, -1) arc = Arc.from_points_in_circle(start_point, end_point, circle) self.assertEqual(arc, Arc(start_point, 90, 1, 270))
def dot(self, other): """Return the dot product of this vector with the other vector""" d = 0 for i in range(max(len(self), len(other))): d += self[i]*Point._get_coord(other, i) return d
def test_compute_point_at(self): arc1 = Arc(Point(5, 3), 90, 2, 100) self.assertEqual(arc1._compute_point_at(90), Point(3, 5)) arc2 = Arc(Point(5, 3), 270, 2, -100) self.assertAlmostEqual(arc2._compute_point_at(-90), Point(3, 1))
def test_end_point_after_counter_clockwise(self): arc = Arc(Point(1, 0), -90, 1, -180).counter_clockwise() self.assertAlmostEqual(arc.end_point(), Point(1, 0))
def test_find_arc_intersection_with_arcs_in_the_same_circle(self): # intersection between and arc and itself arc = Arc(Point(4, 3), 67, 2, 99) self.assertEqual(arc._find_arc_intersection(arc), [arc]) # with no intersection arc1 = Arc(Point(1, 0), 90, 1, 90) arc2 = Arc(Point(-1, 0), 270, 1, 90) self.assertEqual(arc1._find_arc_intersection(arc2), []) # with one point intersection arc1 = Arc(Point(1, 0), 90, 1, 90) arc2 = Arc(Point(0, 1), 180, 1, 90) self.assertAlmostEqual(arc1._find_arc_intersection(arc2), [Point(0, 1)]) self.assertAlmostEqual(arc2._find_arc_intersection(arc1), [Point(0, 1)]) # with two points intersection arc1 = Arc(Point(1, 0), 90, 1, 180) arc2 = Arc(Point(1, 0), -90, 1, -180) self.assertAlmostEqual(arc1._find_arc_intersection(arc2), [Point(-1, 0), Point(1, 0)]) self.assertAlmostEqual(arc2._find_arc_intersection(arc1), [Point(1, 0), Point(-1, 0)]) # with one arc intersection arc1 = Arc(Point(0, -1), 0, 1, 180) arc2 = Arc(Point(1, 0), 90, 1, 180) expected_arc = Arc(Point(1, 0), 90, 1, 90) self.assertEqual(arc1._find_arc_intersection(arc2), [expected_arc]) self.assertEqual(arc2._find_arc_intersection(arc1), [expected_arc]) # with one arc contained in the other arc1 = Arc(Point(2, 4), -90, 2, 270) arc2 = Arc(Point(6, 4), 270, 2, -90) self.assertAlmostEqual(arc1._find_arc_intersection(arc2), [Arc(Point(4, 2), 0, 2, 90)]) self.assertAlmostEqual(arc2._find_arc_intersection(arc1), [Arc(Point(4, 2), 0, 2, 90)]) # with same start point and different end points arc1 = Arc(Point(0, -1), 0, 1, 90) arc2 = Arc(Point(0, -1), 0, 1, 180) self.assertAlmostEqual(arc1._find_arc_intersection(arc2), [arc1]) self.assertAlmostEqual(arc2._find_arc_intersection(arc1), [arc1]) # with the same end point and different start points arc1 = Arc(Point(1, 0), 90, 1, 180) arc2 = Arc(Point(0, 1), 180, 1, 90) self.assertAlmostEqual(arc1._find_arc_intersection(arc2), [arc2]) self.assertAlmostEqual(arc2._find_arc_intersection(arc1), [arc2]) # with two arcs intersection arc1 = Arc(Point(-1, 0), 270, 1, 270) arc2 = Arc(Point(1, 0), 90, 1, 270) expected_intersection = [ Arc(Point(1, 0), 90, 1, 90), Arc(Point(-1, 0), 270, 1, 90) ] self.assertAlmostEqual(arc1._find_arc_intersection(arc2), expected_intersection) # with and arc in clockwise direction arc1 = Arc(Point(0, 1), 0, 1, -270) arc2 = Arc(Point(1, 0), 90, 1, 270) expected_intersection = [ Arc(Point(1, 0), 90, 1, 90), Arc(Point(-1, 0), 270, 1, 90) ] self.assertAlmostEqual(arc1._find_arc_intersection(arc2), expected_intersection)
def test_find_arc_intersection_with_circles_that_intersect_but_no_arc_intersection( self): arc1 = Arc(Point(5, 0), 90, 5, 10) arc2 = Arc(Point(0, 3), 0, 5, 10) self.assertEqual(arc1._find_arc_intersection(arc2), [])
def test_includes_point(self): arc_90_deg = Arc(Point(0, 0), 90, 10, 90) self.assertTrue(arc_90_deg.includes_point(Point(0, 0))) self.assertTrue( arc_90_deg.includes_point(Point(-2.92893219, 7.07106781))) self.assertTrue(arc_90_deg.includes_point(Point(-10, 10))) arc_135_neg_deg = Arc(Point(0, 0), 90, 10, -135) self.assertTrue(arc_135_neg_deg.includes_point(Point(0, 0))) self.assertTrue( arc_135_neg_deg.includes_point(Point(2.92893219, 7.07106781))) self.assertTrue( arc_135_neg_deg.includes_point(Point(17.07106781, 7.07106781))) arc_270_deg = Arc(Point(-1, 0), 90, 3, 270) self.assertTrue(arc_270_deg.includes_point(Point(-4, -3))) null_arc = Arc(Point(0, 0), 80, 20, 0) self.assertTrue(null_arc.includes_point(Point(0, 0))) arc = Arc(Point(0, -1), 0, 1, 180) self.assertFalse(arc.includes_point(Point(0, 0))) self.assertFalse(arc.includes_point(Point(-1, 0))) arc = Arc(Point(1, 0), -90, 1, -180).counter_clockwise() self.assertTrue(arc.includes_point(Point(-1, 0))) self.assertTrue(arc.includes_point(Point(1, 0))) arc1 = Arc(Point(1, 0), 90, 1, 180).counter_clockwise() arc2 = Arc(Point(1, 0), -90, 1, -180).counter_clockwise() self.assertTrue(arc1.includes_point(arc2.start_point())) self.assertTrue(arc1.includes_point(arc2.end_point()))
def __sub__(self, other): coords = [] for i in range(max(len(self), len(other))): coords.append(self[i] - Point._get_coord(other, i)) return Vector(*coords)
def get_coord(self, i): """Get the i coordinate of this vector. Return 0 if past the end.""" return Point._get_coord(self.coordinates, i)
def test_null_arc_end_point(self): null_arc = Arc(Point(0, 0), 90, 10, 0) self.assertAlmostEqual(null_arc.end_point(), Point(0, 0))
def get_near_points_with_cord(self, x, y) -> Iterable[Point]: return self.get_near_points_with_point(Point(x, y))
def test_almost_equal_to(self): arc1 = Arc(Point(1, 0), 90, 1, 180).counter_clockwise() arc2 = Arc(Point(1, 0), -90, 1, -180).counter_clockwise() self.assertFalse(arc1.almost_equal_to(arc2))
def test_merge(self): arc1 = Arc(Point(1, 0), 90, 1, 90) arc2 = Arc(Point(0, 1), 180, 1, 90) self.assertAlmostEqual(arc1.merge(arc2), Arc(Point(1, 0), 90, 1, 180)) arc3 = Arc(Point(1, 0), 270, 1, -90) self.assertRaises(ValueError, lambda: arc1.merge(arc3))
def test_axis_aligned_arc_end_point(self): # Positive heading and angular length arc_90_deg = Arc(Point(0, 0), 90, 10, 90) self.assertAlmostEqual(arc_90_deg.end_point(), Point(-10, 10)) arc_180_deg = Arc(Point(0, 0), 90, 10, 180) self.assertAlmostEqual(arc_180_deg.end_point(), Point(-20, 0)) arc_270_deg = Arc(Point(0, 0), 90, 10, 270) self.assertAlmostEqual(arc_270_deg.end_point(), Point(-10, -10)) arc_360_deg = Arc(Point(0, 0), 90, 10, 360) self.assertAlmostEqual(arc_360_deg.end_point(), Point(0, 0)) # Positive heading and negative angular length arc_minus_90_deg = Arc(Point(0, 0), 90, 10, -90) self.assertAlmostEqual(arc_minus_90_deg.end_point(), Point(10, 10)) arc_minus_180_deg = Arc(Point(0, 0), 90, 10, -180) self.assertAlmostEqual(arc_minus_180_deg.end_point(), Point(20, 0)) arc_minus_270_deg = Arc(Point(0, 0), 90, 10, -270) self.assertAlmostEqual(arc_minus_270_deg.end_point(), Point(10, -10)) arc_minus_360_deg = Arc(Point(0, 0), 90, 10, -360) self.assertAlmostEqual(arc_minus_360_deg.end_point(), Point(0, 0)) # Negative heading and positive angular length arc_minus_90_deg = Arc(Point(0, 0), -90, 10, 90) self.assertAlmostEqual(arc_minus_90_deg.end_point(), Point(10, -10)) arc_minus_180_deg = Arc(Point(0, 0), -90, 10, 180) self.assertAlmostEqual(arc_minus_180_deg.end_point(), Point(20, 0)) arc_minus_270_deg = Arc(Point(0, 0), -90, 10, 270) self.assertAlmostEqual(arc_minus_270_deg.end_point(), Point(10, 10)) arc_minus_360_deg = Arc(Point(0, 0), -90, 10, 360) self.assertAlmostEqual(arc_minus_360_deg.end_point(), Point(0, 0)) # Negative heading and angular length arc_90_deg = Arc(Point(0, 0), -90, 10, -90) self.assertAlmostEqual(arc_90_deg.end_point(), Point(-10, -10)) arc_180_deg = Arc(Point(0, 0), -90, 10, -180) self.assertAlmostEqual(arc_180_deg.end_point(), Point(-20, 0)) arc_270_deg = Arc(Point(0, 0), -90, 10, -270) self.assertAlmostEqual(arc_270_deg.end_point(), Point(-10, 10)) arc_360_deg = Arc(Point(0, 0), -90, 10, -360) self.assertAlmostEqual(arc_360_deg.end_point(), Point(0, 0))
from geometry.point import Point from geometry.line import Line, Ray, Segment, Line2D import sympy.geometry.point import sympy.geometry.line import time t0 = time.clock() p1_my = Point(1, 0) p2_my = Point(0, 1) p3_my = Point(1, 1) p4_my = Point(10, 1) p5_my = Point(1, 0) p6_my = Point(10, 0) # p7_my = Point(2, -2) # print(p7_my) # --------------test line -----------------# l1 = Line2D(p1_my, p2_my) l2 = Line(p3_my, p4_my) l3 = Line(p5_my, p6_my) # print(l3) # print(l2) # print(l1.args) # print(l1.direction) # print(l1.angle_between(l2)) # print(l1.is_parallel(l2)) # print(l3.is_parallel(l2)) # print(l3.is_parallel(l3))
def test_points_at_linear_offset(self): # with one point arc = Arc(Point(0, -1), 0, 1, 180) self.assertAlmostEqual(arc.points_at_linear_offset(Point(2, 0), 1), [Point(1, 0)]) # with two points in the arc arc = Arc(Point(0, -1), 0, 1, 180) expected_points = [ Point(1.0 / 2, math.sqrt(3.0 / 4)), Point(1.0 / 2, -math.sqrt(3.0 / 4)) ] self.assertAlmostEqual(arc.points_at_linear_offset(Point(1, 0), 1), expected_points) # with two points in the circle but only one in the arc arc = Arc(Point(0, -1), 0, 1, 90) expected_point = [Point(1.0 / 2, -math.sqrt(3.0 / 4))] self.assertAlmostEqual(arc.points_at_linear_offset(Point(1, 0), 1), expected_point) # with two points in the circle but none in the arc arc = Arc(Point(0, -1), 180, 1, -90) self.assertAlmostEqual(arc.points_at_linear_offset(Point(1, 0), 1), []) # with all the points in the arc at the given offset arc = Arc(Point(0, -1), 0, 1, 180) self.assertAlmostEqual(arc.points_at_linear_offset(Point(0, 0), 1), [arc])
def exportPrefFncX(self): return PrefFncX([Point(0, 0), Point(self.ix, 1), Point(1, 0)])
def test_split_into(self): arc = Arc(Point(0, 0), 90, 1, 90) self.assertRaises( ValueError, lambda: arc.split_into([(Point(0, 0), Point(-2, 0))]))
def __showModelBasedOnForm(self, cModel): #upModel:UserProfileModel self.upModel = self.userProfileModelStructured.exportAsUserProfileModel( self.linPrefModelConf) # pointsVisitedPC:List<PointWithID> self.pointsWithIDVisitedPC = self.upModel.pointsWithIdDCToPointsWithIdPC( self.pointsWithIdVisitedDC) # preferences:list<float> self.preferences = self.upModel.aggrFnc.preferenceOfPointsWitIDInPC( self.pointsWithIDVisitedPC, self.linPrefModelConf) # aggrLine:LineSegment aggrLine = self.upModel.aggrFnc.exportAsLineSegment( Point(self.aggrLevel, self.aggrLevel), self.linPrefModelConf) # contorLines:LineSegment[] contorLines = self.upModel.getMorphismOfAggregationFncToDataCubeLines( self.aggrLevel, self.linPrefModelConf) # pointsWithIdVisitedPXC:List<PointWithID> pointsWithIdVisitedPXC = [ PointWithID( Point(self.pointsWithIdVisitedDC[i].point.x, self.pointsWithIDVisitedPC[i].point.y), self.pointsWithIdVisitedDC[i].pointID) for i in range(len(self.pointsWithIdVisitedDC)) ] # pointsWithIdVisitedPYC:List<PointWithID> pointsWithIdVisitedPYC = [ PointWithID( Point(self.pointsWithIDVisitedPC[i].point.x, self.pointsWithIdVisitedDC[i].point.y), self.pointsWithIDVisitedPC[i].pointID) for i in range(len(self.pointsWithIdVisitedDC)) ] # selectedPointWithIdDC:PointWithId selectedPointWithIdDC = None if self.selectedPointIdDC is None else PointsWithID( self.pointsWithIdVisitedDC).exportPoint(self.selectedPointIdDC) cModel.addPrefFncX(self.upModel.prefFncX, self.colorU1) cModel.addPrefFncY(self.upModel.prefFncY, self.colorU1) cModel.addAggregationFnc(aggrLine, self.colorU1) cModel.addContorLines(contorLines, self.colorU1) cModel.addDataCubePoints(self.pointsWithIdVisitedDC, self.pointLabelsDC, self.colorU1) cModel.addDataCubePoints(self.pointsWithIdNoVisitedDC, self.pointLabelsDC, Qt.yellow) cModel.addDataCubePoint(selectedPointWithIdDC, self.pointLabelsDC, Qt.red) cModel.addPrefFncXCubePoints( [p for p in pointsWithIdVisitedPXC if self.pointsPrefFncX], self.colorU1) cModel.addPrefFncYCubePoints( [p for p in pointsWithIdVisitedPYC if self.pointsPrefFncY], self.colorU1) cModel.addPrefCubePoints(self.pointsWithIDVisitedPC, self.pointLabelsPC, self.colorU1) cModel.auxiliaryLinesDataCube = self.auxiliaryLinesDataCube cModel.auxiliaryLinesPrefCube = self.auxiliaryLinesPrefCube cModel.auxiliaryLinesPrefFncXCube = self.auxiliaryLinesPrefFncXCube cModel.auxiliaryLinesPrefFncYCube = self.auxiliaryLinesPrefFncYCube cModel.diagonalDC = self.diagonalPC cModel.contourLineDC = self.contourLineDC cModel.pointIDSelected = self.selectedPointIdDC
def test_offset_for_point(self): arc = Arc(Point(1, 0), 90, 1, 270) self.assertAlmostEqual(arc.offset_for_point(Point(0, 1)), math.pi / 2)
def shortest_path(polygon: Polygon, s: Point, t: Point) -> Iterable[Point]: """Find the shortest path from s to t inside polygon.""" # ========================================================================== # Reset properties which can be accessed later on. # ========================================================================== shortest_path.properties = dict(iterations=0, jarvis_marches=0, predicates=0, ignores=0, ignores_theo=0) # ========================================================================== # Type checking. # ========================================================================== assert isinstance(polygon, Polygon) assert isinstance(s, Point) assert isinstance(t, Point) # ========================================================================== # Trivial case: s == t. # ========================================================================== # In the very trivial case the start and end point are identical thus we can # just return without any calculation. if s == t: yield s return # ========================================================================== # Locate s and t. Trivial case: both in same triangle. # ========================================================================== # Locate start and end point inside our polygon. s_triangle = polygon.locate_point_in_triangle(s) t_triangle = polygon.locate_point_in_triangle(t) # If any point is not inside the polygon return if s_triangle is None or t_triangle is None: return # If both points are located inside the same triangle just return both in order if s_triangle == t_triangle: yield s yield t return # ========================================================================== # Preparation. # ========================================================================== # The cusp is the point we are always standing at and from which we can see the triangle boundaries we are visiting. # It gets updated in case we lose visibility. We obviously start at the starting point. cusp = s # The funnel is our visibility angle. funnel = None # We also need to save the trapezoid we are currently in. current_triangle = s_triangle previous_triangle = current_triangle boundary = None # We choose the first neighbour to look at start_neighbour = polygon.delaunay_first_neighbour(current_triangle) # ========================================================================== # Walking the triangles. # ========================================================================== while current_triangle != t_triangle: shortest_path.properties['iterations'] += 1 previous_triangle = current_triangle current_triangle = parallel_find_feasible_subtree(polygon, previous_triangle, start_neighbour, s_triangle, t_triangle) previous_boundary = boundary # Get the boundary between the old and the new current triangle boundary = current_triangle.common_edge(previous_triangle) # Edges need to be oriented in counter-clockwise direction if Point.turn(cusp, boundary.a, boundary.b) == Point.CW_TURN: boundary.reverse() elif Point.turn(cusp, boundary.a, boundary.b) == Point.NO_TURN: # FIXME: We should do something if edge is aligned with cusp # Idea: Look at boundary from third point of previous triangle previous_triangle_points = list(previous_triangle.points) previous_triangle_points.remove(boundary.a) previous_triangle_points.remove(boundary.b) assert len(previous_triangle_points) == 1 previous_triangle_point = previous_triangle_points[0] if Point.turn(previous_triangle_point, boundary.a, boundary.b) == Point.CW_TURN: boundary.reverse() # On encountering the first boundary we do not have a funnel yet. We # then create it and start looking for the next trapezoid if funnel is None: funnel = Funnel(cusp, boundary.a, boundary.b) # ---------------------------------------------------------------------- # Checking (and possibly updating) the visibility. # ---------------------------------------------------------------------- # Check where both boundary end points are in respect to the funnel position_of_a = funnel.position_of(boundary.a) position_of_b = funnel.position_of(boundary.b) # Save whether both end points are on the same side of the funnel both_right_of = position_of_a == position_of_b == Funnel.RIGHT_OF both_left_of = position_of_a == position_of_b == Funnel.LEFT_OF # ---------------------------------------------------------------------- # CASE 1: We do not see the boundary any more. # ---------------------------------------------------------------------- if both_left_of or both_right_of: # The current view point will definitely change now yield cusp # ------------------------------------------------------------------ # Prepare the Jarvis march # ------------------------------------------------------------------ shortest_path.properties['jarvis_marches'] += 1 params = prepare_jarvis_march(polygon, funnel, current_triangle, both_right_of, boundary) # ------------------------------------------------------------------ # Actually perform the Jarvis march # ------------------------------------------------------------------ if both_right_of: ignore_func = ignore_function(previous_boundary or boundary, funnel, Funnel.RIGHT_OF) else: ignore_func = ignore_function(previous_boundary or boundary, funnel, Funnel.LEFT_OF) # Since polygon.point_sees_edge2 returns a tuple of the two funnel # points we directly extract them. Additionally we get the new cusp # and yield all vertices visited until finding cusp. (v1, v2), cusp = yield from jarvis_march( polygon=polygon, predicate=partial(polygon.point_sees_edge2, edge=boundary), ignore=ignore_func, **params ) # ------------------------------------------------------------------ # Update the cusp and the funnel # ------------------------------------------------------------------ # In the special case in which the cusp falls together with an end # point of our edge we advance the funnel point on the next edge # into the right direction. # (We only compare cusp with v1 since polygon.point_sees_edge # guarantees to return the funnel point which falls together first.) if v1 == cusp: triangle_points = current_triangle.points assert v1 in triangle_points assert v2 in triangle_points # Going in clockwise direction if params['direction'] == 1: v1 = polygon.point(cusp.index + 1) else: v1 = polygon.point(cusp.index - 1) # We need to swap v1 and v2 to have them in the right order v1, v2 = v2, v1 funnel.cusp = cusp funnel.first = v1 funnel.second = v2 # ---------------------------------------------------------------------- # CASE 2: We see the boundary but we need to shrink the visibility. # ---------------------------------------------------------------------- else: # If needed (i.e. if the edge reduces the funnel) update the # second and first funnel point if position_of_a == Funnel.INSIDE: funnel.first = boundary.a if position_of_b == Funnel.INSIDE: funnel.second = boundary.b start_neighbour = polygon.delaunay_next_neighbour(current_triangle, previous_triangle) # ========================================================================== # Do the final Jarvis march # ========================================================================== yield cusp if not polygon.point_sees_other_point(cusp, t): shortest_path.properties['jarvis_marches'] += 1 params = prepare_jarvis_march(polygon, funnel, current_triangle, funnel.position_of(t) == Funnel.RIGHT_OF, current_triangle.common_edge(previous_triangle)) # ------------------------------------------------------------------ # Actually perform the Jarvis march # ------------------------------------------------------------------ # Since we are nearly finished we only care about the list of visited # nodes and the new cusp (which is not contained in the list) _, cusp = yield from jarvis_march( polygon=polygon, predicate=partial(polygon.point_sees_other_point, other_point=t), ignore=ignore_function(boundary, funnel, funnel.position_of(t)), **params ) yield cusp yield t
from geometry.polygon import Polygon from geometry.point import Point import sympy.geometry.point import sympy.geometry.polygon import time start_time = time.clock() p1_my = Point(1, 0) p2_my = Point(0, 0) p3_my = Point(0, 1) p4_my = Point(1, 1) p5_my = Point(1, 0) p6_my = Point(10, 0) poly1 = Polygon(p1_my, p2_my, p3_my, p4_my) poly2 = Polygon(p1_my, p2_my, p3_my, p6_my) # print(poly1) # print(poly1.area) # print(poly1.vertices) # print(poly1.bounds) # print(poly1.angles) # print(poly1.perimeter) # print(poly1 == poly2) # print(poly1.encloses_point(p4_my)) # print(poly1.encloses_point((6, 7))) # print(poly1.contains((6, 7))) # print(p4_my in poly1) # print(Polygon._isright(p1_my, p2_my, p3_my))
def test_bounding_box_with_origin_at_0_0(self): ground_plane = GroundPlane(10, Point(0, 0)) expected_box = BoundingBox(Point(-5, -5), Point(5, 5)) self.assertEqual(ground_plane.bounding_box(), expected_box)
def paintDataCubeDiagonal(self): diagonal = [Point(0, 0), Point(4, 4)] diagonalPair = transformToPair(diagonal) self.ax[0].plot(diagonalPair.first, diagonalPair.second, color="b")
#!/usr/bin/env python3 from geometry.point import Point from geometry.vector import Vector p = Point(1,2,0,0) assert str(p) == '(1.0, 2.0)' assert repr(p) == 'Point(1.0, 2.0)' assert p[0] == 1 assert p[1] == 2 assert p[2] == 0 assert p[20] == 0 assert len(p) == 2 assert p + (1,) == Point(2,2) assert p + Point(1,3) == Point(2, 5) assert p - Point(1,3,5) == Vector(0, -1, -5) assert -p == Point(-1, -2) assert p*5 == Point(5, 10) assert p/5 == Point(0.2, 0.4) assert p.translate((1,1,1)) == Point(2,3,1) assert p.scale(3, Point(1,1)) == Point(1,4) assert p.distance(Point(4, 6))==5 assert p.vector() == Vector(1,2) assert p.coordinates == (1,2) for i in range(0, 20): assert p.get_coord(i) == p[i] assert p.ambient_dimension == 2