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

hachure-fill

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hachure-fill

Fill a polygon with lines

  • 0.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

hachure-fill

Demo

This package calculates the hachure lined to fill a polygon. The angle of the lines and the gap between lines can be configured.

The algorithm works on convex, concave, simple, complex polygons, and polygons with holes.

preview of a polygon

Install

From npm

npm install --save hachure-fill

The package is distributed as an ES6 module.

Usage

hachureFill(points: Point[], angle: number, gap: number): Line[];

The function takes in a polygon, which is represented as an array of points (each point being a an array of 2 numbers [x, y]).

The angle sets the angle of the hachure lines in degrees.

The gap arguments sets the distance between each hachure line.

The function returns an array of lines. Each line is an array of two points.

import { hachureFill } from 'hachure-fill';

// Polygon vertices
const vertices = [
  [10, 10],
  [200, 10],
  [100, 100],
  [300, 100],
  [60, 200]
];

// Lines filling the polygon 
// at an angle of 45 degrees. 
// Lines are 10px apart.
const lines = hachureFill(vertices, 45, 10);

// Draw lines...

hachureFill(points: Point[][], angle: number, gap: number): Line[];

When dealing with Polygon with holes, you can provide an array of polygons. The outer polygon, and polygones represented each of the holes. The polygons need not be nested, but if they are, even-odd rules apply to fill the shape.

Keywords

FAQs

Package last updated on 27 Sep 2023

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