ReadonlyareaReadonlyhHeight
ReadonlysizeReadonlytopDerived state: topLeft assumes up is -y
ReadonlywWidth
ReadonlyxTop left x coordinate
ReadonlyyTop left y coordinate
StaticemptyStaticunitReturns true if and only if the given point is contained within this shape.
epsilon is a small number used to counteract floating point error. Thus, if
point is within epsilon of the inside of this shape, containsPoint may also
return true.
The default implementation relies on signedDistance.
Subclasses may override this method to provide a more efficient implementation.
Returns a the subdivision of this into [columns] columns and [rows] rows. For example, Rect2.unitSquare.divideIntoGrid(2, 2) -> [ Rect2(0, 0, 0.5, 0.5), Rect2(0.5, 0, 0.5, 0.5), Rect2(0, 0.5, 0.5, 0.5), Rect2(0.5, 0.5, 0.5, 0.5) ] The rectangles are ordered in row-major order.
Returns edges in the order [ rightEdge, topEdge, leftEdge, bottomEdge ]
Returns a bounding box that loosely fits the content of this shape.
The result of this call can be larger than the result of getTightBoundingBox,
but should not be smaller. Thus, a call to getLooseBoundingBox can be significantly
faster than a call to getTightBoundingBox for some shapes.
points at which this shape intersects the given lineSegment.
If this is a closed shape, returns points where the given lineSegment intersects
the boundary of this.
Computes the signed distance function for this shape.
StaticbboxStaticfromStaticofStaticunion
Represents a rectangle in 2D space, parallel to the XY axes.
Example:
import { Rect2, Vec2 } from '@js-draw/math'; const rect = Rect2.fromCorners( Vec2.of(0, 0), Vec2.of(10, 10), ); console.log('area', rect.area); console.log('topLeft', rect.topLeft);invariant: w ≥ 0, h ≥ 0, immutable