planefill 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jesse Daniel Mitchell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # planefill
2
+
3
+ Coverage path planning algorithms for GeoJSON polygons. Give it a polygon and a spacing, get back a `Feature<LineString>` that sweeps the interior — ready to feed to a drone, robot, or anything else that needs to cover an area.
4
+
5
+ Built during a vibe-coding session with [Claude](https://claude.ai/claude-code).
6
+
7
+ ---
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install planefill
13
+ ```
14
+
15
+ `@turf/turf` is a peer dependency and will be installed automatically.
16
+
17
+ ---
18
+
19
+ ## Quick start
20
+
21
+ ```js
22
+ import { planPath } from 'planefill';
23
+
24
+ const polygon = {
25
+ type: 'Feature',
26
+ geometry: {
27
+ type: 'Polygon',
28
+ coordinates: [[
29
+ [-0.005, -0.005], [0.005, -0.005],
30
+ [0.005, 0.005], [-0.005, 0.005],
31
+ [-0.005, -0.005],
32
+ ]],
33
+ },
34
+ };
35
+
36
+ const path = planPath(polygon, { strategy: 'boustrophedon', spacing: 50 });
37
+ // → Feature<LineString> with properties.strategy and properties.spacing
38
+ ```
39
+
40
+ ---
41
+
42
+ ## API
43
+
44
+ ### `planPath(geojson, options)`
45
+
46
+ Plan a single-agent coverage path over a polygon.
47
+
48
+ | Parameter | Type | Description |
49
+ |---|---|---|
50
+ | `geojson` | `Feature<Polygon\|MultiPolygon>` or bare geometry | The area to cover |
51
+ | `options.spacing` | `number` | Row / ring separation **in metres**. Required. |
52
+ | `options.strategy` | `Strategy` | Which algorithm to use. Default: `'boustrophedon'` |
53
+ | `options.angle` | `number` | Sweep rotation in degrees (clockwise from East). Only used by `'boustrophedon'` and `'diagonal'`. Default: `0` |
54
+
55
+ Returns `Feature<LineString>` with `properties.strategy` and `properties.spacing`.
56
+
57
+ ```js
58
+ import { planPath } from 'planefill';
59
+
60
+ const path = planPath(polygon, {
61
+ strategy: 'hilbert',
62
+ spacing: 30,
63
+ });
64
+ ```
65
+
66
+ ---
67
+
68
+ ### `planMultiPath(geojson, options)`
69
+
70
+ Divide a polygon into N regions and plan a coverage path in each. Returns a `FeatureCollection<LineString>` — one feature per party — with a `properties.party` index on each.
71
+
72
+ | Parameter | Type | Description |
73
+ |---|---|---|
74
+ | `options.parties` | `number` | Number of regions / agents. Default: `2` |
75
+ | `options.divisionStrategy` | `DivisionStrategy` | How to divide the polygon. Default: `'vertical'` |
76
+ | `options.coverageStrategy` | `Strategy` | Coverage algorithm for each region. Default: `'boustrophedon'` |
77
+ | `options.spacing` | `number` | Row / ring separation in metres. Required. |
78
+ | `options.angle` | `number` | Sweep angle (boustrophedon / diagonal only). Default: `0` |
79
+
80
+ ```js
81
+ import { planMultiPath } from 'planefill';
82
+
83
+ const collection = planMultiPath(polygon, {
84
+ parties: 4,
85
+ divisionStrategy: 'balanced',
86
+ coverageStrategy: 'boustrophedon',
87
+ spacing: 50,
88
+ });
89
+
90
+ for (const feature of collection.features) {
91
+ console.log(`Party ${feature.properties.party}:`, feature.geometry.coordinates.length, 'waypoints');
92
+ }
93
+ ```
94
+
95
+ ---
96
+
97
+ ### `dividePolygon(polygon, n, strategy?)`
98
+
99
+ Low-level utility — divide a `Feature<Polygon>` into up to `n` non-empty sub-polygons without planning paths. Useful if you want to handle the coverage step yourself.
100
+
101
+ ```js
102
+ import { dividePolygon } from 'planefill';
103
+
104
+ const regions = dividePolygon(polygon, 3, 'balanced');
105
+ // → Feature<Polygon>[] (may be fewer than 3 for small / irregular polygons)
106
+ ```
107
+
108
+ ---
109
+
110
+ ### `STRATEGIES`
111
+
112
+ `Record<Strategy, fn>` — the map of all registered strategy implementations. Useful for building UI dropdowns or validating user input.
113
+
114
+ ```js
115
+ import { STRATEGIES } from 'planefill';
116
+
117
+ console.log(Object.keys(STRATEGIES));
118
+ // ['boustrophedon', 'diagonal', 'outer-in', 'inner-out', 'hilbert', 'grid-spiral']
119
+ ```
120
+
121
+ ---
122
+
123
+ ### `DIVISION_STRATEGIES`
124
+
125
+ `DivisionStrategy[]` — ordered list of all division strategy names.
126
+
127
+ ```js
128
+ import { DIVISION_STRATEGIES } from 'planefill';
129
+
130
+ console.log(DIVISION_STRATEGIES);
131
+ // ['vertical', 'horizontal', 'grid', 'balanced']
132
+ ```
133
+
134
+ ---
135
+
136
+ ## Coverage strategies
137
+
138
+ | Strategy | Description |
139
+ |---|---|
140
+ | `boustrophedon` | Classic lawnmower pattern — parallel scan lines alternating left→right and right→left. Accepts an `angle` parameter to rotate the sweep direction. |
141
+ | `diagonal` | Boustrophedon at a fixed 45° angle. |
142
+ | `outer-in` | Concentric rings eroding inward from the polygon boundary toward the centre. |
143
+ | `inner-out` | Same concentric rings, traversed from the centre outward. |
144
+ | `hilbert` | Hilbert space-filling curve mapped to a cell grid. Visits every cell in a locality-preserving order. |
145
+ | `grid-spiral` | Outward expanding-square spiral over a cell grid (same grid size as Hilbert). Each step is exactly one cell horizontal or vertical — self-avoiding on convex polygons. |
146
+
147
+ All strategies go through a **Ramer-Douglas-Peucker simplification pass** (tolerance = 5% of spacing) before the path is returned, removing redundant collinear waypoints.
148
+
149
+ ---
150
+
151
+ ## Division strategies
152
+
153
+ | Strategy | Description |
154
+ |---|---|
155
+ | `vertical` | N equal-width vertical strips clipped to the polygon. |
156
+ | `horizontal` | N equal-height horizontal strips clipped to the polygon. |
157
+ | `grid` | ⌈√N⌉ × ⌈N/⌈√N⌉⌉ bounding-box grid (e.g. 4 parties → 2×2, 6 → 3×2). |
158
+ | `balanced` | Recursive binary split along the longer bbox dimension. Each bisection is positioned by binary search so both halves receive area proportional to their leaf count — producing roughly equal-area regions even for irregular polygons and odd values of N. |
159
+
160
+ ---
161
+
162
+ ## TypeScript
163
+
164
+ The package ships a hand-authored declaration file (`dist/index.d.ts`). All public types are exported:
165
+
166
+ ```ts
167
+ import {
168
+ planPath,
169
+ planMultiPath,
170
+ dividePolygon,
171
+ type Strategy,
172
+ type DivisionStrategy,
173
+ type PolygonInput,
174
+ type PlanPathOptions,
175
+ type PlanMultiPathOptions,
176
+ type PathProperties,
177
+ type MultiPathProperties,
178
+ } from 'planefill';
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Browser / bundler usage
184
+
185
+ The package exports both ESM (`dist/index.mjs`) and CJS (`dist/index.cjs`). Modern bundlers (Vite, esbuild, Webpack 5+) will pick up the ESM build automatically via the `exports` field. `@turf/turf` is kept external — your bundler resolves it from `node_modules`.
186
+
187
+ ---
188
+
189
+ ## Development
190
+
191
+ ```bash
192
+ git clone <repo>
193
+ npm install
194
+
195
+ npm test # run the test suite (vitest)
196
+ npm run build # compile dist/ (ESM + CJS + types)
197
+ npm run build:ui # bundle the demo UI (esbuild IIFE → ui/bundle.js)
198
+ npm run dev:ui # same, with --watch
199
+ ```
200
+
201
+ The demo UI (`ui/`) is a Leaflet app that lets you visualise every strategy interactively. Open `ui/index.html` after running `build:ui`. It is not published to npm.
202
+
203
+ ---
204
+
205
+ ## License
206
+
207
+ MIT