View Javadoc
1   /*
2    * Copyright (C) 2019 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.irurueta.navigation.gnss;
17  
18  import com.irurueta.geometry.InhomogeneousPoint3D;
19  import com.irurueta.geometry.Point3D;
20  import com.irurueta.navigation.frames.ECEFPosition;
21  import com.irurueta.navigation.frames.ECEFVelocity;
22  import com.irurueta.units.Distance;
23  import com.irurueta.units.DistanceConverter;
24  import com.irurueta.units.DistanceUnit;
25  import com.irurueta.units.Speed;
26  import com.irurueta.units.SpeedConverter;
27  import com.irurueta.units.SpeedUnit;
28  
29  import java.io.Serializable;
30  import java.util.Objects;
31  
32  /**
33   * Contains GNSS measurement data of a satellite.
34   */
35  public class GNSSMeasurement implements Serializable, Cloneable {
36  
37      /**
38       * Pseudo-range measurement expressed in meters (m).
39       */
40      private double pseudoRange;
41  
42      /**
43       * Pseudo-range rate measurement expressed in meters per second (m/s).
44       */
45      private double pseudoRate;
46  
47      /**
48       * X coordinate of satellite ECEF position expressed in meters (m).
49       */
50      private double x;
51  
52      /**
53       * Y coordinate of satellite ECEF position expressed in meters (m).
54       */
55      private double y;
56  
57      /**
58       * Z coordinate of satellite ECEF position expressed in meters (m).
59       */
60      private double z;
61  
62      /**
63       * X coordinate of satellite ECEF velocity expressed in meters per second (m/s).
64       */
65      private double vx;
66  
67      /**
68       * Y coordinate of satellite ECEF velocity expressed in meters per second (m/s).
69       */
70      private double vy;
71  
72      /**
73       * Z coordinate of satellite ECEF velocity expressed in meters per second (m/s).
74       */
75      private double vz;
76  
77      /**
78       * Constructor.
79       */
80      public GNSSMeasurement() {
81      }
82  
83      /**
84       * Constructor.
85       *
86       * @param pseudoRange pseudo-range measurement expressed in meters (m).
87       * @param pseudoRate  pseudo-range rate measurement expressed in meters per second (m/s).
88       * @param x           x coordinate of satellite ECEF position expressed in meters (m).
89       * @param y           y coordinate of satellite ECEF position expressed in meters (m).
90       * @param z           z coordinate of satellite ECEF position expressed in meters (m).
91       * @param vx          x coordinate of satellite ECEF velocity expressed in meters per second (m/s).
92       * @param vy          y coordinate of satellite ECEF velocity expressed in meters per second (m/s).
93       * @param vz          z coordinate of satellite ECEF velocity expressed in meters per second (m/s).
94       */
95      public GNSSMeasurement(final double pseudoRange, final double pseudoRate,
96                             final double x, final double y, final double z,
97                             final double vx, final double vy, final double vz) {
98          setPseudoRange(pseudoRange);
99          setPseudoRate(pseudoRate);
100         setPositionCoordinates(x, y, z);
101         setVelocityCoordinates(vx, vy, vz);
102     }
103 
104     /**
105      * Constructor.
106      *
107      * @param pseudoRange pseudo-range measurement.
108      * @param pseudoRate  pseudo-range rate measurement.
109      * @param x           x coordinate of satellite ECEF position.
110      * @param y           y coordinate of satellite ECEF position.
111      * @param z           z coordinate of satellite ECEF position.
112      * @param vx          x coordinate of satellite ECEF velocity.
113      * @param vy          y coordinate of satellite ECEF velocity.
114      * @param vz          z coordinate of satellite ECEF velocity.
115      */
116     public GNSSMeasurement(final Distance pseudoRange, final Speed pseudoRate,
117                            final Distance x, final Distance y, final Distance z,
118                            final Speed vx, final Speed vy, final Speed vz) {
119         setPseudoRangeDistance(pseudoRange);
120         setPseudoRateSpeed(pseudoRate);
121         setPositionCoordinates(x, y, z);
122         setVelocityCoordinates(vx, vy, vz);
123     }
124 
125     /**
126      * Constructor.
127      *
128      * @param pseudoRange pseudo-range measurement.
129      * @param pseudoRate  pseudo-range rate measurement.
130      * @param position    satellite ECEF position expressed in meters (m).
131      * @param vx          x coordinate of satellite ECEF velocity.
132      * @param vy          y coordinate of satellite ECEF velocity.
133      * @param vz          z coordinate of satellite ECEF velocity.
134      */
135     public GNSSMeasurement(final Distance pseudoRange, final Speed pseudoRate, final Point3D position,
136                            final Speed vx, final Speed vy, final Speed vz) {
137         setPseudoRangeDistance(pseudoRange);
138         setPseudoRateSpeed(pseudoRate);
139         setPosition(position);
140         setVelocityCoordinates(vx, vy, vz);
141     }
142 
143     /**
144      * Constructor.
145      *
146      * @param pseudoRange pseudo-range measurement expressed in meters (m).
147      * @param pseudoRate  pseudo-range rate measurement expressed in meters per second (m/s).
148      * @param position    satellite ECEF position.
149      * @param velocity    satellite ECEF velocity.
150      */
151     public GNSSMeasurement(final double pseudoRange, final double pseudoRate, final ECEFPosition position,
152                            final ECEFVelocity velocity) {
153         setPseudoRange(pseudoRange);
154         setPseudoRate(pseudoRate);
155         setEcefPosition(position);
156         setEcefVelocity(velocity);
157     }
158 
159     /**
160      * Constructor.
161      *
162      * @param pseudoRange         pseudo-range measurement expressed in meters (m).
163      * @param pseudoRate          pseudo-range rate measurement expressed in meters per second (m/s).
164      * @param positionAndVelocity satellite ECEF position and velocity.
165      */
166     public GNSSMeasurement(final double pseudoRange, final double pseudoRate,
167                            final ECEFPositionAndVelocity positionAndVelocity) {
168         setPseudoRange(pseudoRange);
169         setPseudoRate(pseudoRate);
170         setPositionAndVelocity(positionAndVelocity);
171     }
172 
173     /**
174      * Constructor.
175      *
176      * @param pseudoRange pseudo-range measurement.
177      * @param pseudoRate  pseudo-range rate measurement.
178      * @param position    satellite ECEF position.
179      * @param velocity    satellite ECEF velocity.
180      */
181     public GNSSMeasurement(final Distance pseudoRange, final Speed pseudoRate, final ECEFPosition position,
182                            final ECEFVelocity velocity) {
183         setPseudoRangeDistance(pseudoRange);
184         setPseudoRateSpeed(pseudoRate);
185         setEcefPosition(position);
186         setEcefVelocity(velocity);
187     }
188 
189     /**
190      * Constructor.
191      *
192      * @param pseudoRange         pseudo-range measurement.
193      * @param pseudoRate          pseudo-range rate measurement.
194      * @param positionAndVelocity satellite ECEF position and velocity.
195      */
196     public GNSSMeasurement(final Distance pseudoRange, final Speed pseudoRate,
197                            final ECEFPositionAndVelocity positionAndVelocity) {
198         setPseudoRangeDistance(pseudoRange);
199         setPseudoRateSpeed(pseudoRate);
200         setPositionAndVelocity(positionAndVelocity);
201     }
202 
203     /**
204      * Copy constructor.
205      *
206      * @param input input instance to copy data from.
207      */
208     public GNSSMeasurement(final GNSSMeasurement input) {
209         copyFrom(input);
210     }
211 
212     /**
213      * Gets pseudo-range measurement expressed in meters (m).
214      *
215      * @return pseudo-range measurement expressed in meters (m).
216      */
217     public double getPseudoRange() {
218         return pseudoRange;
219     }
220 
221     /**
222      * Sets pseudo-range measurement expressed in meters (m).
223      *
224      * @param pseudoRange pseudo-range measurement expressed in meters (m).
225      */
226     public void setPseudoRange(final double pseudoRange) {
227         this.pseudoRange = pseudoRange;
228     }
229 
230     /**
231      * Gets pseudo-range measurement.
232      *
233      * @param result instance where pseudo-range measurement will be stored.
234      */
235     public void getPseudoRangeDistance(final Distance result) {
236         result.setValue(pseudoRange);
237         result.setUnit(DistanceUnit.METER);
238     }
239 
240     /**
241      * Gets pseudo-range measurement.
242      *
243      * @return pseudo-range measurement.
244      */
245     public Distance getPseudoRangeDistance() {
246         return new Distance(pseudoRange, DistanceUnit.METER);
247     }
248 
249     /**
250      * Sets pseudo-range measurement.
251      *
252      * @param pseudoRange pseudo-range measurement.
253      */
254     public void setPseudoRangeDistance(final Distance pseudoRange) {
255         this.pseudoRange = DistanceConverter.convert(pseudoRange.getValue().doubleValue(), pseudoRange.getUnit(),
256                 DistanceUnit.METER);
257     }
258 
259     /**
260      * Gets pseudo-range rate measurement expressed in meters per second (m/s).
261      *
262      * @return pseudo-range rate measurement expressed in meters per second (m/s).
263      */
264     public double getPseudoRate() {
265         return pseudoRate;
266     }
267 
268     /**
269      * Sets pseudo-range rate measurement expressed in meters per second (m/s).
270      *
271      * @param pseudoRate pseudo-range rate measurement expressed in meters per second (m/s).
272      */
273     public void setPseudoRate(final double pseudoRate) {
274         this.pseudoRate = pseudoRate;
275     }
276 
277     /**
278      * Gets pseudo-range rate measurement.
279      *
280      * @param result instance where pseudo-range rate measurement will be stored.
281      */
282     public void getPseudoRateSpeed(final Speed result) {
283         result.setValue(pseudoRate);
284         result.setUnit(SpeedUnit.METERS_PER_SECOND);
285     }
286 
287     /**
288      * Gets pseudo-range rate measurement.
289      *
290      * @return pseudo-range rate measurement.
291      */
292     public Speed getPseudoRateSpeed() {
293         return new Speed(pseudoRate, SpeedUnit.METERS_PER_SECOND);
294     }
295 
296     /**
297      * Sets pseudo-range rate measurement.
298      *
299      * @param pseudoRate pseudo-range rate measurement.
300      */
301     public void setPseudoRateSpeed(final Speed pseudoRate) {
302         this.pseudoRate = SpeedConverter.convert(pseudoRate.getValue().doubleValue(), pseudoRate.getUnit(),
303                 SpeedUnit.METERS_PER_SECOND);
304     }
305 
306     /**
307      * Gets x coordinate of satellite ECEF position expressed in meters (m).
308      *
309      * @return x coordinate of satellite ECEF position expressed in meters (m).
310      */
311     public double getX() {
312         return x;
313     }
314 
315     /**
316      * Sets x coordinate of satellite ECEF position expressed in meters (m).
317      *
318      * @param x x coordinate of satellite ECEF position expressed in meters (m).
319      */
320     public void setX(final double x) {
321         this.x = x;
322     }
323 
324     /**
325      * Gets x coordinate of satellite ECEF position.
326      *
327      * @param result instance where x coordinate of satellite ECEF position will be
328      *               stored.
329      */
330     public void getDistanceX(final Distance result) {
331         result.setValue(x);
332         result.setUnit(DistanceUnit.METER);
333     }
334 
335     /**
336      * Gets x coordinate of satellite ECEF position.
337      *
338      * @return x coordinate of satellite ECEF position.
339      */
340     public Distance getDistanceX() {
341         return new Distance(x, DistanceUnit.METER);
342     }
343 
344     /**
345      * Sets x coordinate of satellite ECEF position.
346      *
347      * @param x x coordinate of satellite ECEF position.
348      */
349     public void setDistanceX(final Distance x) {
350         this.x = DistanceConverter.convert(x.getValue().doubleValue(), x.getUnit(), DistanceUnit.METER);
351     }
352 
353     /**
354      * Gets y coordinate of satellite ECEF position expressed in meters (m).
355      *
356      * @return y coordinate of satellite ECEF position expressed in meters (m).
357      */
358     public double getY() {
359         return y;
360     }
361 
362     /**
363      * Sets y coordinate of satellite ECEF position expressed in meters (m).
364      *
365      * @param y y coordinate of satellite ECEF position expressed in meters (m).
366      */
367     public void setY(final double y) {
368         this.y = y;
369     }
370 
371     /**
372      * Gets y coordinate of satellite ECEF position.
373      *
374      * @param result instance where y coordinate of satellite ECEF position will be
375      *               stored.
376      */
377     public void getDistanceY(final Distance result) {
378         result.setValue(y);
379         result.setUnit(DistanceUnit.METER);
380     }
381 
382     /**
383      * Gets y coordinate of satellite ECEF position.
384      *
385      * @return y coordinate of satellite ECEF position.
386      */
387     public Distance getDistanceY() {
388         return new Distance(y, DistanceUnit.METER);
389     }
390 
391     /**
392      * Sets y coordinate of satellite ECEF position.
393      *
394      * @param y y coordinate of satellite ECEF position.
395      */
396     public void setDistanceY(final Distance y) {
397         this.y = DistanceConverter.convert(y.getValue().doubleValue(), y.getUnit(), DistanceUnit.METER);
398     }
399 
400     /**
401      * Gets z coordinate of satellite ECEF position expressed in meters (m).
402      *
403      * @return z coordinate of satellite ECEF position expressed in meters (m).
404      */
405     public double getZ() {
406         return z;
407     }
408 
409     /**
410      * Sets z coordinate of satellite ECEF position expressed in meters (m).
411      *
412      * @param z z coordinate of satellite ECEF position expressed in meters (m).
413      */
414     public void setZ(final double z) {
415         this.z = z;
416     }
417 
418     /**
419      * Gets z coordinate of satellite ECEF position.
420      *
421      * @param result instance where z coordinate of satellite ECEF position will be
422      *               stored.
423      */
424     public void getDistanceZ(final Distance result) {
425         result.setValue(z);
426         result.setUnit(DistanceUnit.METER);
427     }
428 
429     /**
430      * Gets z coordinate of satellite ECEF position.
431      *
432      * @return z coordinate of satellite ECEF position.
433      */
434     public Distance getDistanceZ() {
435         return new Distance(z, DistanceUnit.METER);
436     }
437 
438     /**
439      * Sets z coordinate of satellite ECEF position.
440      *
441      * @param z z coordinate of satellite ECEF position.
442      */
443     public void setDistanceZ(final Distance z) {
444         this.z = DistanceConverter.convert(z.getValue().doubleValue(), z.getUnit(), DistanceUnit.METER);
445     }
446 
447     /**
448      * Sets coordinates of satellite ECEF position expressed in meters (m).
449      *
450      * @param x x coordinate.
451      * @param y y coordinate.
452      * @param z z coordinate.
453      */
454     public void setPositionCoordinates(final double x, final double y, final double z) {
455         this.x = x;
456         this.y = y;
457         this.z = z;
458     }
459 
460     /**
461      * Sets coordinates of satellite ECEF position.
462      *
463      * @param x x coordinate.
464      * @param y y coordinate.
465      * @param z z coordinate.
466      */
467     public void setPositionCoordinates(final Distance x, final Distance y, final Distance z) {
468         setDistanceX(x);
469         setDistanceY(y);
470         setDistanceZ(z);
471     }
472 
473     /**
474      * Gets satellite ECEF position expressed in meters (m).
475      *
476      * @param result instance where satellite ECEF position will be stored.
477      */
478     public void getPosition(final Point3D result) {
479         result.setInhomogeneousCoordinates(x, y, z);
480     }
481 
482     /**
483      * Gets satellite ECEF position expressed in meters (m).
484      *
485      * @return ECEF position of satellite.
486      */
487     public Point3D getPosition() {
488         return new InhomogeneousPoint3D(x, y, z);
489     }
490 
491     /**
492      * Sets ECEF position of satellite expressed in meters (m).
493      *
494      * @param position ECEF position of satellite.
495      */
496     public void setPosition(final Point3D position) {
497         x = position.getInhomX();
498         y = position.getInhomY();
499         z = position.getInhomZ();
500     }
501 
502     /**
503      * Gets ECEF position of satellite.
504      *
505      * @param result instance where ECEF position of satellite will be stored.
506      */
507     public void getEcefPosition(final ECEFPosition result) {
508         result.setCoordinates(x, y, z);
509     }
510 
511     /**
512      * Gets ECEF position of satellite.
513      *
514      * @return ECEF position of satellite.
515      */
516     public ECEFPosition getEcefPosition() {
517         return new ECEFPosition(x, y, z);
518     }
519 
520     /**
521      * Sets ECEF position of satellite.
522      *
523      * @param ecefPosition ECEF position of satellite.
524      */
525     public void setEcefPosition(final ECEFPosition ecefPosition) {
526         x = ecefPosition.getX();
527         y = ecefPosition.getY();
528         z = ecefPosition.getZ();
529     }
530 
531     /**
532      * Gets x coordinate of satellite ECEF velocity expressed in meters per second (m/s).
533      *
534      * @return x coordinate of satellite ECEF velocity expressed in meters per second (m/s).
535      */
536     public double getVx() {
537         return vx;
538     }
539 
540     /**
541      * Sets x coordinate of satellite ECEF velocity expressed in meters per second (m/s).
542      *
543      * @param vx x coordinate of satellite ECEF velocity expressed in meters per second (m/s).
544      */
545     public void setVx(final double vx) {
546         this.vx = vx;
547     }
548 
549     /**
550      * Gets x coordinate of satellite ECEF velocity.
551      *
552      * @param result instance where x coordinate of satellite ECEF velocity will
553      *               be stored.
554      */
555     public void getSpeedX(final Speed result) {
556         result.setValue(vx);
557         result.setUnit(SpeedUnit.METERS_PER_SECOND);
558     }
559 
560     /**
561      * Gets x coordinate of satellite ECEF velocity.
562      *
563      * @return x coordinate of satellite ECEF velocity.
564      */
565     public Speed getSpeedX() {
566         return new Speed(vx, SpeedUnit.METERS_PER_SECOND);
567     }
568 
569     /**
570      * Sets x coordinate of satellite ECEF velocity.
571      *
572      * @param speedX x coordinate of satellite ECEF velocity.
573      */
574     public void setSpeedX(final Speed speedX) {
575         vx = SpeedConverter.convert(speedX.getValue().doubleValue(), speedX.getUnit(), SpeedUnit.METERS_PER_SECOND);
576     }
577 
578     /**
579      * Gets y coordinate of satellite ECEF velocity expressed in meters per second (m/s).
580      *
581      * @return y coordinate of satellite ECEF velocity expressed in meters per second (m/s).
582      */
583     public double getVy() {
584         return vy;
585     }
586 
587     /**
588      * Sets y coordinate of satellite ECEF velocity expressed in meters per second (m/s).
589      *
590      * @param vy y coordinate of satellite ECEF velocity expressed in meters per second (m/s).
591      */
592     public void setVy(final double vy) {
593         this.vy = vy;
594     }
595 
596     /**
597      * Gets y coordinate of satellite ECEF velocity.
598      *
599      * @param result instance where y coordinate of satellite ECEF velocity will
600      *               be stored.
601      */
602     public void getSpeedY(final Speed result) {
603         result.setValue(vy);
604         result.setUnit(SpeedUnit.METERS_PER_SECOND);
605     }
606 
607     /**
608      * Gets y coordinate of satellite ECEF velocity.
609      *
610      * @return y coordinate of satellite ECEF velocity.
611      */
612     public Speed getSpeedY() {
613         return new Speed(vy, SpeedUnit.METERS_PER_SECOND);
614     }
615 
616     /**
617      * Sets y coordinate of satellite ECEF velocity.
618      *
619      * @param speedY y coordinate of satellite ECEF velocity.
620      */
621     public void setSpeedY(final Speed speedY) {
622         vy = SpeedConverter.convert(speedY.getValue().doubleValue(), speedY.getUnit(), SpeedUnit.METERS_PER_SECOND);
623     }
624 
625     /**
626      * Gets z coordinate of satellite ECEF velocity expressed in meters per second (m/s).
627      *
628      * @return z coordinate of satellite ECEF velocity expressed in meters per second (m/s).
629      */
630     public double getVz() {
631         return vz;
632     }
633 
634     /**
635      * Sets z coordinate of satellite ECEF velocity expressed in meters per second (m/s).
636      *
637      * @param vz z coordinate of satellite ECEF velocity expressed in meters per second (m/s).
638      */
639     public void setVz(final double vz) {
640         this.vz = vz;
641     }
642 
643     /**
644      * Gets z coordinate of satellite ECEF velocity.
645      *
646      * @param result z coordinate of satellite ECEF velocity.
647      */
648     public void getSpeedZ(final Speed result) {
649         result.setValue(vz);
650         result.setUnit(SpeedUnit.METERS_PER_SECOND);
651     }
652 
653     /**
654      * Gets z coordinate of satellite ECEF velocity.
655      *
656      * @return z coordinate of satellite ECEF velocity.
657      */
658     public Speed getSpeedZ() {
659         return new Speed(vz, SpeedUnit.METERS_PER_SECOND);
660     }
661 
662     /**
663      * Sets z coordinate of satellite ECEF velocity.
664      *
665      * @param speedZ z coordinate of satellite ECEF velocity.
666      */
667     public void setSpeedZ(final Speed speedZ) {
668         vz = SpeedConverter.convert(speedZ.getValue().doubleValue(), speedZ.getUnit(), SpeedUnit.METERS_PER_SECOND);
669     }
670 
671     /**
672      * Sets ECEF coordinates of satellite velocity expressed in meters per second (m/s).
673      *
674      * @param vx x coordinate of satellite ECEF velocity.
675      * @param vy y coordinate of satellite ECEF velocity.
676      * @param vz z coordinate of satellite ECEF velocity.
677      */
678     public void setVelocityCoordinates(final double vx, final double vy, final double vz) {
679         this.vx = vx;
680         this.vy = vy;
681         this.vz = vz;
682     }
683 
684     /**
685      * Sets ECEF coordinates of satellite velocity.
686      *
687      * @param speedX x coordinate of satellite ECEF velocity.
688      * @param speedY y coordinate of satellite ECEF velocity.
689      * @param speedZ z coordinate of satellite ECEF velocity.
690      */
691     public void setVelocityCoordinates(final Speed speedX, final Speed speedY, final Speed speedZ) {
692         setSpeedX(speedX);
693         setSpeedY(speedY);
694         setSpeedZ(speedZ);
695     }
696 
697     /**
698      * Gets ECEF velocity of satellite.
699      *
700      * @param result instance where ECEF velocity of satellite will be stored.
701      */
702     public void getEcefVelocity(final ECEFVelocity result) {
703         result.setCoordinates(vx, vy, vz);
704     }
705 
706     /**
707      * Gets ECEF velocity of satellite.
708      *
709      * @return ECEF velocity of satellite.
710      */
711     public ECEFVelocity getEcefVelocity() {
712         return new ECEFVelocity(vx, vy, vz);
713     }
714 
715     /**
716      * Sets ECEF velocity of satellite.
717      *
718      * @param ecefVelocity ECEF velocity of satellite.
719      */
720     public void setEcefVelocity(final ECEFVelocity ecefVelocity) {
721         vx = ecefVelocity.getVx();
722         vy = ecefVelocity.getVy();
723         vz = ecefVelocity.getVz();
724     }
725 
726     /**
727      * Gets ECEF position and velocity of satellite.
728      *
729      * @param result instance where position and velocity will be stored.
730      */
731     public void getPositionAndVelocity(final ECEFPositionAndVelocity result) {
732         result.setPositionCoordinates(x, y, z);
733         result.setVelocityCoordinates(vx, vy, vz);
734     }
735 
736     /**
737      * Gets ECEF position and velocity of satellite.
738      *
739      * @return ECEF position and velocity of satellite.
740      */
741     public ECEFPositionAndVelocity getPositionAndVelocity() {
742         return new ECEFPositionAndVelocity(x, y, z, vx, vy, vz);
743     }
744 
745     /**
746      * Sets ECEF position and velocity of satellite.
747      *
748      * @param positionAndVelocity ECEF position and velocity of satellite.
749      */
750     public void setPositionAndVelocity(final ECEFPositionAndVelocity positionAndVelocity) {
751         x = positionAndVelocity.getX();
752         y = positionAndVelocity.getY();
753         z = positionAndVelocity.getZ();
754 
755         vx = positionAndVelocity.getVx();
756         vy = positionAndVelocity.getVy();
757         vz = positionAndVelocity.getVz();
758     }
759 
760     /**
761      * Copies this instance data into provided instance.
762      *
763      * @param output destination instance where data will be copied to.
764      */
765     public void copyTo(final GNSSMeasurement output) {
766         output.pseudoRange = pseudoRange;
767         output.pseudoRate = pseudoRate;
768 
769         output.x = x;
770         output.y = y;
771         output.z = z;
772 
773         output.vx = vx;
774         output.vy = vy;
775         output.vz = vz;
776     }
777 
778     /**
779      * Copies data of provided instance into this instance.
780      *
781      * @param input instance to copy data from.
782      */
783     public void copyFrom(final GNSSMeasurement input) {
784         pseudoRange = input.pseudoRange;
785         pseudoRate = input.pseudoRate;
786 
787         x = input.x;
788         y = input.y;
789         z = input.z;
790 
791         vx = input.vx;
792         vy = input.vy;
793         vz = input.vz;
794     }
795 
796     /**
797      * Computes and returns hash code for this instance. Hash codes are almost unique
798      * values that are useful for fast classification and storage of objects in collections.
799      *
800      * @return Hash code.
801      */
802     @Override
803     public int hashCode() {
804         return Objects.hash(pseudoRange, pseudoRate, x, y, z, vx, vy, vz);
805     }
806 
807     /**
808      * Checks if provided object is a GNSSMeasurement having exactly the same contents
809      * as this instance.
810      *
811      * @param obj Object to be compared.
812      * @return true if both objects are considered to be equal, false otherwise.
813      */
814     @Override
815     public boolean equals(final Object obj) {
816         if (obj == this) {
817             return true;
818         }
819         if (obj == null || getClass() != obj.getClass()) {
820             return false;
821         }
822 
823         final var other = (GNSSMeasurement) obj;
824         return equals(other);
825     }
826 
827     /**
828      * Checks if provided instance has exactly the same contents as this instance.
829      *
830      * @param other instance to be compared.
831      * @return true if both instances are considered to be equal, false otherwise.
832      */
833     public boolean equals(final GNSSMeasurement other) {
834         return equals(other, 0.0);
835     }
836 
837     /**
838      * Checks if provided instance has contents similar to this instance up to provided
839      * threshold value.
840      *
841      * @param other     instance to be compared.
842      * @param threshold maximum difference allowed for values.
843      * @return true if both instances are considered to be equal (up to provided threshold),
844      * false otherwise.
845      */
846     public boolean equals(final GNSSMeasurement other, final double threshold) {
847         if (other == null) {
848             return false;
849         }
850 
851         return Math.abs(pseudoRange - other.pseudoRange) <= threshold
852                 && Math.abs(pseudoRate - other.pseudoRate) <= threshold
853                 && Math.abs(x - other.x) <= threshold
854                 && Math.abs(y - other.y) <= threshold
855                 && Math.abs(z - other.z) <= threshold
856                 && Math.abs(vx - other.vx) <= threshold
857                 && Math.abs(vy - other.vy) <= threshold
858                 && Math.abs(vz - other.vz) <= threshold;
859     }
860 
861     /**
862      * Makes a copy of this instance.
863      *
864      * @return a copy of this instance.
865      * @throws CloneNotSupportedException if clone fails for some reason.
866      */
867     @Override
868     protected Object clone() throws CloneNotSupportedException {
869         final var result = (GNSSMeasurement) super.clone();
870         copyTo(result);
871         return result;
872     }
873 }