@anandommi/fields2cover 0.0.0-stage → 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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 — 2026-11-04
4
+
5
+ First release.
6
+
7
+ - Fields2Cover-style coverage planner in pure JavaScript (`planCoverage`).
8
+ - Mower path generator with validation and optional start/end join (`computeF2cMowerPath`).
9
+ - Headland generation, boustrophedon cell decomposition, swaths along a reference line.
10
+ - Headland laps with even spacing, leapfrog row order, min-radius Dubins turns and obstacle transits.
11
+ - Criss-cross (second pass at 90°) and obstacle avoidance.
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Anand
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,3 +1,70 @@
1
- # Temporary Holding Version
1
+ # @anandommi/fields2cover
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/AnandOmmi/fields2cover/actions/workflows/ci.yml/badge.svg)](https://github.com/AnandOmmi/fields2cover/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@anandommi/fields2cover)](https://www.npmjs.com/package/@anandommi/fields2cover)
5
+
6
+ Pure-JavaScript coverage path planner for robotic mowers, following the
7
+ [Fields2Cover](https://github.com/Fields2Cover/Fields2Cover) v2 pipeline.
8
+ No native build — runs anywhere Node runs, on plain GeoJSON `[lng, lat]` coordinates.
9
+
10
+ | stage | file | what it does |
11
+ |---|---|---|
12
+ | headland | `lib/headland.js` | constant-width headland around boundary and obstacles |
13
+ | decomposition | `lib/decomposition.js` | boustrophedon cells, so rows never straddle an obstacle |
14
+ | swaths | `lib/swaths.js` | parallel swaths along the reference line |
15
+ | headland laps | `lib/headlandLaps.js` | laps that mow the headland band itself |
16
+ | route order | `lib/routeOrder.js` | leapfrog row order per cell + greedy cell order |
17
+ | path planning | `lib/pathPlanner.js` | min-radius Dubins turns, transit around obstacles |
18
+
19
+ Differences from Fields2Cover: the swath angle comes from a user reference
20
+ line (no angle search), cells are ordered greedily instead of with OR-tools,
21
+ and every turn/transit is validated against the real drive area.
22
+
23
+ ## Install
24
+
25
+ ```sh
26
+ npm install @anandommi/fields2cover
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```js
32
+ const { computeF2cMowerPath } = require('@anandommi/fields2cover');
33
+
34
+ const out = computeF2cMowerPath({
35
+ polygonCoords: [[0, 0], [0.0009, 0], [0.0009, 0.00054], [0, 0.00054], [0, 0]],
36
+ referenceLineCoords: [[0, 0], [0.0009, 0]], // rows run parallel to this
37
+ offsetDistance: 3, // headland width, m
38
+ spacing: 1, // row spacing, m
39
+ turningRadius: 2, // minimum turning radius, m
40
+ crissCross: false, // add a second pass at 90°
41
+ obstacleAvoid: true,
42
+ obstaclePolygons: [], // array of [lng, lat] rings
43
+ joinStartAndEnd: false // close the path back to its start
44
+ });
45
+
46
+ if (out.status === 200) {
47
+ console.log(out.result); // GeoJSON FeatureCollection with one LineString
48
+ } else {
49
+ console.error(out.status, out.error);
50
+ }
51
+ ```
52
+
53
+ `computeF2cMowerPath` never throws: it returns `{ status, result }` on success
54
+ or `{ status, error }` on failure. The lower-level
55
+ `planCoverage({ polygonCoords, obstacleRings, referenceLineCoords, headlandWidth, spacing, turningRadius, crissCross })`
56
+ returns raw coordinates and stats, and throws on bad input.
57
+
58
+ For large fields, run it inside a `worker_threads` worker so it does not block the event loop.
59
+
60
+ ## Releasing
61
+
62
+ 1. Bump `version` in `package.json` and add a `CHANGELOG.md` entry.
63
+ 2. Commit, tag `vX.Y.Z`, push the tag.
64
+ 3. The `Publish to npm` workflow tests and publishes (needs repo secret `NPM_TOKEN`).
65
+
66
+ Manual alternative: `npm login` then `npm publish` (runs tests first via `prepublishOnly`).
67
+
68
+ ## License
69
+
70
+ BSD-3-Clause
package/index.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ export type Position = [number, number];
2
+ export type Ring = Position[];
3
+
4
+ export interface PlanCoverageOptions {
5
+ polygonCoords: Ring;
6
+ obstacleRings?: Ring[];
7
+ referenceLineCoords: Position[];
8
+ headlandWidth: number;
9
+ spacing: number;
10
+ turningRadius: number;
11
+ crissCross?: boolean;
12
+ }
13
+
14
+ export interface PlanCoverageResult {
15
+ coordinates: Position[];
16
+ driveFeature: unknown;
17
+ rowCounts: number[];
18
+ cellCount: number;
19
+ skippedRows: number;
20
+ lapCount: number;
21
+ skippedLaps: number;
22
+ [key: string]: unknown;
23
+ }
24
+
25
+ export function planCoverage(options: PlanCoverageOptions): PlanCoverageResult;
26
+
27
+ export interface MowerPathRequest {
28
+ polygonCoords: Ring;
29
+ referenceLineCoords: Position[];
30
+ offsetDistance: number;
31
+ spacing: number;
32
+ turningRadius: number;
33
+ crissCross?: boolean;
34
+ obstacleAvoid?: boolean;
35
+ obstaclePolygons?: Ring[];
36
+ joinStartAndEnd?: boolean;
37
+ }
38
+
39
+ export interface MowerPathFeatureCollection {
40
+ type: 'FeatureCollection';
41
+ features: Array<{
42
+ type: 'Feature';
43
+ properties: Record<string, unknown>;
44
+ geometry: { type: 'LineString'; coordinates: Position[] };
45
+ }>;
46
+ }
47
+
48
+ export type MowerPathResponse =
49
+ | { status: 200; result: MowerPathFeatureCollection; contentDisposition: string }
50
+ | { status: number; error: string; message?: string };
51
+
52
+ export function computeF2cMowerPath(body: MowerPathRequest): MowerPathResponse;
53
+
54
+ export function closeMowerPath(coordinates: Position[], options: { turningRadius: number; gap?: number }): any;
55
+ export function closeMowerPathFallback(coordinates: Position[], options: { turningRadius: number; gap?: number; safeArea?: unknown }): any;
56
+
57
+ export const CONNECTOR_BOUNDARY_CLEARANCE_M: number;
58
+ export const CONNECTOR_OBSTACLE_CLEARANCE_M: number;
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ const { planCoverage, CONNECTOR_BOUNDARY_CLEARANCE_M, CONNECTOR_OBSTACLE_CLEARANCE_M } = require('./lib/coverage');
2
+ const { computeF2cMowerPath } = require('./lib/mowerPath');
3
+ const { closeMowerPath } = require('./lib/mowerLoopPath');
4
+ const { closeMowerPathFallback } = require('./lib/mowerLoopFallback');
5
+
6
+ module.exports = {
7
+ planCoverage,
8
+ computeF2cMowerPath,
9
+ closeMowerPath,
10
+ closeMowerPathFallback,
11
+ CONNECTOR_BOUNDARY_CLEARANCE_M,
12
+ CONNECTOR_OBSTACLE_CLEARANCE_M
13
+ };