Skip to content

Commit

Permalink
refactor(formats): check zone region points are 2-tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
tsa96 committed Sep 15, 2024
1 parent fc4cb8c commit 830e137
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libs/formats/zone/src/zone-validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,22 @@ describe('validateZoneFile', () => {
);
});

it('should throw if a regions point are not a 2-tuple', () => {
input.tracks.main.zones.segments[0].checkpoints[0].regions[0].points[0] =
[0, 0, 0] as any;

expect(() => validateZoneFile(input)).toThrow(
'Track Main segment 1 start zone region 0 point 0 is not a 2-tuple'
);

input.tracks.main.zones.segments[0].checkpoints[0].regions[0].points[0] =
[0, 'i can hear the voice of God'] as any;

expect(() => validateZoneFile(input)).toThrow(
'Track Main segment 1 start zone region 0 point 0 is not a 2-tuple'
);
});

it('should throw if a region has no bottom position', () => {
input.tracks.main.zones.segments[0].checkpoints[0].regions[0].bottom =
undefined;
Expand Down
6 changes: 6 additions & 0 deletions libs/formats/zone/src/zone-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ export function validateZoneFile(input: MapZones): void {
thr('is too high');
}

for (const [i, point] of region.points.entries()) {
if (point.length !== 2 || !point.every((p) => !Number.isNaN(+p))) {
thr(`point ${i} is not a 2-tuple`);
}
}

const MIN_DIST = 4;
const MIN_ANGLE = Math.PI * (15 / 180);

Expand Down

0 comments on commit 830e137

Please sign in to comment.