MCPcopy Index your code
hub / github.com/Stanko/offset-polygon

github.com/Stanko/offset-polygon @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
125 symbols 261 edges 21 files 0 documented · 0% updated 4y ago★ 441 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Offset Polygon

Small, no dependency library for offsetting polygons. Heavily based on this CodePen by Hans Muller.

Interactive demo

Example polygons

Params

function offsetPolygon(vertices: Vector[], offset: number, arcSegments?: number): Vector[]
  • vertices - array of vector objects { x: number, y: number }
  • offset - number, how much should the polygon be offset. Positive values will create add margin, and negative padding.
  • arcSegments - number, default 0. When set, corners of the generated polygon will be rounded by an arc formed of straight line segments.

Returns newly generated polygon vertices as an array of vector objects { x: number, y: number }.

Usage

Get it from npm:

npm install offset-polygon
import offsetPolygon from "offset-polygon";

const polygon = [
  { "x": 413, "y": 123 },
  { "x": 510, "y": 299 },
  { "x": 395, "y": 487 },
  { "x": 292, "y": 341 },
  { "x": 92,  "y": 327 },
  { "x": 146, "y": 158 },
];

// Padding
const smallerPolygon = offsetPolygon(polygon, -10, 5);

// Margin
const largerPolygon = offsetPolygon(polygon, 10, 5);

Core symbols most depended-on inside this repo

attr
called by 44
docs/snowpack/pkg/common/index-fbcaf5b0.js
insert
called by 15
docs/snowpack/pkg/common/index-fbcaf5b0.js
detach
called by 15
docs/snowpack/pkg/common/index-fbcaf5b0.js
append
called by 14
docs/snowpack/pkg/common/index-fbcaf5b0.js
transition_in
called by 12
docs/snowpack/pkg/common/index-fbcaf5b0.js
transition_out
called by 9
docs/snowpack/pkg/common/index-fbcaf5b0.js
element
called by 8
docs/snowpack/pkg/common/index-fbcaf5b0.js
space
called by 8
docs/snowpack/pkg/common/index-fbcaf5b0.js

Shape

Function 111
Class 8
Method 6

Languages

TypeScript100%

Modules by API surface

docs/snowpack/pkg/common/index-fbcaf5b0.js41 symbols
docs/demo/Demo.svelte.js31 symbols
docs/demo/Draggable.svelte.js13 symbols
src/offset-polygon.ts9 symbols
lib/offset-polygon.js9 symbols
docs/src/offset-polygon.js9 symbols
docs/demo/Control.svelte.js9 symbols
docs/demo/is-mobile-device.js1 symbols
docs/demo/generate-polygon.js1 symbols
demo/is-mobile-device.js1 symbols
demo/generate-polygon.js1 symbols

For agents

$ claude mcp add offset-polygon \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact