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

d3-polygon

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-polygon

Operations for two-dimensional polygons.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
decreased by-56.52%
Maintainers
1
Weekly downloads
 
Created

What is d3-polygon?

The d3-polygon npm package is a part of the D3.js library that provides utilities for working with polygons. It includes functions for calculating the area, centroid, and perimeter of polygons, as well as for clipping and hull generation.

What are d3-polygon's main functionalities?

Polygon Area Calculation

This feature allows you to calculate the area of a polygon. The code sample demonstrates how to calculate the area of a rectangle with vertices at (0,0), (4,0), (4,3), and (0,3).

const d3 = require('d3-polygon');
const polygon = [[0, 0], [4, 0], [4, 3], [0, 3]];
const area = d3.polygonArea(polygon);
console.log(area); // Output: 12

Polygon Centroid Calculation

This feature allows you to calculate the centroid (geometric center) of a polygon. The code sample demonstrates how to find the centroid of a rectangle.

const d3 = require('d3-polygon');
const polygon = [[0, 0], [4, 0], [4, 3], [0, 3]];
const centroid = d3.polygonCentroid(polygon);
console.log(centroid); // Output: [2, 1.5]

Polygon Hull Generation

This feature allows you to generate the convex hull of a set of points. The code sample demonstrates how to find the convex hull of a set of points that includes the vertices of a rectangle and an additional point inside the rectangle.

const d3 = require('d3-polygon');
const points = [[0, 0], [4, 0], [4, 3], [0, 3], [2, 1.5]];
const hull = d3.polygonHull(points);
console.log(hull); // Output: [[0, 0], [4, 0], [4, 3], [0, 3]]

Other packages similar to d3-polygon

Keywords

FAQs

Package last updated on 04 Nov 2015

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