Creates a rectangle aligned to a plane. One corner of the rectangle will sit on the plane's origin, with the rest of the rectangle growing along the plane's axes from that point.
The plane the rectangle is aligned to. The plane's origin will be one corner of the rectangle with the rest of the rectangle growing from that point.
The width of the rectangle along the plane's x-axis.
The width of the rectangle along the plane's y-axis.
Creates a new rectangle on a plane.
The plane the rectangle is aligned to. The plane's origin will be one corner of the rectangle with the rest of the rectangle growing from that point.
The width of the rectangle along the plane's x-axis.
The width of the rectangle along the plane's y-axis.
Gets the area of the rectangle.
Gets the smallest bounding box that contains the rectangle.
Gets the center of the rectangle.
Gets the total length of the rectangle's edges.
Gets the width of the rectangle along its x-axis.
Gets the width of the rectangle along its y-axis.
Gets the position of the rectangle relative to the plane's x-axis.
Gets the position of the rectangle relative to the plane's y-axis.
Creates a rectangle centered and aligned to a plane.
The plane the rectangle is aligned to. The plane's origin will be the center of the rectangle.
Width of the rectangle along the x-axis of the plane (rectangle will be centered on the plane's origin).
Width of the rectangle along the y-axis of the plane (rectangle will be centered on the plane's origin).
Creates a rectangle from two corner points.
One corner of the rectangle.
The opposite corner of the rectangle.
The plane the rectangle is orientated to. If unset, the rectangle will be aligned to the global x- and y-axis.
Finds the closest point on the rectangle and returns the point.
The target to get closest to.
If false, the closest point must lie on the outer edge of the rectangle. If true, the closest point can also be a point on the interior of the rectangle.
Checks whether a point is inside, outside, or on the edge of a rectangle.
The point to test for containment.
The distance the point can be from the edge of the rectangle and still considered coincident.
Gets a corner of the rectangle.
If true, point will be at the min x value relative to the rectangle's plane. If false, it will be at max.
If true, point will be at the min y value. If false, it will be at max.
Checks whether another rectangle has the same dimensions and location. Returns true if it does.
Rectangle to compare against.
The amount the dimensions can differ and still be considered equal.
Gets the four corners of the rectangle. The order is: [[minX, minY], [minX, maxY], [maxX, maxY], [maxX, minY]].
Gets the four edges of the rectangle. Follows the order in getCorners.
Remaps a point from the u-v space of the rectangle to the global coordinate system.
The normalized distance along the x-axis of the rectangle.
The normalized distance along the y-axis of the rectangle.
The uvPoint remapped to the global coordinate system.
Remaps a point from the u-v space of the rectangle to the global coordinate system.
A point in the u-v coordinates of the rectangle. The point's x value is the normalized distance along the x-axis of the rectangle (u-direction). The point's y value is the normalized distance along the y-axis of the rectangle (v-direction).
The uvPoint remapped to the global coordinate system.
Gets the rectangle as a closed polyline.
Gets the rectangle as a string in the format: [plane,widthX,widthY]
.
Creates a copy of the rectangle with a different x interval.
The new position of the rectangle along the x-axis of the plane.
Creates a copy of the rectangle with a different y interval.
The new position of the rectangle along the y-axis of the plane.
Translates the geometry from one coordinate system to another while keeping
the geometry in the same position. In other words, if the geometry is currently
described relative to planeFrom
, after changeBasis,
it will be in the same position but described relative to planeTo
.
The coordinate system the geometry is currently described relative to.
The coordinate system to describe the geometry relative to.
The geometry in the new coordinate system.
Rotates the geometry about (0,0).
Angle to rotate the geometry (in radians). The direction is counter-clockwise.
Rotates the geometry about a point.
Angle to rotate the geometry (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.
Point to pivot the geometry about.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x- and y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Scales the geometry about a point and returns the resized geometry.
Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.
Center of scaling. Everything will shrink or expand away from this point.
Transforms the rectangle by a transform matrix and returns the result.
import { Plane, Rectangle, Transform } from 'shapetypes';
// Create a new rectangle
const rect = new Rectangle(Plane.worldXY(), 10, 20);
console.log(rect.area);
// => 200
// Scale rectangle using a transform matrix
const matrix = Transform.scale(2);
const scaled = rect.transform(matrix);
console.log(scaled.area);
// => 800
// Scale rectangle using the direct method
const otherScaled = rect.scale(2);
console.log(otherScaled.area);
// => 800
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction and distance to move the geometry.
Moves the geometry along a vector and returns the moved geometry. The translation is always linear.
The direction to move the geometry.
The distance to move the geometry.
Generated using TypeDoc
A rectangular shape aligned to a plane.
Example
import { Plane, Point, Rectangle, Vector } from 'shapetypes'; // Create a new rectangle const rect = new Rectangle(Plane.worldXY(), 10, 20); // Get properties of the rectangle console.log(rect.area); // => 200 console.log(rect.circumference); // => 60 console.log(rect.center.toString()); // => (5,10) // Create a new rectangle aligned to a plane const plane = new Plane(new Point(3,4), new Vector(1,1)); const angledRect = new Rectangle(plane, 10, 20); // Get corners of angled rectangle console.log(angledRect.getCorners()); // => [(3,4),(-11.14213562373095,8.14213562373095),(-4.071067811865474,25.213203435596427),(10.071067811865476,11.071067811865476)]