geometry.Rectangle()¶
-
class
feign.geometry.Rectangle(p1, p2, p3, p4)¶ A class used to represent a Rectangle.
Rectangles are actually general convex quadritlaterals. To create a Rectangle, one should give the four corners in a clockwise or counter-clockwise order
- Parameters
-
corners¶ list of the corner points
- Type
list of Point()
-
sides¶ list of the sides
- Type
list of Segment()
- Raises
ValueError – if Corners are not defined in clockwise or counter-clockwise order.
-
encloses_point(P)¶ The function to assess whether a point is enclosed by a Rectangle().
- Parameters
P (Point()) – point to decide whether is enclosed by Rectangle
- Returns
True if the point is enclosed by the Rectangle, False otherwise.
- Return type
bool
Examples
>>> rect=Rectangle(Point(3,7),Point(5,3),Point(13,5),Point(12,6)) >>> P=Point(6,5) >>> rect.encloses_point(P) True >>> Q=Point(4,3) >>> rect.encloses_point(Q) False
-
intersection(seg)¶ The function to find the intersection of a Rectangle with a Segment.
- Parameters
seg (Segment()) – The Segment for which the intersection is calculated
- Returns
list of the intersections
- Return type
list of Point()
Notes
The list has one element if one of the endpoints of the Segment is enclosed by the rectangle.
The list has two elements if both endpoints of the Segment lies outside the Rectangle, and the Segment passes through the Rectangle.
An empty list is returned if the Segment does not pass through the Rectangle, or in case the Segment passes through only one of the corners.
Examples
>>> rect=Rectangle(Point(-10,10),Point(10,10),Point(10,-10),Point(-10,-10)) >>> s=Segment(Point(-30,-30),Point(30,30)) >>> rect.intersection(s) [Point(10.000, 10.000), Point(-10.000, -10.000)]