MCPcopy
hub / github.com/slowlydev/f1-dash / createSectors

Function createSectors

dashboard/src/lib/map.ts:45–70  ·  view source on GitHub ↗
(map: Map)

Source from the content-addressed store, hash-verified

43};
44
45export 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
72export const findYellowSectors = (messages: Message[] | undefined): Set<number> => {
73 const msgs = messages?.sort(sortUtc).filter((msg) => {

Callers 1

MapFunction · 0.90

Calls 1

findMinDistanceFunction · 0.85

Tested by

no test coverage detected