All files / engine/Source/DataSources ScaledPositionProperty.js

77.14% Statements 27/35
38.09% Branches 8/21
77.77% Functions 7/9
77.14% Lines 27/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                            15x 15x 15x 15x     1x     2x         18x                       1x   1x 2x     2x     1x 15x 15x   15x         15x 15x         15x       1x           21x     21x         21x       21x 21x         1x             1x 1x      
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Ellipsoid from "../Core/Ellipsoid.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import ReferenceFrame from "../Core/ReferenceFrame.js";
import Property from "./Property.js";
 
/**
 * This is a temporary class for scaling position properties to the ellipsoid surface.
 * It will go away or be refactored to support data with arbitrary height references.
 * @private
 */
function ScaledPositionProperty(value) {
  this._definitionChanged = new Event();
  this._value = undefined;
  this._removeSubscription = undefined;
  this.setValue(value);
}
 
Object.defineProperties(ScaledPositionProperty.prototype, {
  isConstant: {
    get: function () {
      return Property.isConstant(this._value);
    },
  },
  definitionChanged: {
    get: function () {
      return this._definitionChanged;
    },
  },
  referenceFrame: {
    get: function () {
      return defined(this._value)
        ? this._value.referenceFrame
        : ReferenceFrame.FIXED;
    },
  },
});
 
const timeScratch = new JulianDate();
 
ScaledPositionProperty.prototype.getValue = function (time, result) {
  Iif (!defined(time)) {
    time = JulianDate.now(timeScratch);
  }
  return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
};
 
ScaledPositionProperty.prototype.setValue = function (value) {
  Eif (this._value !== value) {
    this._value = value;
 
    Iif (defined(this._removeSubscription)) {
      this._removeSubscription();
      this._removeSubscription = undefined;
    }
 
    Eif (defined(value)) {
      this._removeSubscription = value.definitionChanged.addEventListener(
        this._raiseDefinitionChanged,
        this,
      );
    }
    this._definitionChanged.raiseEvent(this);
  }
};
 
ScaledPositionProperty.prototype.getValueInReferenceFrame = function (
  time,
  referenceFrame,
  result,
) {
  //>>includeStart('debug', pragmas.debug);
  Iif (!defined(time)) {
    throw new DeveloperError("time is required.");
  }
  Iif (!defined(referenceFrame)) {
    throw new DeveloperError("referenceFrame is required.");
  }
  //>>includeEnd('debug');
 
  Iif (!defined(this._value)) {
    return undefined;
  }
 
  result = this._value.getValueInReferenceFrame(time, referenceFrame, result);
  return defined(result)
    ? Ellipsoid.default.scaleToGeodeticSurface(result, result)
    : undefined;
};
 
ScaledPositionProperty.prototype.equals = function (other) {
  return (
    this === other ||
    (other instanceof ScaledPositionProperty && this._value === other._value)
  );
};
 
ScaledPositionProperty.prototype._raiseDefinitionChanged = function () {
  this._definitionChanged.raiseEvent(this);
};
export default ScaledPositionProperty;