1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
use crate::;
use Z0;
use Angle;
use ;
use crate::;
/// Defines how a coordinate system behaves.
///
/// For example, two coordinate systems that implement `CoordinateSystem<Convention = NedLike>`
/// both behave [`NedLike`], and get appropriately-named accessors on types like [`Coordinate`]
/// and [`Vector`] (ie, `north`, `east`, and `down`).
///
/// While you _can_ implement this trait directly, prefer using [`system!`](crate::system).
/// Links a coordinate system convention to the type holding the constituent parts under proper
/// names.
///
/// The `Time` component is the magnitude of the time dimension in the encompassed unit, expressed
/// in terms of values from the [`typenum`] crate. For example, `Time = Z0` would signify a length
/// with no time component, which would simply be a length (eg, meters). `Time = N1` would signify
/// a length with a ^-1 time component, which is a velocity (eg, meters per second). Similarly,
/// `Time = N2` is acceleration (eg, meters per second squared).
///
/// You should generally implement this trait generically. The `Time = Z0` default is only there to
/// preserve backwards compatibility.
/// Indicates that the implementing coordinate system is exactly equivalent to
/// `OtherCoordinateSystem`.
///
/// More technically, `impl EquivalentTo<B> for A` should only exist if the transform from `A` to
/// `B` is the identify function.
///
/// This is useful when you have two coordinate systems that you know have exactly equivalent axes,
/// and you need the types to "work out". This can be the case, for instance, when two crates have
/// both separately declared a NED-like coordinate system centered on the same object, and you need
/// to move types between them.
///
/// When an `impl EquivalentTo<B> for A` exists, a number of the types in this library provide a
/// `cast` method that allows directly changing the coordinate system type parameter without any
/// other transformation argument.
///
/// You will generally want to implement `EquivalentTo` for both `A` and `B` so that casts can
/// happen in either direction. This should always be safe since if the transform is identity from
/// `A` to `B`, it better also be from `B` to `A`.
///
/// # Safety
///
/// This trait is unsafe to implement because it allows moving between types annotated with two
/// different coordinate systems without performing any transform on them. If a transform actually
/// _is_ needed (and thus this implementation is incorrect), this would violate type safety.
pub unsafe
/// All coordinate systems are equivalent to themselves.
unsafe
/// Defines the meaning of "bearing" (ie, azimuth and elevation) in a coordinate system.
///
/// For example, for [`NedLike`] and [`FrdLike`] coordinate systems:
///
/// - azimuth is the angle counterclockwise about positive Z along the XY plane from the positive X
/// axis (ie, North or Forward); and
/// - elevation is the angle towards _negative_ Z from the XY plane
/// (ie, "up").
///
/// Note that the "counterclockwise" above is around Z-axis as viewed from positive Z, which in
/// [`NedLike`] and [`FrdLike`] is _down_, so viewed from "above" positive azimuth will look
/// clockwise (as expected).
///
/// And for the [`EnuLike`] coordinate system:
///
/// - azimuth is the angle clockwise about positive Z along the XY plane from positive Y; and
/// - elevation is the angle towards positive Z from the XY plane.
/// Marks an NED-like coordinate system where the axes are North, East, and Down.
///
/// NEDs are always right-handed coordinate systems, and have earth bounded axes:
///
/// - Positive X is North.
/// - Positive Y is East.
/// - Positive Z is towards the center of the earth ("Down").
///
/// Note that two NED-like coordinate systems may have different "absolute" Earth-bound coordinates
/// for their origin. For example, two different aircraft may both define their observations in
/// NED-like coordinate systems, but for each aircraft, (0, 0, 0) corresponds to the location of
/// that aircraft. Thus, an object observed at, say, (10, 20, 30) in one aircraft's local NED-like
/// coordinate system will have completely different coordinates in the other aircraft's local
/// NED-like coordinate system. NED systems also vary by time for moving observers, which you can
/// read more about in the crate-level docs on temporal drift.
///
/// Since NED has earth bounded axes, two observers that are located in the same place but face in
/// different directions, they will still have the same NED-like coordinates to a given emitter.
///
/// [Bearing](BearingDefined) in NED-like coordinate systems are defined as:
///
/// - azimuth is the angle clockwise as seen from above along the horizontal plane from North; and
/// - elevation is the angle upwards from the horizontal plane.
///
/// <https://en.wikipedia.org/wiki/Local_tangent_plane_coordinates#Local_north,_east,_down_(NED)_coordinates>
;
/// Components for Cartesian points in an [`NedLike`] coordinate system.
///
/// Usually provided to methods like [`Coordinate::build`] or [`Vector::build`].
/// Marks an FRD-like coordinate system where the axes are Front (or "Forward"), Right, and Down.
///
/// FRDs are right-handed coordinate systems, and have observer bounded axes:
///
/// - Positive X is in the direction of travel of the observer (eg, aircraft).
/// - Positive Y is to the right of the observer's center of mass, parallel to the line that runs
/// wingtip to wingtip.
/// - Positive Z is along the line that runs through the belly of the plane.
///
/// Note that two FRD-like coordinate systems may have different "absolute" Earth-bound coordinates
/// for their origin. For example, two different aircraft may both define their observations in
/// FRD-like coordinate systems, but for each aircraft, (0, 0, 0) corresponds to the center of mass
/// of that aircraft. Thus, an object observed at, say, (10, 20, 30) in one aircraft's local
/// FRD-like coordinate system will have completely different coordinates in the other aircraft's
/// local FRD-like coordinate system. FRD systems also vary by time for moving observers, which you
/// can read more about in the crate-level docs on temporal drift.
///
/// Further note that, unlike [`NedLike`], two FRD-like systems with a colocated origin may also be
/// rotated with respect to each other. In other words, two observers that are located in the same
/// place but face in different directions will measure _different_ FRD-like coordinates to a given
/// emitter.
///
/// [Bearing](BearingDefined) in FRD-like coordinate systems are defined as:
///
/// - azimuth is the angle clockwise as seen from above along the horizontal plane from forward;
/// and
/// - elevation is the angle upwards from the horizontal plane.
///
/// <https://en.wikipedia.org/wiki/Aircraft_principal_axes>
;
/// Components for Cartesian points in an [`FrdLike`] coordinate system.
///
/// Usually provided to methods like [`Coordinate::build`] or [`Vector::build`].
/// Marks an ENU-like coordinate system where the axes are East, North, and Up.
///
/// ENUs are always right-handed coordinate systems, and have earth bounded axes:
///
/// - Positive X is East.
/// - Positive Y is North.
/// - Positive Z is away from the center of the earth ("Up").
///
/// Note that two ENU-like coordinate systems may have different "absolute" Earth-bound coordinates
/// for their origin. For example, two different aircraft may both define their observations in
/// ENU-like coordinate systems, but for each aircraft, (0, 0, 0) corresponds to the location of
/// that aircraft. Thus, an object observed at, say, (10, 20, 30) in one aircraft's local ENU-like
/// coordinate system will have completely different coordinates in the other aircraft's local
/// ENU-like coordinate system. ENU systems also vary by time for moving observers, which you can
/// read more about in the crate-level docs on temporal drift.
///
/// Since ENU has earth bounded axes, two observers that are located in the same place but face in
/// different directions, they will still have the same ENU-like coordinates to a given emitter.
///
/// [Bearing](BearingDefined) in ENU-like coordinate systems are defined as:
///
/// - azimuth is the angle clockwise as seen from above along the horizontal plane from North; and
/// - elevation is the angle upwards from the horizontal plane.
///
/// <https://en.wikipedia.org/wiki/Local_tangent_plane_coordinates#Local_east,_north,_up_(ENU)_coordinates>
;
/// Components for Cartesian points in an [`EnuLike`] coordinate system.
///
/// Usually provided to methods like [`Coordinate::build`] or [`Vector::build`].
/// Marks a coordinate system whose axes are simply named X, Y, and Z.
///
/// Unlike [`NedLike`] and [`FrdLike`], there is no intrinsic relationship between XYZ-like
/// coordinate systems. While two XYZ-like coordinate systems _may_ share definitions of X, Y, and
/// Z, that shared meaning is not communicated through this type.
;
/// Components for Cartesian points in an coordinate system without specific names for X, Y, and Z,
/// like [`RightHandedXyzLike`].
///
/// Usually provided to methods like [`Coordinate::build`] or [`Vector::build`].
/// Defines a new coordinate system and its conventions.
///
/// Note that the coordinate system is a zero-sized type used only to mark things like
/// [`Coordinate`] and [`Vector`] with what coordinate system they are in. A coordinate system does
/// not know its relation to any other coordinate system (or global positions like WGS84).
///
/// At present, this macro allows you to define the following kinds of coordinate systems:
///
/// [`NedLike`]
///
/// ```rust
/// # use sguaba::system;
/// system!(pub struct SensorNed using NED);
/// ```
///
/// [`EnuLike`]
///
/// ```rust
/// # use sguaba::system;
/// system!(pub struct SensorEnu using ENU);
/// ```
///
/// [`FrdLike`]
///
/// ```rust
/// # use sguaba::system;
/// system!(pub struct EmitterFrd using FRD);
/// ```
///
/// [`RightHandedXyzLike`]
///
/// ```rust
/// # use sguaba::system;
/// system!(pub struct PlaneEcef using right-handed XYZ);
/// ```
///
/// You can include doc comments and attributes directly in the invocation of `system!` to add docs
/// and derived traits to your type:
///
/// ```rust
/// sguaba::system! {
/// #[derive(Hash)]
/// pub(crate) struct SensorNed using NED
/// }
/// ```