(line, target, property)
| 1 | import {_boundSegment, _boundSegments, _normalizeAngle} from '../../helpers/index.js'; |
| 2 | |
| 3 | export function _segments(line, target, property) { |
| 4 | const segments = line.segments; |
| 5 | const points = line.points; |
| 6 | const tpoints = target.points; |
| 7 | const parts = []; |
| 8 | |
| 9 | for (const segment of segments) { |
| 10 | let {start, end} = segment; |
| 11 | end = _findSegmentEnd(start, end, points); |
| 12 | |
| 13 | const bounds = _getBounds(property, points[start], points[end], segment.loop); |
| 14 | |
| 15 | if (!target.segments) { |
| 16 | // Special case for boundary not supporting `segments` (simpleArc) |
| 17 | // Bounds are provided as `target` for partial circle, or undefined for full circle |
| 18 | parts.push({ |
| 19 | source: segment, |
| 20 | target: bounds, |
| 21 | start: points[start], |
| 22 | end: points[end] |
| 23 | }); |
| 24 | continue; |
| 25 | } |
| 26 | |
| 27 | // Get all segments from `target` that intersect the bounds of current segment of `line` |
| 28 | const targetSegments = _boundSegments(target, bounds); |
| 29 | |
| 30 | for (const tgt of targetSegments) { |
| 31 | const subBounds = _getBounds(property, tpoints[tgt.start], tpoints[tgt.end], tgt.loop); |
| 32 | const fillSources = _boundSegment(segment, points, subBounds); |
| 33 | |
| 34 | for (const fillSource of fillSources) { |
| 35 | parts.push({ |
| 36 | source: fillSource, |
| 37 | target: tgt, |
| 38 | start: { |
| 39 | [property]: _getEdge(bounds, subBounds, 'start', Math.max) |
| 40 | }, |
| 41 | end: { |
| 42 | [property]: _getEdge(bounds, subBounds, 'end', Math.min) |
| 43 | } |
| 44 | }); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | return parts; |
| 49 | } |
| 50 | |
| 51 | export function _getBounds(property, first, last, loop) { |
| 52 | if (loop) { |
no test coverage detected