gradum-kit - v0.1.0
    Preparing search index...

    Class GradumRect

    GradumRect

    A rectangle that can be rotated, unlike the axis-aligned DOMRect it extends. Its geometry helpers (GradumRect.closestPoint, GradumRect.distanceTo, GradumRect.overlaps) all account for the rotation, and accept a point, a segment, or another rect.

    Hierarchy

    Index
    • Parameters

      • Optionalproperties: GradumRectProperties = {}

        The rectangle's position, size, rotation, and anchor.

      Returns GradumRect

      Create a rectangle. Give either angleRad or angleDeg to rotate it; omitting both leaves it axis-aligned.

    angleRad: number = 0

    The rectangle's rotation in radians, about its centre.

    anchor: AnchorPoint

    The anchor the rectangle is positioned from.

    • get angleDeg(): number

      Returns number

      The rectangle's rotation in degrees. Reads and writes the same rotation as GradumRect.angleRad, converted.

    • set angleDeg(value: number): void

      Parameters

      • value: number

      Returns void

    • get center(): Point

      Returns Point

      The rectangle's centre point.

    • get xAxis(): Point

      Returns Point

      The unit vector along the rectangle's own x axis, pointing along its width once rotated.

    • get yAxis(): Point

      Returns Point

      The unit vector along the rectangle's own y axis, pointing along its height once rotated.

    • get half(): Point

      Returns Point

      Half the rectangle's width and height, as a point.

    • get points(): [Point, Point, Point, Point]

      Returns [Point, Point, Point, Point]

      The rectangle's four corners in screen coordinates, clockwise from the top-left, with the rotation applied.

    • Function

      fromSegment

      Parameters

      • a: Point

        The segment's start.

      • b: Point

        The segment's end.

      • Optionalthickness: number = 1

        The rectangle's height, across the segment.

      • Optionalproperties: GradumRectProperties = {}

        Extra properties. The computed rotation wins over any angle given here.

      Returns GradumRect

      The rectangle covering the segment.

      Build a rectangle covering the segment between two points: centred on the segment, as long as it, and rotated to match its direction.

    • Function

      fromDOMRect

      Parameters

      • rect: DOMRect

        The rect to copy position and size from.

      • Optionalproperties: GradumRectProperties = {}

        Extra properties, such as a rotation to apply.

      Returns GradumRect

      The converted rectangle.

      Build a rectangle from a plain DOMRect, such as one returned by getBoundingClientRect().

    • Function

      render

      Returns HTMLElement

      The generated element. It is not attached to the document.

      Create a translucent red div matching this rectangle's position, size, and rotation. Meant for debugging geometry — append the result to the document to see where the rect actually is.

    • Function

      closestPoint

      Parameters

      • point: Point

        The point to measure to.

      Returns Point

      The nearest point on this rectangle.

      Find the point on this rectangle nearest to the given point. Points inside the rectangle return themselves.

    • Function

      closestPoint

      Parameters

      • point1: Point

        The segment's start.

      • point2: Point

        The segment's end.

      Returns Point

      The nearest point on this rectangle.

      Find the point on this rectangle nearest to the segment between two points. Returns the intersection if the segment crosses the rectangle.

    • Function

      closestPoint

      Parameters

      • rect: DOMRect

        The rectangle to measure to.

      Returns Point

      The nearest point on this rectangle.

      Find the point on this rectangle nearest to another rectangle. Accepts a plain DOMRect or a rotated GradumRect.

    • Function

      distanceTo

      Parameters

      • point: Point

        The point to measure to.

      Returns number

      The distance, or 0 if the point is inside this rectangle.

      Measure the shortest distance from this rectangle to a point.

    • Function

      distanceTo

      Parameters

      • point1: Point

        The segment's start.

      • point2: Point

        The segment's end.

      Returns number

      The distance, or 0 if the segment crosses this rectangle.

      Measure the shortest distance from this rectangle to the segment between two points.

    • Function

      distanceTo

      Parameters

      • rect: DOMRect

        The rectangle to measure to.

      Returns number

      The distance, or 0 if the two overlap.

      Measure the shortest distance from this rectangle to another rectangle.

    • Function

      overlaps

      Parameters

      • other: DOMRect

        The rectangle to test against.

      Returns boolean

      Whether the two overlap.

      Test whether this rectangle overlaps another. Accepts a plain DOMRect or a rotated GradumRect.

    • Function

      overlaps

      Parameters

      • point: Point

        The point to test.

      Returns boolean

      Whether the point is contained.

      Test whether a point lies on or inside this rectangle.

    • Function

      overlaps

      Parameters

      • a: Point

        The segment's start.

      • b: Point

        The segment's end.

      Returns boolean

      Whether the segment intersects this rectangle.

      Test whether the segment between two points crosses this rectangle.