Reference · Framing, geometry and quiz tools
placeHandlesfunction
Places every handle clear of the ones before it.
Greedy and order-dependent by design: the caller has already sorted the marks into the order they are numbered, and a handle that has found a home does not move to make room for a later one. With a handful of choices on a board that is enough, and it keeps the placement stable as tones change mid-question.
Import it
import { placeHandles } from "@johnmorrisdotca/chizu";
Definition
function placeHandles<T>(entries: ReadonlyArray<{ item: T; centroid: readonly [number, number]; }>, radius: number, bounds?: HandleBounds): Array<HandleSpot & { item: T; }>
Parameters
| Name | Type | Description |
|---|---|---|
entries | readonly { item: T; centroid: readonly [number, number]; }[] | Native places to order or lay out. |
radius | number | The circle or label radius in native map units. |
bounds (optional) | HandleBounds | undefined | The allowed label placement bounds in native map units. |
Returns
(HandleSpot & { item: T; })[]
Places every handle clear of the ones before it.
Examples
import { placeHandles } from "@johnmorrisdotca/chizu";
const spots = placeHandles([{ item: "a", centroid: [50, 50] }, { item: "b", centroid: [52, 50] }], 4);
console.log(spots.map((spot) => spot.item).join(" "), Math.hypot(spots[0]!.hx - spots[1]!.hx, spots[0]!.hy - spots[1]!.hy) >= 8);
// a b truea b trueWhat it prints (run when this page was built)