1- import isObject from 'lodash-es/isObject' ;
21import max from 'lodash-es/max' ;
32
43import { convexHull2D , euclideanDistance2D } from '@skybrush/math' ;
54import {
5+ getTrajectorySegmentsInTimeWindow ,
6+ isValidTrajectory ,
67 type TimeWindow ,
78 type Trajectory ,
89 type TrajectorySegment ,
9- trajectorySegmentsInTimeWindow ,
1010} from '@skybrush/show-format' ;
1111
1212import type { Coordinate2D , Coordinate3D } from '~/utils/math' ;
@@ -119,27 +119,6 @@ export const getPointsOfTrajectory = (
119119 return points . map ( ( point ) => point [ 1 ] ) ;
120120} ;
121121
122- /**
123- * Returns the duration of a single drone trajectory, in seconds.
124- */
125- export const getDurationOfTrajectory = (
126- trajectory : Trajectory
127- ) : number | undefined => {
128- if ( ! isValidTrajectory ( trajectory ) ) {
129- return ;
130- }
131-
132- const { points, takeoffTime } = trajectory ;
133-
134- // TODO: `isValidTrajectory` already ensures `points.length > 0`...
135- if ( points . length > 0 ) {
136- const lastPoint = points . at ( - 1 ) ;
137- if ( Array . isArray ( lastPoint ) && lastPoint . length > 1 ) {
138- return lastPoint [ 0 ] + ( takeoffTime ?? 0 ) ;
139- }
140- }
141- } ;
142-
143122/**
144123 * Returns the subtrajectory of the given trajectory that is within the given time window.
145124 *
@@ -155,7 +134,7 @@ export function getTrajectoryInTimeWindow(
155134) : Trajectory {
156135 return {
157136 ...trajectory ,
158- points : trajectorySegmentsInTimeWindow (
137+ points : getTrajectorySegmentsInTimeWindow (
159138 trajectory . points ,
160139 timeWindow
161140 // TODO: Get rid of this type assertion! It only holds if the given
@@ -164,22 +143,3 @@ export function getTrajectoryInTimeWindow(
164143 ) as Trajectory [ 'points' ] ,
165144 } ;
166145}
167-
168- /**
169- * Returns whether a trajectory object "looks like" a valid trajectory.
170- *
171- * TODO: Add validation for the optional `takeoffTime` and `landingTime` fields
172- * Also, maybe this function should be in `@skybrush/show-format` instead
173- */
174- export const isValidTrajectory = (
175- trajectory : unknown
176- ) : trajectory is Trajectory =>
177- // prettier-ignore
178- isObject ( trajectory )
179- // `version` is valid
180- && 'version' in trajectory
181- && trajectory . version === 1
182- // `points` is a valid, non-empty array
183- && 'points' in trajectory
184- && Array . isArray ( trajectory . points )
185- && trajectory . points . length > 0 ;
0 commit comments