Reference · Framing, geometry and quiz tools
nearestWrappedBoxfunction
The copy of a window nearest another one. Travelling from Japan to Hawaii is a short hop east across the date line, and their stored coordinates are at opposite ends of the canvas, so easing between the two as they are stored sweeps the whole earth the wrong way. Sliding the destination onto the nearest copy makes the journey the short one.
Import it
import { nearestWrappedBox } from "@johnmorrisdotca/chizu";
Definition
function nearestWrappedBox(from: MapBox, to: MapBox, width: number): MapBox
Parameters
| Name | Type | Description |
|---|---|---|
from | MapBox | The starting window in native map units. |
to | MapBox | The destination window whose nearest wrapped copy is requested. |
width | number | The native canvas width or frame width specified by this signature. |
Returns
MapBox
The copy of a window nearest another one. Travelling from Japan to Hawaii is a short hop east across the date line, and their stored coordinates are at opposite ends of the canvas, so easing between the two as they are stored sweeps the whole earth the wrong way. Sliding the destination onto the nearest copy makes the journey the short one.
Examples
import { nearestWrappedBox } from "@johnmorrisdotca/chizu";
console.log(nearestWrappedBox({ x: -50, y: 0, width: 100, height: 100 }, { x: 900, y: 0, width: 100, height: 100 }, 1000));
// { x: -100, y: 0, width: 100, height: 100 }{ x: -100, y: 0, width: 100, height: 100 }What it prints (run when this page was built)