1
1
define ( [
2
2
'../Core/binarySearch' ,
3
+ '../Core/Check' ,
3
4
'../Core/defaultValue' ,
4
5
'../Core/defined' ,
5
6
'../Core/defineProperties' ,
@@ -10,6 +11,7 @@ define([
10
11
'../Core/LinearApproximation'
11
12
] , function (
12
13
binarySearch ,
14
+ Check ,
13
15
defaultValue ,
14
16
defined ,
15
17
defineProperties ,
@@ -166,9 +168,7 @@ define([
166
168
*/
167
169
function SampledProperty ( type , derivativeTypes ) {
168
170
//>>includeStart('debug', pragmas.debug);
169
- if ( ! defined ( type ) ) {
170
- throw new DeveloperError ( 'type is required.' ) ;
171
- }
171
+ Check . defined ( 'type' , type ) ;
172
172
//>>includeEnd('debug');
173
173
174
174
var innerType = type ;
@@ -372,9 +372,7 @@ define([
372
372
*/
373
373
SampledProperty . prototype . getValue = function ( time , result ) {
374
374
//>>includeStart('debug', pragmas.debug);
375
- if ( ! defined ( time ) ) {
376
- throw new DeveloperError ( 'time is required.' ) ;
377
- }
375
+ Check . defined ( 'time' , time ) ;
378
376
//>>includeEnd('debug');
379
377
380
378
var times = this . _times ;
@@ -531,7 +529,7 @@ define([
531
529
} ;
532
530
533
531
/**
534
- * Adds a new sample
532
+ * Adds a new sample.
535
533
*
536
534
* @param {JulianDate } time The sample time.
537
535
* @param {Packable } value The value at the provided time.
@@ -542,14 +540,10 @@ define([
542
540
var hasDerivatives = defined ( innerDerivativeTypes ) ;
543
541
544
542
//>>includeStart('debug', pragmas.debug);
545
- if ( ! defined ( time ) ) {
546
- throw new DeveloperError ( 'time is required.' ) ;
547
- }
548
- if ( ! defined ( value ) ) {
549
- throw new DeveloperError ( 'value is required.' ) ;
550
- }
551
- if ( hasDerivatives && ! defined ( derivatives ) ) {
552
- throw new DeveloperError ( 'derivatives is required.' ) ;
543
+ Check . defined ( 'time' , time ) ;
544
+ Check . defined ( 'value' , value ) ;
545
+ if ( hasDerivatives ) {
546
+ Check . defined ( 'derivatives' , derivatives ) ;
553
547
}
554
548
//>>includeEnd('debug');
555
549
@@ -570,7 +564,7 @@ define([
570
564
} ;
571
565
572
566
/**
573
- * Adds an array of samples
567
+ * Adds an array of samples.
574
568
*
575
569
* @param {JulianDate[] } times An array of JulianDate instances where each index is a sample time.
576
570
* @param {Packable[] } values The array of values, where each value corresponds to the provided times index.
@@ -584,12 +578,8 @@ define([
584
578
var hasDerivatives = defined ( innerDerivativeTypes ) ;
585
579
586
580
//>>includeStart('debug', pragmas.debug);
587
- if ( ! defined ( times ) ) {
588
- throw new DeveloperError ( 'times is required.' ) ;
589
- }
590
- if ( ! defined ( values ) ) {
591
- throw new DeveloperError ( 'values is required.' ) ;
592
- }
581
+ Check . defined ( 'times' , times ) ;
582
+ Check . defined ( 'values' , values ) ;
593
583
if ( times . length !== values . length ) {
594
584
throw new DeveloperError ( 'times and values must be the same length.' ) ;
595
585
}
@@ -627,16 +617,68 @@ define([
627
617
*/
628
618
SampledProperty . prototype . addSamplesPackedArray = function ( packedSamples , epoch ) {
629
619
//>>includeStart('debug', pragmas.debug);
630
- if ( ! defined ( packedSamples ) ) {
631
- throw new DeveloperError ( 'packedSamples is required.' ) ;
632
- }
620
+ Check . defined ( 'packedSamples' , packedSamples ) ;
633
621
//>>includeEnd('debug');
634
622
635
623
mergeNewSamples ( epoch , this . _times , this . _values , packedSamples , this . _packedLength ) ;
636
624
this . _updateTableLength = true ;
637
625
this . _definitionChanged . raiseEvent ( this ) ;
638
626
} ;
639
627
628
+ /**
629
+ * Removes a sample at the given time, if present.
630
+ *
631
+ * @param {JulianDate } time The sample time.
632
+ * @returns {Boolean } <code>true</code> if a sample at time was removed, <code>false</code> otherwise.
633
+ */
634
+ SampledProperty . prototype . removeSample = function ( time ) {
635
+ //>>includeStart('debug', pragmas.debug);
636
+ Check . defined ( 'time' , time ) ;
637
+ //>>includeEnd('debug');
638
+
639
+ var index = binarySearch ( this . _times , time , JulianDate . compare ) ;
640
+ if ( index < 0 ) {
641
+ return false ;
642
+ }
643
+ removeSamples ( this , index , 1 ) ;
644
+ return true ;
645
+ } ;
646
+
647
+ function removeSamples ( property , startIndex , numberToRemove ) {
648
+ var packedLength = property . _packedLength ;
649
+ property . _times . splice ( startIndex , numberToRemove ) ;
650
+ property . _values . splice ( startIndex * packedLength , numberToRemove * packedLength ) ;
651
+ property . _updateTableLength = true ;
652
+ property . _definitionChanged . raiseEvent ( property ) ;
653
+ }
654
+
655
+ /**
656
+ * Removes all samples for the given time interval.
657
+ *
658
+ * @param {TimeInterval } time The time interval for which to remove all samples.
659
+ */
660
+ SampledProperty . prototype . removeSamples = function ( timeInterval ) {
661
+ //>>includeStart('debug', pragmas.debug);
662
+ Check . defined ( 'timeInterval' , timeInterval ) ;
663
+ //>>includeEnd('debug');
664
+
665
+ var times = this . _times ;
666
+ var startIndex = binarySearch ( times , timeInterval . start , JulianDate . compare ) ;
667
+ if ( startIndex < 0 ) {
668
+ startIndex = ~ startIndex ;
669
+ } else if ( ! timeInterval . isStartIncluded ) {
670
+ ++ startIndex ;
671
+ }
672
+ var stopIndex = binarySearch ( times , timeInterval . stop , JulianDate . compare ) ;
673
+ if ( stopIndex < 0 ) {
674
+ stopIndex = ~ stopIndex ;
675
+ } else if ( timeInterval . isStopIncluded ) {
676
+ ++ stopIndex ;
677
+ }
678
+
679
+ removeSamples ( this , startIndex , stopIndex - startIndex ) ;
680
+ } ;
681
+
640
682
/**
641
683
* Compares this property to the provided property and returns
642
684
* <code>true</code> if they are equal, <code>false</code> otherwise.
0 commit comments