(map: Map)
| 43 | }; |
| 44 | |
| 45 | export const createSectors = (map: Map): MapSector[] => { |
| 46 | const sectors: MapSector[] = []; |
| 47 | const points: TrackPosition[] = map.x.map((x, index) => ({ x, y: map.y[index] })); |
| 48 | |
| 49 | for (let i = 0; i < map.marshalSectors.length; i++) { |
| 50 | sectors.push({ |
| 51 | number: i + 1, |
| 52 | start: map.marshalSectors[i].trackPosition, |
| 53 | end: map.marshalSectors[i + 1] ? map.marshalSectors[i + 1].trackPosition : map.marshalSectors[0].trackPosition, |
| 54 | points: [], |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | const dividers: number[] = sectors.map((s) => findMinDistance(s.start, points)); |
| 59 | for (let i = 0; i < dividers.length; i++) { |
| 60 | const start = dividers[i]; |
| 61 | const end = dividers[i + 1] ? dividers[i + 1] : dividers[0]; |
| 62 | if (start < end) { |
| 63 | sectors[i].points = points.slice(start, end + 1); |
| 64 | } else { |
| 65 | sectors[i].points = points.slice(start).concat(points.slice(0, end + 1)); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return sectors; |
| 70 | }; |
| 71 | |
| 72 | export const findYellowSectors = (messages: Message[] | undefined): Set<number> => { |
| 73 | const msgs = messages?.sort(sortUtc).filter((msg) => { |
no test coverage detected