Math.Geometry


Rectangle2D Module

Functions and values

Function or value Description

area rectangle

Full Usage: area rectangle

Parameters:
Returns: Quantity<Squared<'Units>>

Get the area of a rectangle.

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Quantity<Squared<'Units>>

axes rectangle

Full Usage: axes rectangle

Parameters:
Returns: Frame2D<'Units, 'Coordinates, 'Defines>

Get the central axes of a rectangle as a `Frame2D`: rectangle = Rectangle2D.with (Length.meters 2) (Length.meters 5) (Length.meters 1) (Length.meters 3) Rectangle2D.axes rectangle --> Frame2D.atPoint (Point2D.meters 3.5 2) The origin point of the frame will be the center point of the rectangle.

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Frame2D<'Units, 'Coordinates, 'Defines>

boundingBox rectangle

Full Usage: boundingBox rectangle

Parameters:
Returns: BoundingBox2D<'Units, 'Coordinates>

Get the minimal bounding box containing a given rectangle. This will have exactly the same shape and size as the rectangle itself if the rectangle is axis-aligned, but will be larger than the rectangle if the rectangle is at an angle. square = Rectangle2D.with { x1 = Length.meters 0 , x2 = Length.meters 1 , y1 = Length.meters 0 , y2 = Length.meters 1 } diamond = square |> Rectangle2D.rotateAround Point2D.origin (Angle.degrees 45) Rectangle2D.boundingBox diamond --> BoundingBox2D.from --> (Point2D.meters -0.7071 0) --> (Point2D.meters 0.7071 1.4142)

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: BoundingBox2D<'Units, 'Coordinates>

centerPoint rectangle

Full Usage: centerPoint rectangle

Parameters:
Returns: Point2D<'Units, 'Coordinates>

Get the center point of a rectangle.

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Point2D<'Units, 'Coordinates>

centeredOn givenAxes dimensions

Full Usage: centeredOn givenAxes dimensions

Parameters:
    givenAxes : Frame2D<'Units, 'Coordinates, 'Defines>
    dimensions : Size2D<'Units, 'Coordinates>

Returns: Rectangle2D<'Units, 'Coordinates>

Construct a frame centered on the given axes, with the given overall dimensions; Rectangle2D.withDimensions dimensions angle centerPoint could be written as Rectangle2D.centeredOn (Frame2D.withAngle angle centerPoint) dimensions

givenAxes : Frame2D<'Units, 'Coordinates, 'Defines>
dimensions : Size2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

contains point rectangle

Full Usage: contains point rectangle

Parameters:
Returns: bool

Check if a rectangle contains a given point.

point : Point2D<'Units, 'Coordinates>
rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: bool

dimensions rectangle

Full Usage: dimensions rectangle

Parameters:
Returns: Size2D<'Units, 'Coordinates>

Get the overall dimensions (width and height) of a rectangle: rectangle = Rectangle2D.with { x1 = Length.meters 2 , x2 = Length.meters 5 , y1 = Length.meters 1 , y2 = Length.meters 3 } Rectangle2D.dimensions rectangle --> ( Length.meters 3, Length.meters 2 )

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Size2D<'Units, 'Coordinates>

edges rectangle

Full Usage: edges rectangle

Parameters:
Returns: LineSegment2D<'Units, 'Coordinates> list

Get the edges of a rectangle as a list. The edges will be returned in counterclockwise order if the rectangle's axes are right-handed, and clockwise order if the axes are left-handed.

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: LineSegment2D<'Units, 'Coordinates> list

from x1 y1 x2 y2

Full Usage: from x1 y1 x2 y2

Parameters:
Returns: Rectangle2D<'Units, 'Coordinates>

Construct an axis-aligned rectangle given the X and Y coordinates of two diagonally opposite vertices. The X and Y directions of the resulting rectangle are determined by the order of the given values: - If `x1 <= x2`, then the rectangle's X direction will be `Direction2D.positiveX`, otherwise it will be `Direction2D.negativeX` - If `y1 <= y2`, then the rectangle's Y direction will be `Direction2D.positiveY`, otherwise it will be `Direction2D.negativeY` Therefore, something like Rectangle2D.from (Pixels.pixels 0) (Pixels.pixels 300) (Pixels.pixels 500) (Pixels.pixels 0) would have its X direction equal to `Direction2D.positiveX` and its Y direction equal to `Direction2D.negativeY`. -}

