Polygon class
A polygon defined by an ordered list of vertices.
Implements Shape with area (shoelace formula) and perimeter. Supports containment checks (ray-casting), convexity detection, intersection with lines and circles, and centroid computation.
final hex = Polygon.regular(sides: 6, radius: 10, center: Point(0, 0));
print(hex.isConvex); // true
print(hex.contains(Point(0, 0))); // true
- Implemented types
Constructors
Properties
- area → double
-
Area of this polygon using the shoelace formula.
no setteroverride
- bottomPoint → Point
-
Get the furthest bottom point of the polygon
no setter
- centroid → Point
-
Centroid of this polygon (alias for getInnerCentroid)
no setter
-
edges
→ List<
Line> -
Get all edges of this polygon
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClockwise → bool
-
Whether vertices are in clockwise winding order
no setter
- isConvex → bool
-
Whether this polygon is convex
no setter
- mostLeftPoint → Point
-
Get the furthest left point of the polygon
no setter
- mostRightPoint → Point
-
Get the furthest right point of the polygon
no setter
- perimeter → double
-
Perimeter of this polygon (sum of all edge lengths).
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- topPoint → Point
-
Get the furthest top point of the polygon
no setter
-
vertices
→ List<
Point> -
Ordered list of vertices.
final
Methods
-
contains(
Point point) → bool - Check if a point is inside this polygon
-
getBound(
) → Polygon - Get all the boundary of the polygon
-
getCircumCentroid(
) → Point - Get the centroid of Outer circle
-
getCircumCircle(
List< Point> list) → Circle - Get the outer circle
-
getClosestVertex(
Point point) → Point - Get closest vertex to the point
-
getClosetVertex(
Point point) → Point - Get closet vertex to the point
-
getFurthestVertex(
Point point) → Point - Get furthest vertex to the point
-
getInnerCentroid(
) → Point - Get the centroid of inner circle
-
getInnerCircle(
) → Circle - Get the outer circle
-
intersectsCircle(
Circle circle) → bool - Check if a circle intersects this polygon
-
intersectsLine(
Line line) → bool - Check if a line segment intersects this polygon
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
rotate(
double deg) → Polygon -
Rotate all vertices by
degdegrees around the origin.override -
scale(
double value) → Polygon -
Scale all vertices by
value.override -
toString(
) → String -
A string representation of this object.
inherited
-
translate(
{double x = 0, double y = 0}) → Polygon -
Translate all vertices by
xhorizontally andyvertically.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited