polygon
Import from bear/geometry/polygon.
Interfaces
SliceCrossing
Defined in: bear/geometry/polygon.ts:138
One horizontal-ray crossing: where, and through which polygon edge.
Properties
Functions
centerPolygon()
function centerPolygon(points): object;Defined in: bear/geometry/polygon.ts:58
Local footprint and insertion point, using the bounding-box center, not the centroid.
Parameters
| Parameter | Type |
|---|---|
points | Vec2[] |
Returns
object
ensureCCW()
function ensureCCW(pts): Vec2[];Defined in: bear/geometry/polygon.ts:33
Return points in CCW order (reverse if currently CW).
Parameters
| Parameter | Type |
|---|---|
pts | Vec2[] |
Returns
Vec2[]
horizontalSliceCrossings()
function horizontalSliceCrossings(pts, y): SliceCrossing[];Defined in: bear/geometry/polygon.ts:149
Cast a horizontal ray at the given Y through a polygon and return every edge crossing, sorted by X. Consecutive pairs bound the inside spans, and the edge index says which boundary each span ends on.
Parameters
| Parameter | Type |
|---|---|
pts | Vec2[] |
y | number |
Returns
horizontalSliceRanges()
function horizontalSliceRanges(pts, y): [number, number][];Defined in: bear/geometry/polygon.ts:182
Cast a horizontal ray at the given Y through a polygon and return the X-ranges where the ray is inside the polygon.
Returns sorted, non-overlapping [xEnter, xExit] pairs.
Parameters
| Parameter | Type |
|---|---|
pts | Vec2[] |
y | number |
Returns
[number, number][]
insetPolygon()
function insetPolygon(pts, distance): Vec2[];Defined in: bear/geometry/polygon.ts:81
Offset each edge inward by distance and recompute vertices.
For CCW winding, the inward normal of edge direction (dx, dy) is (-dy, dx). Each edge is shifted inward, then consecutive shifted edges are intersected to produce the new vertex positions.
Parameters
| Parameter | Type |
|---|---|
pts | Vec2[] |
distance | number |
Returns
Vec2[]
polygonBoundingBox()
function polygonBoundingBox(pts): object;Defined in: bear/geometry/polygon.ts:38
Axis-aligned bounding box of a polygon.
Parameters
| Parameter | Type |
|---|---|
pts | Vec2[] |
Returns
object
| Name | Type |
|---|---|
maxX | number |
maxY | number |
minX | number |
minY | number |
polygonEdges()
function polygonEdges(pts): [Vec2, Vec2][];Defined in: bear/geometry/polygon.ts:11
Return consecutive edge pairs, wrapping the last vertex back to the first.
Parameters
| Parameter | Type |
|---|---|
pts | Vec2[] |
Returns
polygonSignedArea()
function polygonSignedArea(pts): number;Defined in: bear/geometry/polygon.ts:21
Signed area via the shoelace formula. Positive = CCW, negative = CW.
Parameters
| Parameter | Type |
|---|---|
pts | Vec2[] |
Returns
number