x1 : Quantity<'Units>
y1 : Quantity<'Units>
x2 : Quantity<'Units>
y2 : Quantity<'Units>
Returns: Rectangle2D<'Units, 'Coordinates>

fromBoundingBox box

Full Usage: fromBoundingBox box

Parameters:
Returns: Rectangle2D<'Units, 'Coordinates>

Convert a `BoundingBox2D` to the equivalent axis-aligned `Rectangle2D`.

box : BoundingBox2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

fromPoints p1 p2

Full Usage: fromPoints p1 p2

Parameters:
    p1 : Point2D<'Units, 'Coordinates>
    p2 : Point2D<'Units, 'Coordinates>

Returns: Rectangle2D<'Units, 'Coordinates>

Construct an axis-aligned rectangle stretching from one point to another; Rectangle2D.from p1 p2 is equivalent to Rectangle2D.with p1.X p1.Y p2.X p2.Y and so the same logic about the resulting rectangle's X and Y directions applies (see above for details). Therefore, assuming a Y-up coordinate system, something like Rectangle2D.from lowerLeftPoint upperRightPoint would have positive X and Y directions, while Rectangle2D.from upperLeftPoint lowerRightPoint would have a positive X direction but a negative Y direction.

p1 : Point2D<'Units, 'Coordinates>
p2 : Point2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

interpolate rectangle u v

Full Usage: interpolate rectangle u v

Parameters:
    rectangle : Rectangle2D<'Units, 'Coordinates>
    u : float
    v : float

Returns: Point2D<'Units, 'Coordinates>

Interpolate within a rectangle based on coordinates which range from 0 to 1. For example, the four vertices of a given rectangle are [ Rectangle2D.interpolate rectangle 0 0 Rectangle2D.interpolate rectangle 1 0 Rectangle2D.interpolate rectangle 1 1 Rectangle2D.interpolate rectangle 0 1 ] and its center point is Rectangle2D.interpolate rectangle 0.5 0.5

rectangle : Rectangle2D<'Units, 'Coordinates>
u : float
v : float
Returns: Point2D<'Units, 'Coordinates>

mirrorAcross axis rectangle

Full Usage: mirrorAcross axis rectangle

Parameters:
Returns: Rectangle2D<'Units, 'Coordinates>

Mirror a rectangle across a given axis. Note that this will flip the handedness of the rectangle's axes, and therefore the order/direction of results from `Rectangle2D.vertices` and `Rectangle2D.edges` will change.

axis : Axis2D<'Units, 'Coordinates>
rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

placeIn frame rectangle

Full Usage: placeIn frame rectangle

Parameters:
    frame : Frame2D<'Units, 'GlobalCoordinates, 'LocalCoordinates>
    rectangle : Rectangle2D<'Units, 'LocalCoordinates>

Returns: Rectangle2D<'Units, 'GlobalCoordinates>

Take a rectangle considered to be defined in local coordinates relative to a given reference frame, and return that rectangle expressed in global coordinates.

frame : Frame2D<'Units, 'GlobalCoordinates, 'LocalCoordinates>
rectangle : Rectangle2D<'Units, 'LocalCoordinates>
Returns: Rectangle2D<'Units, 'GlobalCoordinates>

relativeTo frame rectangle

Full Usage: relativeTo frame rectangle

Parameters:
    frame : Frame2D<'Units, 'GlobalCoordinates, 'LocalCoordinates>
    rectangle : Rectangle2D<'Units, 'GlobalCoordinates>

Returns: Rectangle2D<'Units, 'LocalCoordinates>

Take a rectangle defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.

frame : Frame2D<'Units, 'GlobalCoordinates, 'LocalCoordinates>
rectangle : Rectangle2D<'Units, 'GlobalCoordinates>
Returns: Rectangle2D<'Units, 'LocalCoordinates>

rotateAround point angle rectangle

Full Usage: rotateAround point angle rectangle

Parameters:
    point : Point2D<'Units, 'Coordinates>
    angle : Angle
    rectangle : Rectangle2D<'Units, 'Coordinates>

Returns: Rectangle2D<'Units, 'Coordinates>

Rotate a rectangle around a given point by a given angle.

point : Point2D<'Units, 'Coordinates>
angle : Angle
rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

scaleAbout point scale rectangle

Full Usage: scaleAbout point scale rectangle

Parameters:
    point : Point2D<'Units, 'Coordinates>
    scale : float
    rectangle : Rectangle2D<'Units, 'Coordinates>

Returns: Rectangle2D<'Units, 'Coordinates>

Scale a rectangle about a given point by a given scale. Note that scaling by a negative value will flip the handedness of the rectangle's axes, and therefore the order/direction of results from `Rectangle2D.vertices` and `Rectangle2D.edges` will change.

point : Point2D<'Units, 'Coordinates>
scale : float
rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

toPolygon rectangle

Full Usage: toPolygon rectangle

Parameters:
Returns: Polygon2D<'Units, 'Coordinates>

Convert a rectangle to a [`Polygon2D`](Polygon2D#Polygon2D).

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Polygon2D<'Units, 'Coordinates>

translateBy displacement rectangle

Full Usage: translateBy displacement rectangle

Parameters:
Returns: Rectangle2D<'Units, 'Coordinates>

Translate a rectangle by a given displacement.

displacement : Vector2D<'Units, 'Coordinates>
rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

translateIn direction distance rectangle

Full Usage: translateIn direction distance rectangle

Parameters:
Returns: Rectangle2D<'Units, 'Coordinates>

Translate a rectangle in a given direction by a given distance.

direction : Direction2D<'Coordinates>
distance : Quantity<'Units>
rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

vertices rectangle

Full Usage: vertices rectangle

Parameters:
Returns: Point2D<'Units, 'Coordinates> list

Get the vertices of a rectangle as a list. The vertices will be returned in counterclockwise order if the rectangle's axes are right-handed, and clockwise order if the axes are left-handed.

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Point2D<'Units, 'Coordinates> list

withDimensions size angle center

Full Usage: withDimensions size angle center

Parameters:
    size : Size2D<'Units, 'Coordinates>
    angle : Angle
    center : Point2D<'Units, 'Coordinates>

Returns: Rectangle2D<'Units, 'Coordinates>
size : Size2D<'Units, 'Coordinates>
angle : Angle
center : Point2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

withXAxis axis dimensions

Full Usage: withXAxis axis dimensions

Parameters:
    axis : Axis2D<'Units, 'Coordinates>
    dimensions : Size2D<'Units, 'Coordinates>

Returns: Rectangle2D<'Units, 'Coordinates>

Construct a rectangle with the given X axis and overall dimensions. The rectangle will be centered on the axis' origin point.

axis : Axis2D<'Units, 'Coordinates>
dimensions : Size2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

withYAxis axis dimensions

Full Usage: withYAxis axis dimensions

Parameters:
    axis : Axis2D<'Units, 'Coordinates>
    dimensions : Size2D<'Units, 'Coordinates>

Returns: Rectangle2D<'Units, 'Coordinates>

Construct a rectangle with the given Y axis and overall dimensions. The rectangle will be centered on the axis' origin point.

axis : Axis2D<'Units, 'Coordinates>
dimensions : Size2D<'Units, 'Coordinates>
Returns: Rectangle2D<'Units, 'Coordinates>

xAxis rectangle

Full Usage: xAxis rectangle

Parameters:
Returns: Axis2D<'Units, 'Coordinates>

Get the X axis of a rectangle.

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Axis2D<'Units, 'Coordinates>

yAxis rectangle

Full Usage: yAxis rectangle

Parameters:
Returns: Axis2D<'Units, 'Coordinates>

Get the Y axis of a rectangle.

rectangle : Rectangle2D<'Units, 'Coordinates>
Returns: Axis2D<'Units, 'Coordinates>