All files / engine/Source/Core CylinderGeometryLibrary.js

100% Statements 34/34
100% Branches 8/8
100% Functions 1/1
100% Lines 34/34

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          1x         1x             17x 17x   17x 17x 17x   17x 17x 17x 17x   17x 1176x 1176x 1176x 1176x 1176x 1176x 1176x   1176x 1176x 1176x   1176x 1176x 1176x 1176x 1176x 1039x 1039x 1039x 1039x 1039x 1039x       17x      
import CesiumMath from "./Math.js";
 
/**
 * @private
 */
const CylinderGeometryLibrary = {};
 
/**
 * @private
 */
CylinderGeometryLibrary.computePositions = function (
  length,
  topRadius,
  bottomRadius,
  slices,
  fill,
) {
  const topZ = length * 0.5;
  const bottomZ = -topZ;
 
  const twoSlice = slices + slices;
  const size = fill ? 2 * twoSlice : twoSlice;
  const positions = new Float64Array(size * 3);
  let i;
  let index = 0;
  let tbIndex = 0;
  const bottomOffset = fill ? twoSlice * 3 : 0;
  const topOffset = fill ? (twoSlice + slices) * 3 : slices * 3;
 
  for (i = 0; i < slices; i++) {
    const angle = (i / slices) * CesiumMath.TWO_PI;
    const x = Math.cos(angle);
    const y = Math.sin(angle);
    const bottomX = x * bottomRadius;
    const bottomY = y * bottomRadius;
    const topX = x * topRadius;
    const topY = y * topRadius;
 
    positions[tbIndex + bottomOffset] = bottomX;
    positions[tbIndex + bottomOffset + 1] = bottomY;
    positions[tbIndex + bottomOffset + 2] = bottomZ;
 
    positions[tbIndex + topOffset] = topX;
    positions[tbIndex + topOffset + 1] = topY;
    positions[tbIndex + topOffset + 2] = topZ;
    tbIndex += 3;
    if (fill) {
      positions[index++] = bottomX;
      positions[index++] = bottomY;
      positions[index++] = bottomZ;
      positions[index++] = topX;
      positions[index++] = topY;
      positions[index++] = topZ;
    }
  }
 
  return positions;
};
export default CylinderGeometryLibrary;