All files / engine/Source/Core VerticalExaggeration.js

78.57% Statements 11/14
50% Branches 3/6
100% Functions 2/2
78.57% Lines 11/14

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                1x                 1x   38094x     38094x       38094x     1x                     1x             417x         417x     417x         417x                    
import Cartesian3 from "./Cartesian3.js";
import Cartographic from "./Cartographic.js";
import DeveloperError from "./DeveloperError.js";
import defined from "./defined.js";
 
/**
 * @private
 */
const VerticalExaggeration = {};
 
/**
 * Scales a height relative to an offset.
 *
 * @param {number} height The height.
 * @param {number} scale A scalar used to exaggerate the terrain. If the value is 1.0 there will be no effect.
 * @param {number} relativeHeight The height relative to which terrain is exaggerated. If the value is 0.0 terrain will be exaggerated relative to the ellipsoid surface.
 */
VerticalExaggeration.getHeight = function (height, scale, relativeHeight) {
  //>>includeStart('debug', pragmas.debug);
  Iif (!Number.isFinite(scale)) {
    throw new DeveloperError("scale must be a finite number.");
  }
  Iif (!Number.isFinite(relativeHeight)) {
    throw new DeveloperError("relativeHeight must be a finite number.");
  }
  //>>includeEnd('debug');
  return (height - relativeHeight) * scale + relativeHeight;
};
 
const scratchCartographic = new Cartographic();
 
/**
 * Scales a position by exaggeration.
 *
 * @param {Cartesian3} position The position.
 * @param {Ellipsoid} ellipsoid The ellipsoid.
 * @param {number} verticalExaggeration A scalar used to exaggerate the terrain. If the value is 1.0 there will be no effect.
 * @param {number} verticalExaggerationRelativeHeight The height relative to which terrain is exaggerated. If the value is 0.0 terrain will be exaggerated relative to the ellipsoid surface.
 * @param {Cartesian3} [result] The object onto which to store the result.
 */
VerticalExaggeration.getPosition = function (
  position,
  ellipsoid,
  verticalExaggeration,
  verticalExaggerationRelativeHeight,
  result,
) {
  const cartographic = ellipsoid.cartesianToCartographic(
    position,
    scratchCartographic,
  );
  // If the position is too near the center of the ellipsoid, exaggeration is undefined.
  Iif (!defined(cartographic)) {
    return Cartesian3.clone(position, result);
  }
  const newHeight = VerticalExaggeration.getHeight(
    cartographic.height,
    verticalExaggeration,
    verticalExaggerationRelativeHeight,
  );
  return Cartesian3.fromRadians(
    cartographic.longitude,
    cartographic.latitude,
    newHeight,
    ellipsoid,
    result,
  );
};
 
export default VerticalExaggeration;