Socket
Socket
Sign inDemoInstall

offset-polygon

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    offset-polygon

Small, no dependency library for offsetting polygons. Heavily based on this [CodePen](https://codepen.io/HansMuller/pen/lDfzt) by Hans Muller.


Version published
Weekly downloads
521
increased by0.97%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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);

Keywords

FAQs

Last updated on 21 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc