Skip to the content

Karakuriからくり

Play eight native puzzles, run bounded searches, step deterministic physics and mount a canvas player controlled by pointer or keyboard.

Karakuri is the Japanese word からくり for a mechanism or ingenious device. About the name

Contents

Reference · Deterministic 2D physics

pointInPolygonfunction

Whether (px, py) is inside the polygon (an even-odd test over its vertices, in order).

Import it

import { pointInPolygon } from "@johnmorrisdotca/karakuri/physics";

Definition

function pointInPolygon(px: number, py: number, polygon: readonly Vec[]): boolean

Parameters

NameTypeDescription
pxnumber

The horizontal coordinate of the point to test.

pynumber

The vertical coordinate of the point to test.

polygonreadonly Vec[]

The polygon’s native vertices, in outline order.

Returns

boolean

Whether (px, py) is inside the polygon (an even-odd test over its vertices, in order).

Examples

import { pointInPolygon } from "@johnmorrisdotca/karakuri/physics";

console.log(pointInPolygon(2,2,[{x:0,y:0},{x:5,y:0},{x:5,y:5},{x:0,y:5}]));
true

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/karakuri 0.2.1.