Skip to content

Commit

Permalink
front: rename getPointCoordinates -> getPointCoordinatesOnTrack
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Jan 24, 2025
1 parent 49915e2 commit 848a054
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { setFailure } from 'reducers/main';
import type { PathStep } from 'reducers/osrdconf/types';
import { useAppDispatch } from 'store';
import { castErrorToFailure } from 'utils/error';
import { getPointCoordinates } from 'utils/geometry';
import { getPointCoordinatesOnTrack } from 'utils/geometry';

import type { ManageTrainSchedulePathProperties } from '../types';
import { useManageTrainScheduleContext } from './useManageTrainScheduleContext';
Expand Down Expand Up @@ -103,7 +103,7 @@ const useSetupItineraryForTrainUpdate = (trainIdToEdit: number) => {
if ('track' in step) {
const track = tracks[step.track];
if (track) {
coordinates = getPointCoordinates(track.geo, track.length, step.offset);
coordinates = getPointCoordinatesOnTrack(track.geo, track.length, step.offset);
}
} else {
let op: SearchResultItemOperationalPoint | undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TrackRange, TrackSection } from 'common/api/osrdEditoastApi';
import { findTrackSectionOffset } from 'modules/powerRestriction/helpers/createPathStep';
import { getPointCoordinates } from 'utils/geometry';
import { getPointCoordinatesOnTrack } from 'utils/geometry';
import { mToMm } from 'utils/physics';

/**
Expand All @@ -21,7 +21,7 @@ const getPointOnPathCoordinates = (

const track = tracks[trackOffset!.track];

return getPointCoordinates(track.geo, mToMm(track.length), trackOffset!.offset);
return getPointCoordinatesOnTrack(track.geo, mToMm(track.length), trackOffset!.offset);
};

export default getPointOnPathCoordinates;
4 changes: 2 additions & 2 deletions front/src/modules/pathfinding/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getSupportedElectrification, isThermal } from 'modules/rollingStock/hel
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import type { PathStep } from 'reducers/osrdconf/types';
import { addElementAtIndex } from 'utils/array';
import { getPointCoordinates } from 'utils/geometry';
import { getPointCoordinatesOnTrack } from 'utils/geometry';

import getStepLocation from './helpers/getStepLocation';

Expand All @@ -35,7 +35,7 @@ export const formatSuggestedOperationalPoints = (
offsetOnTrack: op.part.position,
track: op.part.track,
positionOnPath: op.position,
coordinates: getPointCoordinates(geometry, pathLength, op.position),
coordinates: getPointCoordinatesOnTrack(geometry, pathLength, op.position),
metadata: op?.metadata,
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { osrdEditoastApi, type OperationalPoint } from 'common/api/osrdEditoastA
import { useOsrdConfSelectors } from 'common/osrdContext';
import { setPointIti } from 'modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/setPointIti';
import { type PathStep } from 'reducers/osrdconf/types';
import { getPointCoordinates } from 'utils/geometry';
import { getPointCoordinatesOnTrack } from 'utils/geometry';

import type { FeatureInfoClick } from '../types';
import OperationalPointPopupDetails from './OperationalPointPopupDetails';
Expand Down Expand Up @@ -121,7 +121,7 @@ const AddPathStepPopup = ({

const trackPartCoordinates = operationalPoint.parts.map((part) => ({
trackName: tracks[part.track]?.extensions?.sncf?.track_name,
coordinates: getPointCoordinates(
coordinates: getPointCoordinatesOnTrack(
tracks[part.track]?.geo,
tracks[part.track]?.length,
part.position
Expand Down
15 changes: 10 additions & 5 deletions front/src/utils/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,21 @@ export function nearestPointOnLine(
});
}

export function getPointCoordinates(
/**
* Given a track's geometry and length and an offset from the start of the track (in mm),
* returns the coordinates of the point for the given offset.
*/
export function getPointCoordinatesOnTrack(
geometry: GeoJsonLineString,
pathLength: number,
infraPositionOnPath: number
trackLength: number, // in mm
infraPositionOnTrack: number // in mm
): Position {
const pathLineString = lineString(geometry.coordinates);
const geometryTrackLength = length(pathLineString, { units: 'millimeters' });
const infraTrackLength = pathLength;
const infraTrackLength = trackLength;
// TODO TS2 : when adapting train update check that this computation works properly
const geometryDistanceAlongTrack = infraPositionOnPath * (geometryTrackLength / infraTrackLength);
const geometryDistanceAlongTrack =
infraPositionOnTrack * (geometryTrackLength / infraTrackLength);
return along(pathLineString, geometryDistanceAlongTrack, { units: 'millimeters' }).geometry
.coordinates;
}

0 comments on commit 848a054

Please sign in to comment.