PolylineVolumeGeometryLibrary-00b304ef.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.95
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(['exports', './Matrix2-9e1c22e2', './EllipsoidTangentPlane-d42ee682', './ComponentDatatype-4eeb6d9b', './PolylinePipeline-e67c0760', './Transforms-273eeb44', './defaultValue-97284df2', './RuntimeError-4f8ec8a2'], (function (exports, Matrix2, EllipsoidTangentPlane, ComponentDatatype, PolylinePipeline, Transforms, defaultValue, RuntimeError) { 'use strict';
  26. /**
  27. * Style options for corners.
  28. *
  29. * @demo The {@link https://sandcastle.cesium.com/index.html?src=Corridor.html&label=Geometries|Corridor Demo}
  30. * demonstrates the three corner types, as used by {@link CorridorGraphics}.
  31. *
  32. * @enum {Number}
  33. */
  34. const CornerType = {
  35. /**
  36. * <img src="Images/CornerTypeRounded.png" style="vertical-align: middle;" width="186" height="189" />
  37. *
  38. * Corner has a smooth edge.
  39. * @type {Number}
  40. * @constant
  41. */
  42. ROUNDED: 0,
  43. /**
  44. * <img src="Images/CornerTypeMitered.png" style="vertical-align: middle;" width="186" height="189" />
  45. *
  46. * Corner point is the intersection of adjacent edges.
  47. * @type {Number}
  48. * @constant
  49. */
  50. MITERED: 1,
  51. /**
  52. * <img src="Images/CornerTypeBeveled.png" style="vertical-align: middle;" width="186" height="189" />
  53. *
  54. * Corner is clipped.
  55. * @type {Number}
  56. * @constant
  57. */
  58. BEVELED: 2,
  59. };
  60. var CornerType$1 = Object.freeze(CornerType);
  61. const warnings = {};
  62. /**
  63. * Logs a one time message to the console. Use this function instead of
  64. * <code>console.log</code> directly since this does not log duplicate messages
  65. * unless it is called from multiple workers.
  66. *
  67. * @function oneTimeWarning
  68. *
  69. * @param {String} identifier The unique identifier for this warning.
  70. * @param {String} [message=identifier] The message to log to the console.
  71. *
  72. * @example
  73. * for(let i=0;i<foo.length;++i) {
  74. * if (!defined(foo[i].bar)) {
  75. * // Something that can be recovered from but may happen a lot
  76. * oneTimeWarning('foo.bar undefined', 'foo.bar is undefined. Setting to 0.');
  77. * foo[i].bar = 0;
  78. * // ...
  79. * }
  80. * }
  81. *
  82. * @private
  83. */
  84. function oneTimeWarning(identifier, message) {
  85. //>>includeStart('debug', pragmas.debug);
  86. if (!defaultValue.defined(identifier)) {
  87. throw new RuntimeError.DeveloperError("identifier is required.");
  88. }
  89. //>>includeEnd('debug');
  90. if (!defaultValue.defined(warnings[identifier])) {
  91. warnings[identifier] = true;
  92. console.warn(defaultValue.defaultValue(message, identifier));
  93. }
  94. }
  95. oneTimeWarning.geometryOutlines =
  96. "Entity geometry outlines are unsupported on terrain. Outlines will be disabled. To enable outlines, disable geometry terrain clamping by explicitly setting height to 0.";
  97. oneTimeWarning.geometryZIndex =
  98. "Entity geometry with zIndex are unsupported when height or extrudedHeight are defined. zIndex will be ignored";
  99. oneTimeWarning.geometryHeightReference =
  100. "Entity corridor, ellipse, polygon or rectangle with heightReference must also have a defined height. heightReference will be ignored";
  101. oneTimeWarning.geometryExtrudedHeightReference =
  102. "Entity corridor, ellipse, polygon or rectangle with extrudedHeightReference must also have a defined extrudedHeight. extrudedHeightReference will be ignored";
  103. const scratch2Array = [new Matrix2.Cartesian3(), new Matrix2.Cartesian3()];
  104. const scratchCartesian1 = new Matrix2.Cartesian3();
  105. const scratchCartesian2 = new Matrix2.Cartesian3();
  106. const scratchCartesian3 = new Matrix2.Cartesian3();
  107. const scratchCartesian4 = new Matrix2.Cartesian3();
  108. const scratchCartesian5 = new Matrix2.Cartesian3();
  109. const scratchCartesian6 = new Matrix2.Cartesian3();
  110. const scratchCartesian7 = new Matrix2.Cartesian3();
  111. const scratchCartesian8 = new Matrix2.Cartesian3();
  112. const scratchCartesian9 = new Matrix2.Cartesian3();
  113. const scratch1 = new Matrix2.Cartesian3();
  114. const scratch2 = new Matrix2.Cartesian3();
  115. /**
  116. * @private
  117. */
  118. const PolylineVolumeGeometryLibrary = {};
  119. let cartographic = new Matrix2.Cartographic();
  120. function scaleToSurface(positions, ellipsoid) {
  121. const heights = new Array(positions.length);
  122. for (let i = 0; i < positions.length; i++) {
  123. const pos = positions[i];
  124. cartographic = ellipsoid.cartesianToCartographic(pos, cartographic);
  125. heights[i] = cartographic.height;
  126. positions[i] = ellipsoid.scaleToGeodeticSurface(pos, pos);
  127. }
  128. return heights;
  129. }
  130. function subdivideHeights(points, h0, h1, granularity) {
  131. const p0 = points[0];
  132. const p1 = points[1];
  133. const angleBetween = Matrix2.Cartesian3.angleBetween(p0, p1);
  134. const numPoints = Math.ceil(angleBetween / granularity);
  135. const heights = new Array(numPoints);
  136. let i;
  137. if (h0 === h1) {
  138. for (i = 0; i < numPoints; i++) {
  139. heights[i] = h0;
  140. }
  141. heights.push(h1);
  142. return heights;
  143. }
  144. const dHeight = h1 - h0;
  145. const heightPerVertex = dHeight / numPoints;
  146. for (i = 1; i < numPoints; i++) {
  147. const h = h0 + i * heightPerVertex;
  148. heights[i] = h;
  149. }
  150. heights[0] = h0;
  151. heights.push(h1);
  152. return heights;
  153. }
  154. const nextScratch = new Matrix2.Cartesian3();
  155. const prevScratch = new Matrix2.Cartesian3();
  156. function computeRotationAngle(start, end, position, ellipsoid) {
  157. const tangentPlane = new EllipsoidTangentPlane.EllipsoidTangentPlane(position, ellipsoid);
  158. const next = tangentPlane.projectPointOntoPlane(
  159. Matrix2.Cartesian3.add(position, start, nextScratch),
  160. nextScratch
  161. );
  162. const prev = tangentPlane.projectPointOntoPlane(
  163. Matrix2.Cartesian3.add(position, end, prevScratch),
  164. prevScratch
  165. );
  166. const angle = Matrix2.Cartesian2.angleBetween(next, prev);
  167. return prev.x * next.y - prev.y * next.x >= 0.0 ? -angle : angle;
  168. }
  169. const negativeX = new Matrix2.Cartesian3(-1, 0, 0);
  170. let transform = new Matrix2.Matrix4();
  171. const translation = new Matrix2.Matrix4();
  172. let rotationZ = new Matrix2.Matrix3();
  173. const scaleMatrix = Matrix2.Matrix3.IDENTITY.clone();
  174. const westScratch = new Matrix2.Cartesian3();
  175. const finalPosScratch = new Matrix2.Cartesian4();
  176. const heightCartesian = new Matrix2.Cartesian3();
  177. function addPosition(
  178. center,
  179. left,
  180. shape,
  181. finalPositions,
  182. ellipsoid,
  183. height,
  184. xScalar,
  185. repeat
  186. ) {
  187. let west = westScratch;
  188. let finalPosition = finalPosScratch;
  189. transform = Transforms.Transforms.eastNorthUpToFixedFrame(center, ellipsoid, transform);
  190. west = Matrix2.Matrix4.multiplyByPointAsVector(transform, negativeX, west);
  191. west = Matrix2.Cartesian3.normalize(west, west);
  192. const angle = computeRotationAngle(west, left, center, ellipsoid);
  193. rotationZ = Matrix2.Matrix3.fromRotationZ(angle, rotationZ);
  194. heightCartesian.z = height;
  195. transform = Matrix2.Matrix4.multiplyTransformation(
  196. transform,
  197. Matrix2.Matrix4.fromRotationTranslation(rotationZ, heightCartesian, translation),
  198. transform
  199. );
  200. const scale = scaleMatrix;
  201. scale[0] = xScalar;
  202. for (let j = 0; j < repeat; j++) {
  203. for (let i = 0; i < shape.length; i += 3) {
  204. finalPosition = Matrix2.Cartesian3.fromArray(shape, i, finalPosition);
  205. finalPosition = Matrix2.Matrix3.multiplyByVector(
  206. scale,
  207. finalPosition,
  208. finalPosition
  209. );
  210. finalPosition = Matrix2.Matrix4.multiplyByPoint(
  211. transform,
  212. finalPosition,
  213. finalPosition
  214. );
  215. finalPositions.push(finalPosition.x, finalPosition.y, finalPosition.z);
  216. }
  217. }
  218. return finalPositions;
  219. }
  220. const centerScratch = new Matrix2.Cartesian3();
  221. function addPositions(
  222. centers,
  223. left,
  224. shape,
  225. finalPositions,
  226. ellipsoid,
  227. heights,
  228. xScalar
  229. ) {
  230. for (let i = 0; i < centers.length; i += 3) {
  231. const center = Matrix2.Cartesian3.fromArray(centers, i, centerScratch);
  232. finalPositions = addPosition(
  233. center,
  234. left,
  235. shape,
  236. finalPositions,
  237. ellipsoid,
  238. heights[i / 3],
  239. xScalar,
  240. 1
  241. );
  242. }
  243. return finalPositions;
  244. }
  245. function convertShapeTo3DDuplicate(shape2D, boundingRectangle) {
  246. //orientate 2D shape to XZ plane center at (0, 0, 0), duplicate points
  247. const length = shape2D.length;
  248. const shape = new Array(length * 6);
  249. let index = 0;
  250. const xOffset = boundingRectangle.x + boundingRectangle.width / 2;
  251. const yOffset = boundingRectangle.y + boundingRectangle.height / 2;
  252. let point = shape2D[0];
  253. shape[index++] = point.x - xOffset;
  254. shape[index++] = 0.0;
  255. shape[index++] = point.y - yOffset;
  256. for (let i = 1; i < length; i++) {
  257. point = shape2D[i];
  258. const x = point.x - xOffset;
  259. const z = point.y - yOffset;
  260. shape[index++] = x;
  261. shape[index++] = 0.0;
  262. shape[index++] = z;
  263. shape[index++] = x;
  264. shape[index++] = 0.0;
  265. shape[index++] = z;
  266. }
  267. point = shape2D[0];
  268. shape[index++] = point.x - xOffset;
  269. shape[index++] = 0.0;
  270. shape[index++] = point.y - yOffset;
  271. return shape;
  272. }
  273. function convertShapeTo3D(shape2D, boundingRectangle) {
  274. //orientate 2D shape to XZ plane center at (0, 0, 0)
  275. const length = shape2D.length;
  276. const shape = new Array(length * 3);
  277. let index = 0;
  278. const xOffset = boundingRectangle.x + boundingRectangle.width / 2;
  279. const yOffset = boundingRectangle.y + boundingRectangle.height / 2;
  280. for (let i = 0; i < length; i++) {
  281. shape[index++] = shape2D[i].x - xOffset;
  282. shape[index++] = 0;
  283. shape[index++] = shape2D[i].y - yOffset;
  284. }
  285. return shape;
  286. }
  287. const quaterion = new Transforms.Quaternion();
  288. const startPointScratch = new Matrix2.Cartesian3();
  289. const rotMatrix = new Matrix2.Matrix3();
  290. function computeRoundCorner(
  291. pivot,
  292. startPoint,
  293. endPoint,
  294. cornerType,
  295. leftIsOutside,
  296. ellipsoid,
  297. finalPositions,
  298. shape,
  299. height,
  300. duplicatePoints
  301. ) {
  302. const angle = Matrix2.Cartesian3.angleBetween(
  303. Matrix2.Cartesian3.subtract(startPoint, pivot, scratch1),
  304. Matrix2.Cartesian3.subtract(endPoint, pivot, scratch2)
  305. );
  306. const granularity =
  307. cornerType === CornerType$1.BEVELED
  308. ? 0
  309. : Math.ceil(angle / ComponentDatatype.CesiumMath.toRadians(5));
  310. let m;
  311. if (leftIsOutside) {
  312. m = Matrix2.Matrix3.fromQuaternion(
  313. Transforms.Quaternion.fromAxisAngle(
  314. Matrix2.Cartesian3.negate(pivot, scratch1),
  315. angle / (granularity + 1),
  316. quaterion
  317. ),
  318. rotMatrix
  319. );
  320. } else {
  321. m = Matrix2.Matrix3.fromQuaternion(
  322. Transforms.Quaternion.fromAxisAngle(pivot, angle / (granularity + 1), quaterion),
  323. rotMatrix
  324. );
  325. }
  326. let left;
  327. let surfacePoint;
  328. startPoint = Matrix2.Cartesian3.clone(startPoint, startPointScratch);
  329. if (granularity > 0) {
  330. const repeat = duplicatePoints ? 2 : 1;
  331. for (let i = 0; i < granularity; i++) {
  332. startPoint = Matrix2.Matrix3.multiplyByVector(m, startPoint, startPoint);
  333. left = Matrix2.Cartesian3.subtract(startPoint, pivot, scratch1);
  334. left = Matrix2.Cartesian3.normalize(left, left);
  335. if (!leftIsOutside) {
  336. left = Matrix2.Cartesian3.negate(left, left);
  337. }
  338. surfacePoint = ellipsoid.scaleToGeodeticSurface(startPoint, scratch2);
  339. finalPositions = addPosition(
  340. surfacePoint,
  341. left,
  342. shape,
  343. finalPositions,
  344. ellipsoid,
  345. height,
  346. 1,
  347. repeat
  348. );
  349. }
  350. } else {
  351. left = Matrix2.Cartesian3.subtract(startPoint, pivot, scratch1);
  352. left = Matrix2.Cartesian3.normalize(left, left);
  353. if (!leftIsOutside) {
  354. left = Matrix2.Cartesian3.negate(left, left);
  355. }
  356. surfacePoint = ellipsoid.scaleToGeodeticSurface(startPoint, scratch2);
  357. finalPositions = addPosition(
  358. surfacePoint,
  359. left,
  360. shape,
  361. finalPositions,
  362. ellipsoid,
  363. height,
  364. 1,
  365. 1
  366. );
  367. endPoint = Matrix2.Cartesian3.clone(endPoint, startPointScratch);
  368. left = Matrix2.Cartesian3.subtract(endPoint, pivot, scratch1);
  369. left = Matrix2.Cartesian3.normalize(left, left);
  370. if (!leftIsOutside) {
  371. left = Matrix2.Cartesian3.negate(left, left);
  372. }
  373. surfacePoint = ellipsoid.scaleToGeodeticSurface(endPoint, scratch2);
  374. finalPositions = addPosition(
  375. surfacePoint,
  376. left,
  377. shape,
  378. finalPositions,
  379. ellipsoid,
  380. height,
  381. 1,
  382. 1
  383. );
  384. }
  385. return finalPositions;
  386. }
  387. PolylineVolumeGeometryLibrary.removeDuplicatesFromShape = function (
  388. shapePositions
  389. ) {
  390. const length = shapePositions.length;
  391. const cleanedPositions = [];
  392. for (let i0 = length - 1, i1 = 0; i1 < length; i0 = i1++) {
  393. const v0 = shapePositions[i0];
  394. const v1 = shapePositions[i1];
  395. if (!Matrix2.Cartesian2.equals(v0, v1)) {
  396. cleanedPositions.push(v1); // Shallow copy!
  397. }
  398. }
  399. return cleanedPositions;
  400. };
  401. PolylineVolumeGeometryLibrary.angleIsGreaterThanPi = function (
  402. forward,
  403. backward,
  404. position,
  405. ellipsoid
  406. ) {
  407. const tangentPlane = new EllipsoidTangentPlane.EllipsoidTangentPlane(position, ellipsoid);
  408. const next = tangentPlane.projectPointOntoPlane(
  409. Matrix2.Cartesian3.add(position, forward, nextScratch),
  410. nextScratch
  411. );
  412. const prev = tangentPlane.projectPointOntoPlane(
  413. Matrix2.Cartesian3.add(position, backward, prevScratch),
  414. prevScratch
  415. );
  416. return prev.x * next.y - prev.y * next.x >= 0.0;
  417. };
  418. const scratchForwardProjection = new Matrix2.Cartesian3();
  419. const scratchBackwardProjection = new Matrix2.Cartesian3();
  420. PolylineVolumeGeometryLibrary.computePositions = function (
  421. positions,
  422. shape2D,
  423. boundingRectangle,
  424. geometry,
  425. duplicatePoints
  426. ) {
  427. const ellipsoid = geometry._ellipsoid;
  428. const heights = scaleToSurface(positions, ellipsoid);
  429. const granularity = geometry._granularity;
  430. const cornerType = geometry._cornerType;
  431. const shapeForSides = duplicatePoints
  432. ? convertShapeTo3DDuplicate(shape2D, boundingRectangle)
  433. : convertShapeTo3D(shape2D, boundingRectangle);
  434. const shapeForEnds = duplicatePoints
  435. ? convertShapeTo3D(shape2D, boundingRectangle)
  436. : undefined;
  437. const heightOffset = boundingRectangle.height / 2;
  438. const width = boundingRectangle.width / 2;
  439. let length = positions.length;
  440. let finalPositions = [];
  441. let ends = duplicatePoints ? [] : undefined;
  442. let forward = scratchCartesian1;
  443. let backward = scratchCartesian2;
  444. let cornerDirection = scratchCartesian3;
  445. let surfaceNormal = scratchCartesian4;
  446. let pivot = scratchCartesian5;
  447. let start = scratchCartesian6;
  448. let end = scratchCartesian7;
  449. let left = scratchCartesian8;
  450. let previousPosition = scratchCartesian9;
  451. let position = positions[0];
  452. let nextPosition = positions[1];
  453. surfaceNormal = ellipsoid.geodeticSurfaceNormal(position, surfaceNormal);
  454. forward = Matrix2.Cartesian3.subtract(nextPosition, position, forward);
  455. forward = Matrix2.Cartesian3.normalize(forward, forward);
  456. left = Matrix2.Cartesian3.cross(surfaceNormal, forward, left);
  457. left = Matrix2.Cartesian3.normalize(left, left);
  458. let h0 = heights[0];
  459. let h1 = heights[1];
  460. if (duplicatePoints) {
  461. ends = addPosition(
  462. position,
  463. left,
  464. shapeForEnds,
  465. ends,
  466. ellipsoid,
  467. h0 + heightOffset,
  468. 1,
  469. 1
  470. );
  471. }
  472. previousPosition = Matrix2.Cartesian3.clone(position, previousPosition);
  473. position = nextPosition;
  474. backward = Matrix2.Cartesian3.negate(forward, backward);
  475. let subdividedHeights;
  476. let subdividedPositions;
  477. for (let i = 1; i < length - 1; i++) {
  478. const repeat = duplicatePoints ? 2 : 1;
  479. nextPosition = positions[i + 1];
  480. if (position.equals(nextPosition)) {
  481. oneTimeWarning(
  482. "Positions are too close and are considered equivalent with rounding error."
  483. );
  484. continue;
  485. }
  486. forward = Matrix2.Cartesian3.subtract(nextPosition, position, forward);
  487. forward = Matrix2.Cartesian3.normalize(forward, forward);
  488. cornerDirection = Matrix2.Cartesian3.add(forward, backward, cornerDirection);
  489. cornerDirection = Matrix2.Cartesian3.normalize(cornerDirection, cornerDirection);
  490. surfaceNormal = ellipsoid.geodeticSurfaceNormal(position, surfaceNormal);
  491. const forwardProjection = Matrix2.Cartesian3.multiplyByScalar(
  492. surfaceNormal,
  493. Matrix2.Cartesian3.dot(forward, surfaceNormal),
  494. scratchForwardProjection
  495. );
  496. Matrix2.Cartesian3.subtract(forward, forwardProjection, forwardProjection);
  497. Matrix2.Cartesian3.normalize(forwardProjection, forwardProjection);
  498. const backwardProjection = Matrix2.Cartesian3.multiplyByScalar(
  499. surfaceNormal,
  500. Matrix2.Cartesian3.dot(backward, surfaceNormal),
  501. scratchBackwardProjection
  502. );
  503. Matrix2.Cartesian3.subtract(backward, backwardProjection, backwardProjection);
  504. Matrix2.Cartesian3.normalize(backwardProjection, backwardProjection);
  505. const doCorner = !ComponentDatatype.CesiumMath.equalsEpsilon(
  506. Math.abs(Matrix2.Cartesian3.dot(forwardProjection, backwardProjection)),
  507. 1.0,
  508. ComponentDatatype.CesiumMath.EPSILON7
  509. );
  510. if (doCorner) {
  511. cornerDirection = Matrix2.Cartesian3.cross(
  512. cornerDirection,
  513. surfaceNormal,
  514. cornerDirection
  515. );
  516. cornerDirection = Matrix2.Cartesian3.cross(
  517. surfaceNormal,
  518. cornerDirection,
  519. cornerDirection
  520. );
  521. cornerDirection = Matrix2.Cartesian3.normalize(cornerDirection, cornerDirection);
  522. const scalar =
  523. 1 /
  524. Math.max(
  525. 0.25,
  526. Matrix2.Cartesian3.magnitude(
  527. Matrix2.Cartesian3.cross(cornerDirection, backward, scratch1)
  528. )
  529. );
  530. const leftIsOutside = PolylineVolumeGeometryLibrary.angleIsGreaterThanPi(
  531. forward,
  532. backward,
  533. position,
  534. ellipsoid
  535. );
  536. if (leftIsOutside) {
  537. pivot = Matrix2.Cartesian3.add(
  538. position,
  539. Matrix2.Cartesian3.multiplyByScalar(
  540. cornerDirection,
  541. scalar * width,
  542. cornerDirection
  543. ),
  544. pivot
  545. );
  546. start = Matrix2.Cartesian3.add(
  547. pivot,
  548. Matrix2.Cartesian3.multiplyByScalar(left, width, start),
  549. start
  550. );
  551. scratch2Array[0] = Matrix2.Cartesian3.clone(previousPosition, scratch2Array[0]);
  552. scratch2Array[1] = Matrix2.Cartesian3.clone(start, scratch2Array[1]);
  553. subdividedHeights = subdivideHeights(
  554. scratch2Array,
  555. h0 + heightOffset,
  556. h1 + heightOffset,
  557. granularity
  558. );
  559. subdividedPositions = PolylinePipeline.PolylinePipeline.generateArc({
  560. positions: scratch2Array,
  561. granularity: granularity,
  562. ellipsoid: ellipsoid,
  563. });
  564. finalPositions = addPositions(
  565. subdividedPositions,
  566. left,
  567. shapeForSides,
  568. finalPositions,
  569. ellipsoid,
  570. subdividedHeights,
  571. 1
  572. );
  573. left = Matrix2.Cartesian3.cross(surfaceNormal, forward, left);
  574. left = Matrix2.Cartesian3.normalize(left, left);
  575. end = Matrix2.Cartesian3.add(
  576. pivot,
  577. Matrix2.Cartesian3.multiplyByScalar(left, width, end),
  578. end
  579. );
  580. if (
  581. cornerType === CornerType$1.ROUNDED ||
  582. cornerType === CornerType$1.BEVELED
  583. ) {
  584. computeRoundCorner(
  585. pivot,
  586. start,
  587. end,
  588. cornerType,
  589. leftIsOutside,
  590. ellipsoid,
  591. finalPositions,
  592. shapeForSides,
  593. h1 + heightOffset,
  594. duplicatePoints
  595. );
  596. } else {
  597. cornerDirection = Matrix2.Cartesian3.negate(cornerDirection, cornerDirection);
  598. finalPositions = addPosition(
  599. position,
  600. cornerDirection,
  601. shapeForSides,
  602. finalPositions,
  603. ellipsoid,
  604. h1 + heightOffset,
  605. scalar,
  606. repeat
  607. );
  608. }
  609. previousPosition = Matrix2.Cartesian3.clone(end, previousPosition);
  610. } else {
  611. pivot = Matrix2.Cartesian3.add(
  612. position,
  613. Matrix2.Cartesian3.multiplyByScalar(
  614. cornerDirection,
  615. scalar * width,
  616. cornerDirection
  617. ),
  618. pivot
  619. );
  620. start = Matrix2.Cartesian3.add(
  621. pivot,
  622. Matrix2.Cartesian3.multiplyByScalar(left, -width, start),
  623. start
  624. );
  625. scratch2Array[0] = Matrix2.Cartesian3.clone(previousPosition, scratch2Array[0]);
  626. scratch2Array[1] = Matrix2.Cartesian3.clone(start, scratch2Array[1]);
  627. subdividedHeights = subdivideHeights(
  628. scratch2Array,
  629. h0 + heightOffset,
  630. h1 + heightOffset,
  631. granularity
  632. );
  633. subdividedPositions = PolylinePipeline.PolylinePipeline.generateArc({
  634. positions: scratch2Array,
  635. granularity: granularity,
  636. ellipsoid: ellipsoid,
  637. });
  638. finalPositions = addPositions(
  639. subdividedPositions,
  640. left,
  641. shapeForSides,
  642. finalPositions,
  643. ellipsoid,
  644. subdividedHeights,
  645. 1
  646. );
  647. left = Matrix2.Cartesian3.cross(surfaceNormal, forward, left);
  648. left = Matrix2.Cartesian3.normalize(left, left);
  649. end = Matrix2.Cartesian3.add(
  650. pivot,
  651. Matrix2.Cartesian3.multiplyByScalar(left, -width, end),
  652. end
  653. );
  654. if (
  655. cornerType === CornerType$1.ROUNDED ||
  656. cornerType === CornerType$1.BEVELED
  657. ) {
  658. computeRoundCorner(
  659. pivot,
  660. start,
  661. end,
  662. cornerType,
  663. leftIsOutside,
  664. ellipsoid,
  665. finalPositions,
  666. shapeForSides,
  667. h1 + heightOffset,
  668. duplicatePoints
  669. );
  670. } else {
  671. finalPositions = addPosition(
  672. position,
  673. cornerDirection,
  674. shapeForSides,
  675. finalPositions,
  676. ellipsoid,
  677. h1 + heightOffset,
  678. scalar,
  679. repeat
  680. );
  681. }
  682. previousPosition = Matrix2.Cartesian3.clone(end, previousPosition);
  683. }
  684. backward = Matrix2.Cartesian3.negate(forward, backward);
  685. } else {
  686. finalPositions = addPosition(
  687. previousPosition,
  688. left,
  689. shapeForSides,
  690. finalPositions,
  691. ellipsoid,
  692. h0 + heightOffset,
  693. 1,
  694. 1
  695. );
  696. previousPosition = position;
  697. }
  698. h0 = h1;
  699. h1 = heights[i + 1];
  700. position = nextPosition;
  701. }
  702. scratch2Array[0] = Matrix2.Cartesian3.clone(previousPosition, scratch2Array[0]);
  703. scratch2Array[1] = Matrix2.Cartesian3.clone(position, scratch2Array[1]);
  704. subdividedHeights = subdivideHeights(
  705. scratch2Array,
  706. h0 + heightOffset,
  707. h1 + heightOffset,
  708. granularity
  709. );
  710. subdividedPositions = PolylinePipeline.PolylinePipeline.generateArc({
  711. positions: scratch2Array,
  712. granularity: granularity,
  713. ellipsoid: ellipsoid,
  714. });
  715. finalPositions = addPositions(
  716. subdividedPositions,
  717. left,
  718. shapeForSides,
  719. finalPositions,
  720. ellipsoid,
  721. subdividedHeights,
  722. 1
  723. );
  724. if (duplicatePoints) {
  725. ends = addPosition(
  726. position,
  727. left,
  728. shapeForEnds,
  729. ends,
  730. ellipsoid,
  731. h1 + heightOffset,
  732. 1,
  733. 1
  734. );
  735. }
  736. length = finalPositions.length;
  737. const posLength = duplicatePoints ? length + ends.length : length;
  738. const combinedPositions = new Float64Array(posLength);
  739. combinedPositions.set(finalPositions);
  740. if (duplicatePoints) {
  741. combinedPositions.set(ends, length);
  742. }
  743. return combinedPositions;
  744. };
  745. exports.CornerType = CornerType$1;
  746. exports.PolylineVolumeGeometryLibrary = PolylineVolumeGeometryLibrary;
  747. exports.oneTimeWarning = oneTimeWarning;
  748. }));
  749. //# sourceMappingURL=PolylineVolumeGeometryLibrary-00b304ef.js.map