-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front: fix space time chart when first or last waypoint are hidden
Filter data from projected path (path and occupancy blocks) and conflicts when the first or last waypoint is hidden. Allow the space time chart to look as if it started/ended with the first/last displayed waypoint. Signed-off-by: SharglutDev <p.filimon75@gmail.com>
- Loading branch information
1 parent
d371907
commit cd4cdfb
Showing
4 changed files
with
233 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
front/src/modules/simulationResult/components/SpaceTimeChart/helpers/__tests__/utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
import cutSpaceTimeRect from '../utils'; | ||
|
||
describe('interpolateRange', () => { | ||
it('should return null if the interpolated range ends before the cut space', () => { | ||
const range = { | ||
spaceStart: 3, | ||
spaceEnd: 5, | ||
timeStart: 100, | ||
timeEnd: 200, | ||
}; | ||
const interpolatedRange = cutSpaceTimeRect(range, 1, 3); | ||
expect(interpolatedRange).toBeNull(); | ||
}); | ||
|
||
it('should return null if the interpolated range starts after the cut space', () => { | ||
const range = { | ||
spaceStart: 3, | ||
spaceEnd: 5, | ||
timeStart: 100, | ||
timeEnd: 200, | ||
}; | ||
const interpolatedRange = cutSpaceTimeRect(range, 5, 7); | ||
expect(interpolatedRange).toBeNull(); | ||
}); | ||
|
||
it('should return the same range if its ranges are inside the cut space', () => { | ||
const range = { | ||
spaceStart: 3, | ||
spaceEnd: 5, | ||
timeStart: 100, | ||
timeEnd: 200, | ||
}; | ||
const interpolatedRange = cutSpaceTimeRect(range, 2, 7); | ||
expect(interpolatedRange).toEqual(range); | ||
}); | ||
|
||
it('should return the interpolated range when the start position is outside the cut space', () => { | ||
const range = { | ||
spaceStart: 3, | ||
spaceEnd: 5, | ||
timeStart: 100, | ||
timeEnd: 200, | ||
}; | ||
const interpolatedRange = cutSpaceTimeRect(range, 4, 5); | ||
expect(interpolatedRange).toEqual({ | ||
spaceStart: 4, | ||
spaceEnd: 5, | ||
timeStart: 150, | ||
timeEnd: 200, | ||
}); | ||
}); | ||
|
||
it('should return the interpolated range when the end position is is outside the cut space', () => { | ||
const range = { | ||
spaceStart: 3, | ||
spaceEnd: 6, | ||
timeStart: 100, | ||
timeEnd: 160, | ||
}; | ||
const interpolatedRange = cutSpaceTimeRect(range, 3, 5); | ||
expect(interpolatedRange).toEqual({ | ||
spaceStart: 3, | ||
spaceEnd: 5, | ||
timeStart: 100, | ||
timeEnd: 140, | ||
}); | ||
}); | ||
|
||
it('should return the interpolated range when both positions are outside the cut space', () => { | ||
const range = { | ||
spaceStart: 3, | ||
spaceEnd: 6, | ||
timeStart: 100, | ||
timeEnd: 160, | ||
}; | ||
const interpolatedRange = cutSpaceTimeRect(range, 4, 5); | ||
expect(interpolatedRange).toEqual({ | ||
spaceStart: 4, | ||
spaceEnd: 5, | ||
timeStart: 120, | ||
timeEnd: 140, | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
front/src/modules/simulationResult/components/SpaceTimeChart/helpers/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { LayerRangeData } from '../../../types'; | ||
|
||
const cutSpaceTimeRect = ( | ||
range: LayerRangeData, | ||
minSpace: number, | ||
maxSpace: number | ||
): LayerRangeData | null => { | ||
let { timeStart, timeEnd, spaceStart, spaceEnd } = range; | ||
|
||
if (spaceEnd <= minSpace || spaceStart >= maxSpace) { | ||
return null; | ||
} | ||
|
||
if (spaceStart < minSpace) { | ||
const interpolationFactor = (minSpace - spaceStart) / (spaceEnd - spaceStart); | ||
spaceStart = minSpace; | ||
timeStart += (timeEnd - timeStart) * interpolationFactor; | ||
} | ||
|
||
if (spaceEnd > maxSpace) { | ||
const interpolationFactor = (spaceEnd - maxSpace) / (spaceEnd - spaceStart); | ||
spaceEnd = maxSpace; | ||
timeEnd -= (timeEnd - timeStart) * interpolationFactor; | ||
} | ||
|
||
return { | ||
spaceStart, | ||
spaceEnd, | ||
timeStart, | ||
timeEnd, | ||
}; | ||
}; | ||
|
||
export default cutSpaceTimeRect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters