CoplanarPolygonGeometryLibrary-ecf852df.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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', './RuntimeError-4f8ec8a2', './OrientedBoundingBox-a82b3552'], (function (exports, Matrix2, RuntimeError, OrientedBoundingBox) { 'use strict';
  26. /**
  27. * @private
  28. */
  29. const CoplanarPolygonGeometryLibrary = {};
  30. const scratchIntersectionPoint = new Matrix2.Cartesian3();
  31. const scratchXAxis = new Matrix2.Cartesian3();
  32. const scratchYAxis = new Matrix2.Cartesian3();
  33. const scratchZAxis = new Matrix2.Cartesian3();
  34. const obbScratch = new OrientedBoundingBox.OrientedBoundingBox();
  35. CoplanarPolygonGeometryLibrary.validOutline = function (positions) {
  36. //>>includeStart('debug', pragmas.debug);
  37. RuntimeError.Check.defined("positions", positions);
  38. //>>includeEnd('debug');
  39. const orientedBoundingBox = OrientedBoundingBox.OrientedBoundingBox.fromPoints(
  40. positions,
  41. obbScratch
  42. );
  43. const halfAxes = orientedBoundingBox.halfAxes;
  44. const xAxis = Matrix2.Matrix3.getColumn(halfAxes, 0, scratchXAxis);
  45. const yAxis = Matrix2.Matrix3.getColumn(halfAxes, 1, scratchYAxis);
  46. const zAxis = Matrix2.Matrix3.getColumn(halfAxes, 2, scratchZAxis);
  47. const xMag = Matrix2.Cartesian3.magnitude(xAxis);
  48. const yMag = Matrix2.Cartesian3.magnitude(yAxis);
  49. const zMag = Matrix2.Cartesian3.magnitude(zAxis);
  50. // If all the points are on a line return undefined because we can't draw a polygon
  51. return !(
  52. (xMag === 0 && (yMag === 0 || zMag === 0)) ||
  53. (yMag === 0 && zMag === 0)
  54. );
  55. };
  56. // call after removeDuplicates
  57. CoplanarPolygonGeometryLibrary.computeProjectTo2DArguments = function (
  58. positions,
  59. centerResult,
  60. planeAxis1Result,
  61. planeAxis2Result
  62. ) {
  63. //>>includeStart('debug', pragmas.debug);
  64. RuntimeError.Check.defined("positions", positions);
  65. RuntimeError.Check.defined("centerResult", centerResult);
  66. RuntimeError.Check.defined("planeAxis1Result", planeAxis1Result);
  67. RuntimeError.Check.defined("planeAxis2Result", planeAxis2Result);
  68. //>>includeEnd('debug');
  69. const orientedBoundingBox = OrientedBoundingBox.OrientedBoundingBox.fromPoints(
  70. positions,
  71. obbScratch
  72. );
  73. const halfAxes = orientedBoundingBox.halfAxes;
  74. const xAxis = Matrix2.Matrix3.getColumn(halfAxes, 0, scratchXAxis);
  75. const yAxis = Matrix2.Matrix3.getColumn(halfAxes, 1, scratchYAxis);
  76. const zAxis = Matrix2.Matrix3.getColumn(halfAxes, 2, scratchZAxis);
  77. const xMag = Matrix2.Cartesian3.magnitude(xAxis);
  78. const yMag = Matrix2.Cartesian3.magnitude(yAxis);
  79. const zMag = Matrix2.Cartesian3.magnitude(zAxis);
  80. const min = Math.min(xMag, yMag, zMag);
  81. // If all the points are on a line return undefined because we can't draw a polygon
  82. if (
  83. (xMag === 0 && (yMag === 0 || zMag === 0)) ||
  84. (yMag === 0 && zMag === 0)
  85. ) {
  86. return false;
  87. }
  88. let planeAxis1;
  89. let planeAxis2;
  90. if (min === yMag || min === zMag) {
  91. planeAxis1 = xAxis;
  92. }
  93. if (min === xMag) {
  94. planeAxis1 = yAxis;
  95. } else if (min === zMag) {
  96. planeAxis2 = yAxis;
  97. }
  98. if (min === xMag || min === yMag) {
  99. planeAxis2 = zAxis;
  100. }
  101. Matrix2.Cartesian3.normalize(planeAxis1, planeAxis1Result);
  102. Matrix2.Cartesian3.normalize(planeAxis2, planeAxis2Result);
  103. Matrix2.Cartesian3.clone(orientedBoundingBox.center, centerResult);
  104. return true;
  105. };
  106. function projectTo2D(position, center, axis1, axis2, result) {
  107. const v = Matrix2.Cartesian3.subtract(position, center, scratchIntersectionPoint);
  108. const x = Matrix2.Cartesian3.dot(axis1, v);
  109. const y = Matrix2.Cartesian3.dot(axis2, v);
  110. return Matrix2.Cartesian2.fromElements(x, y, result);
  111. }
  112. CoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction = function (
  113. center,
  114. axis1,
  115. axis2
  116. ) {
  117. return function (positions) {
  118. const positionResults = new Array(positions.length);
  119. for (let i = 0; i < positions.length; i++) {
  120. positionResults[i] = projectTo2D(positions[i], center, axis1, axis2);
  121. }
  122. return positionResults;
  123. };
  124. };
  125. CoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction = function (
  126. center,
  127. axis1,
  128. axis2
  129. ) {
  130. return function (position, result) {
  131. return projectTo2D(position, center, axis1, axis2, result);
  132. };
  133. };
  134. exports.CoplanarPolygonGeometryLibrary = CoplanarPolygonGeometryLibrary;
  135. }));
  136. //# sourceMappingURL=CoplanarPolygonGeometryLibrary-ecf852df.js.map