npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-polygon

v1.1.3

Published

A JavaScript/TypeScript library for handling Polygon geometry according to OGC standards with advanced geometric operations

Readme

node-polygon

A JavaScript/TypeScript library for handling Polygon geometry according to OGC (Open Geospatial Consortium) standards with advanced geometric operations.

Features

  • Create and manipulate Polygon geometries
  • Support for WKT (Well-Known Text) format
  • Geometric transformations including translation, scaling, and rotation
  • Matrix-based transformations
  • Polygon simplification using Douglas-Peucker algorithm
  • Polygon smoothing using Catmull-Rom spline interpolation
  • TypeScript support with full type definitions

Installation

npm install node-polygon

Usage

Basic Usage

import { Polygon, create, clone } from 'node-polygon';

// Create a new Polygon
const polygon = create();
polygon.coordinates = [[
  [-100, 40],
  [-105, 45],
  [-110, 55],
  [-100, 40]
]];

// Clone a polygon
const clonedPolygon = clone(polygon);

Working with WKT

import { Polygon, fromWKT } from 'node-polygon';

// Create polygon from WKT format
const polygon = new Polygon();
fromWKT(polygon, "POLYGON((116.36 39.90, 116.46 39.90, 116.56 39.90, 116.36 39.90))");
console.log(polygon.coordinates);

Geometric Transformations

import { Polygon, translate, scale, rotate, transformMat3 } from 'node-polygon';

const polygon = new Polygon();
polygon.coordinates = [[
  [10, 10],
  [20, 10],
  [20, 20],
  [10, 20],
  [10, 10]
]];

// Translation
translate(polygon, polygon, [5, 5]);

// Scaling
scale(polygon, polygon, [2, 2], [0, 0]);

// Rotation
rotate(polygon, polygon, Math.PI / 2, [0, 0]);

// Matrix transformation
const matrix = new Float32Array([1, 0, 0, 0, 1, 0, 10, 20, 1]);
transformMat3(polygon, polygon, matrix);

Polygon Simplification

import { Polygon, simplify } from 'node-polygon';

const complexPolygon = new Polygon();
// ... set complex coordinates ...

// Simplify polygon with tolerance value
const simplifiedPolygon = new Polygon();
simplify(simplifiedPolygon, complexPolygon, 0.01);

Polygon Smoothing

import { Polygon, smooth } from 'node-polygon';

const polygon = new Polygon();
// ... set coordinates ...

// Smooth polygon with default parameters
const smoothedPolygon = new Polygon();
smooth(smoothedPolygon, polygon);

// Smooth with custom tension and segment count
smooth(smoothedPolygon, polygon, 0.3, 15);

API Reference

Polygon Class

The main Polygon class representing a polygon geometry with the following properties:

  • type: String - Always 'Polygon'
  • coordinates: Array - Array of linear rings, each ring is an array of [x, y] coordinates

Functions

create(): Polygon

Creates a new empty Polygon object.

clone(a: Polygon): Polygon

Clones a Polygon object.

fromWKT(out: Polygon, wkt: string): void

Parses a Polygon from WKT format string (e.g., "POLYGON((116.36 39.90, 116.46 39.90, 116.56 39.90, 116.36 39.90))").

transformMat3(out: Polygon, a: Polygon, mat3: Float32Array): Polygon

Transforms a Polygon using a 3x3 matrix transformation.

translate(out: Polygon, a: Polygon, dxdy: number[]): Polygon

Translates a Polygon by dx and dy distances provided as an array.

scale(out: Polygon, a: Polygon, scalexy: number[], origin: number[] = [0, 0]): Polygon

Scales a Polygon by scale factors around an origin point.

rotate(out: Polygon, a: Polygon, rad: number, origin: number[] = [0, 0]): Polygon

Rotates a Polygon by radians around an origin point.

simplify(out: Polygon, a: Polygon, tolerance: number): Polygon

Simplifies a Polygon using the Douglas-Peucker algorithm with the given tolerance.

smooth(out: Polygon, a: Polygon, tension: number = 0.5, numOfSegments: number = 10): Polygon

Smooths a Polygon using Catmull-Rom spline interpolation with configurable tension and segment count.

Data Format

Polygon Structure

{
  "type": "Polygon",
  "coordinates": [
    [
      [-100, 40],
      [-105, 45],
      [-110, 55],
      [-100, 40]
    ]
  ]
}

WKT Format Support

Supports parsing POLYGON type WKT format:

POLYGON((116.36 39.90, 116.46 39.90, 116.56 39.90, 116.36 39.90))

License

MIT