Skip to the content

Chizu地図

Draw SVG maps, frame regions, place numbered callouts and build geography quizzes with English and Japanese names.

Chizu is the Japanese word 地図 for map. About the name

Contents

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

NameTypeDescription
fromMapBox

The starting window in native map units.

toMapBox

The destination window whose nearest wrapped copy is requested.

widthnumber

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)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/chizu 1.5.0.