turf.booleanParallel
What is turf.booleanParallel?
turf.booleanParallel compares two LineStrings segment by segment and returns true only if every segment of the first is parallel to the corresponding segment of the second. Parallel here means the direction vectors match within a tolerance.
turf.booleanParallel(line1, line2) → booleanWhen would you use turf.booleanParallel?
Use turf.booleanParallel for geometry checks in map design and engineering — verifying that two segmented lines (e.g. a rail alignment and a service road) remain aligned, or confirming that a redrawn centreline preserves the original shape.
It is strict: any single non-parallel segment returns false. For a partial or average parallelism check, roll your own with turf.segmentEach and turf.bearing.
turf.booleanParallel(rail, road); // true if rail and road run parallel throughoutFAQs
How do I install Turf.js to use this function?
Install npm install @turf/boolean-parallel and import import { booleanParallel } from '@turf/boolean-parallel', or reach turf.booleanParallel via @turf/turf.
Do the two lines need the same number of vertices?
Yes. The comparison is segment-by-segment; unequal vertex counts fail early.
Does direction matter?
Yes — segments must point the same way. A line running east-to-west is not considered parallel to its west-to-east twin under this function.
When should I use booleanParallel vs computing bearings?
Use booleanParallel for a quick yes/no on whole lines. For nuanced analysis — average deviation, per-segment angles — compute bearings yourself with turf.segmentEach and turf.bearing.