智慧水务管理系统 - 精河县供水工程综合管理平台

BufferPoint.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // @ts-check
  2. import BufferPrimitive from "./BufferPrimitive.js";
  3. import Cartesian3 from "../Core/Cartesian3.js";
  4. import assert from "../Core/assert.js";
  5. import BufferPrimitiveCollection from "./BufferPrimitiveCollection.js";
  6. /** @import BufferPointCollection from "./BufferPointCollection.js"; */
  7. const { ERR_CAPACITY } = BufferPrimitiveCollection.Error;
  8. const scratchCartesian = new Cartesian3();
  9. /**
  10. * View bound to the underlying buffer data of a {@link BufferPointCollection}.
  11. *
  12. * <p>BufferPoint instances are {@link https://en.wikipedia.org/wiki/Flyweight_pattern|flyweights}:
  13. * a single BufferPoint instance can be temporarily bound to any conceptual
  14. * "point" in a BufferPointCollection, allowing very large collections to be
  15. * iterated and updated with a minimal memory footprint.</p>
  16. *
  17. * Represented as one (1) position.
  18. *
  19. * @see BufferPointCollection
  20. * @see BufferPointMaterial
  21. * @see BufferPrimitive
  22. * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
  23. * @extends BufferPrimitive
  24. */
  25. class BufferPoint extends BufferPrimitive {
  26. /**
  27. * @type {BufferPointCollection}
  28. * @ignore
  29. */
  30. _collection = null;
  31. /** @ignore */
  32. static Layout = {
  33. ...BufferPrimitive.Layout,
  34. /**
  35. * Offset in position array to current point vertex, number of VEC3 elements.
  36. * @type {number}
  37. * @ignore
  38. */
  39. POSITION_OFFSET_U32: BufferPrimitive.Layout.__BYTE_LENGTH,
  40. /**
  41. * @type {number}
  42. * @ignore
  43. */
  44. __BYTE_LENGTH: BufferPrimitive.Layout.__BYTE_LENGTH + 4,
  45. };
  46. /////////////////////////////////////////////////////////////////////////////
  47. // LIFECYCLE
  48. /**
  49. * Copies data from source point to result.
  50. *
  51. * @param {BufferPoint} point
  52. * @param {BufferPoint} result
  53. * @return {BufferPoint}
  54. * @override
  55. */
  56. static clone(point, result) {
  57. super.clone(point, result);
  58. result.setPosition(point.getPosition(scratchCartesian));
  59. return result;
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // GEOMETRY
  63. /**
  64. * Offset in collection position array to position of this point, number
  65. * of VEC3 elements.
  66. *
  67. * @type {number}
  68. * @readonly
  69. * @ignore
  70. */
  71. get vertexOffset() {
  72. return this._getUint32(BufferPoint.Layout.POSITION_OFFSET_U32);
  73. }
  74. /**
  75. * Count of positions (vertices) in this primitive. Always 1.
  76. *
  77. * @type {number}
  78. * @readonly
  79. */
  80. get vertexCount() {
  81. return 1;
  82. }
  83. /**
  84. * Gets the position of this point.
  85. *
  86. * @param {Cartesian3} [result]
  87. * @returns {Cartesian3}
  88. */
  89. getPosition(result) {
  90. const positionF64 = this._collection._positionView;
  91. // @ts-expect-error TODO(tsd-jsdoc): See https://github.com/CesiumGS/cesium/pull/13302.
  92. return Cartesian3.fromArray(positionF64, this.vertexOffset * 3, result);
  93. }
  94. /**
  95. * Sets the position of this point.
  96. *
  97. * @param {Cartesian3} position
  98. */
  99. setPosition(position) {
  100. const collection = this._collection;
  101. const vertexOffset = this.vertexOffset;
  102. //>>includeStart('debug', pragmas.debug);
  103. assert(vertexOffset < collection.vertexCountMax, ERR_CAPACITY);
  104. //>>includeEnd('debug');
  105. collection._positionView[vertexOffset * 3] = position.x;
  106. collection._positionView[vertexOffset * 3 + 1] = position.y;
  107. collection._positionView[vertexOffset * 3 + 2] = position.z;
  108. this._dirty = true;
  109. collection._makeDirtyBoundingVolume();
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // DEBUG
  113. /**
  114. * Returns a JSON-serializable object representing the point. This encoding
  115. * is not memory-efficient, and should generally be used for debugging and
  116. * testing.
  117. *
  118. * @returns {Object} JSON-serializable object.
  119. * @override
  120. */
  121. toJSON() {
  122. return {
  123. ...super.toJSON(),
  124. position: Cartesian3.pack(this.getPosition(), []),
  125. };
  126. }
  127. }
  128. export default BufferPoint;