https://github.com/pshihn/hachure-fill
Fill a polygon with lines at the specified angle and gap between them
https://github.com/pshihn/hachure-fill
Last synced: about 1 month ago
JSON representation
Fill a polygon with lines at the specified angle and gap between them
- Host: GitHub
- URL: https://github.com/pshihn/hachure-fill
- Owner: pshihn
- License: mit
- Created: 2020-05-01T01:08:10.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T17:40:02.000Z (over 1 year ago)
- Last Synced: 2025-04-15T19:09:07.192Z (about 1 month ago)
- Language: TypeScript
- Size: 158 KB
- Stars: 27
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hachure-fill
[Demo](https://hachure-fill.pages.dev/)
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.

## 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.
```javascript
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.