Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

offset-polygon

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

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.

  • 0.9.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by16.11%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 21 Oct 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc