ixfx
    Preparing search index...

    Namespace Rects

    Functions

    applyDim

    Applies op with param to rect's width and height.

    applyFields

    Applies an operation over each field of a rectangle.

    applyMerge

    Applies an joint operation field-wise on two rectangles, returning a single rectangle. This is used to support operations like summing two rectangles.

    applyScalar

    Uses op with param to width and height.

    area

    Returns the area of rect

    cardinal

    Returns a point on cardinal direction, or 'center' for the middle.

    center

    Returns the center of a rectangle as a Point. If the rectangle lacks a position and origin parameter is not provided, 0,0 is used instead.

    corners

    Returns the four corners of a rectangle as an array of Points.

    distanceFromCenter

    Return the distance of pt to the center of rect.

    distanceFromExterior

    Returns the distance from the perimeter of rect to pt. If the point is within the rectangle, 0 is returned.

    divide

    Divides positioned rect by width/height. Useful for normalising a value. x & y value of second parameter are ignored

    divideDim
    dividerByLargestDimension

    Returns a function that divides numbers or points by the largest dimension of rect.

    divideScalar

    Divides all components of rect by amount. This includes x,y if present.

    edges

    Returns four lines based on each corner. Lines are given in order: top, right, bottom, left

    encompass

    Returns a copy of rect with rect resized so it also encompasses points. If provided point(s) are within bounds of rect, a copy of rect is returned.

    fromCenter

    Initialises a rectangle based on its center, a width and height

    fromElement

    Initialise a rectangle based on the width and height of a HTML element.

    fromNumbers

    Returns a rectangle from a series of numbers: x, y, width, height OR width, height

    fromTopLeft

    Creates a rectangle from its top-left coordinate, a width and height.

    getEdgeX

    Returns a point on the edge of rectangle

    const r1 = {x: 10, y: 10, width: 100, height: 50};
    Rects.getEdgeX(r1, `right`); // Yields: 110
    Rects.getEdgeX(r1, `bottom`);
    getEdgeY

    Returns a point on the edge of rectangle

    getRectPositioned

    Returns a positioned rect or if it's not possible, throws an error.

    getRectPositionedParameter

    Accepts:

    • x,y,w,h
    • x,y,rect
    • point,rect
    • RectPositioned
    • Rect, x,y
    • Rect, Point
    guard

    Throws an error if rectangle is missing fields or they are not valid.

    guardDim

    Throws an error if the dimensions of the rectangle are undefined, NaN or negative.

    guardPositioned

    Throws an error if rect is does not have a position, or is an invalid rectangle

    intersectsPoint

    Returns true if point is within or on boundary of rect.

    isEmpty

    Returns true if rect has width and height values of 0. Use Rects.Empty or Rects.EmptyPositioned to generate an empty rectangle.

    isEqual

    Returns true if two rectangles have identical values. Both rectangles must be positioned or not.

    isEqualSize

    Returns true if the width & height of the two rectangles is the same.

    isIntersecting

    Returns true if a or b overlap, are equal, or a contains b. A rectangle can be checked for intersections with another RectPositioned, CirclePositioned or Point.

    isPlaceholder

    Returns true if rect is a placeholder, with both width and height values of NaN. Use Rects.Placeholder or Rects.PlaceholderPositioned to generate a placeholder.

    isPositioned

    Returns true if rect has position (x,y) fields.

    isRect

    Returns true if rect has width and height fields.

    isRectPositioned

    Returns true if rect is a positioned rectangle Having width, height, x and y properties.

    lengths

    Returns the length of each side of the rectangle (top, right, bottom, left)

    maxFromCorners

    Returns a rectangle based on provided four corners.

    multiply

    Multiplies positioned rect by width/height. Useful for denormalising a value. x/y value of second parameter are ignored.

    // Normalised rectangle
    const r = { x:0.5, y:0.5, width: 0.5, height: 0.5
    multiplyDim

    Multiplies only the width/height of rect, leaving x and y as they are.

    multiplyScalar

    Multiplies all components of rect by amount. This includes x,y if present.

    nearestInternal

    If p is inside of rect, a copy of p is returned. If p is outside of rect, a point is returned closest to p on the edge of the rectangle.

    perimeter

    Returns the perimeter of rect (ie. sum of all edges) *

    random

    Returns a random positioned Rect on a 0..1 scale.

    randomPoint

    Returns a random point within a rectangle.

    subtract

    Subtracts width/height from a.

    subtractOffset

    Subtracts A-B. Applies to x, y, width & height

    subtractSize

    Subtracts a width & height from a. Leaves x & y as-is.

    sum

    Sums width/height of b with a (ie: a + b), returning result.

    sumOffset

    Sums x,y,width,height of a+b.

    toArray

    Converts a rectangle to an array of numbers. See fromNumbers for the opposite conversion.

    Type Aliases

    ApplyFieldOp
    ApplyMergeOp

    An operation between two fields of a rectangle. Used in the context of applyMerge

    Rect
    Rect3d
    Rect3dPositioned
    RectArray

    Rectangle as array: [width, height]

    RectPositioned
    RectPositionedArray

    Positioned rectangle as array: [x, y, width, height]

    RectRandomPointOpts

    Variables

    Empty
    EmptyPositioned
    Placeholder
    PlaceholderPositioned