Skip to content

editor / fitInBox

Function: fitInBox() ​

fitInBox(points, size, anchor): readonly Point[]

Defined in: geometry/fit-in-box.ts:27

Scales a set of points uniformly to the largest size fitting a width × height box, and places it in the room left by its anchor (DERIV-regular-polygon-fit steps 3–5).

The scale is s = min(width / spanX, height / spanY): the shape keeps its proportions and reaches the width, the height or both, within a rounding error relative to the box: about 1e-16 × its size (written 0 by the output for boxes up to millions of units). The room left on each axis goes before the shape for 0 (min), half (mid) or all of it (max), as SVG's preserveAspectRatio with meet. The points must span both axes (spanX > 0, spanY > 0); a box of size 0 gives s = 0: every point goes to the anchored place. The y axis is not flipped: the points are already in the SVG frame.

Parameters ​

points ​

readonly Point[]

points spanning both axes, in drawing order

size ​

Size

width and height of the box, >= 0

anchor ​

Anchor

horizontal and vertical alignment in the box

Returns ​

readonly Point[]

the points scaled and placed, in the same order

Kind ​

geometry

See ​

DERIV-regular-polygon-fit