getCoordinates method
Get list of coordinates starting at angle startAngle
inside a rectangle defined by size
.
For regular n-sided star, make sure size
defines a square with equal dimensions.
Note: Depending on resolution, a rectangle may be defined to create the visual appearance of a regular polygon.
Angle startAngle
is defined as start from east direction, and moving counter-clockwise (towards north, west, then south)
Implementation
List<GeoCoordinate2D> getCoordinates(
{required GeoAngle startAngle,
bool clockwise = false,
required Size size,
double indentSideFactor = 0.5,
BoxFit boxFit = BoxFit.none}) {
GeoEllipse outerEllipse = GeoEllipse(size.width / 2, size.height / 2);
indentSideFactor = indentSideFactor.clamp(0, 1);
GeoEllipse innerEllipse = GeoEllipse(
outerEllipse.xRadius * indentSideFactor,
outerEllipse.yRadius * indentSideFactor);
List<GeoCoordinate2D> coords = <GeoCoordinate2D>[];
double currentAngle = clockwise ? startAngle.radian : -startAngle.radian;
double currentInnerAngle = 0;
bool hasBoxFit = (boxFit != BoxFit.none);
for (int i = 0; i < sides; i++) {
coords.add(outerEllipse.coordinateByRadian(currentAngle));
currentInnerAngle = currentAngle +
(clockwise ? -halfInteriorAngle.radian : halfInteriorAngle.radian);
coords.add(innerEllipse.coordinateByRadian(currentInnerAngle));
currentAngle += clockwise ? -interiorAngle.radian : interiorAngle.radian;
}
if (hasBoxFit) {
GeoUtility.scaleToFit(size, boxFit, coords, true, true);
}
GeoUtility.recenter(
GeoCoordinate2D(size.width / 2, size.height / 2), coords, true);
return coords;
}