Home Reference Source

src/octree/world/WorldOctantId.js

  1. /**
  2. * A world octant identifier.
  3. *
  4. * Each octant can be identified by a LOD index and a positional key.
  5. */
  6.  
  7. export class WorldOctantId {
  8.  
  9. /**
  10. * Constructs a new world octant identifier.
  11. *
  12. * @param {Number} [lod=0] - The LOD index.
  13. * @param {Number} [key=0] - The key.
  14. */
  15.  
  16. constructor(lod = 0, key = 0) {
  17.  
  18. /**
  19. * The LOD grid in which the world octant resides.
  20. *
  21. * @type {Number}
  22. */
  23.  
  24. this.lod = lod;
  25.  
  26. /**
  27. * The unique key of the world octant.
  28. *
  29. * @type {Number}
  30. */
  31.  
  32. this.key = key;
  33.  
  34. }
  35.  
  36. /**
  37. * Sets the LOD index and key.
  38. *
  39. * @param {Number} lod - The LOD index.
  40. * @param {Number} key - The key.
  41. * @return {WorldOctantId} This octant identifier.
  42. */
  43.  
  44. set(lod, key) {
  45.  
  46. this.lod = lod;
  47. this.key = key;
  48.  
  49. }
  50.  
  51. /**
  52. * Copies the given octant identifier.
  53. *
  54. * @param {WorldOctantId} id - An octant identifier.
  55. * @return {WorldOctantId} This octant identifier.
  56. */
  57.  
  58. copy(id) {
  59.  
  60. this.lod = id.lod;
  61. this.key = id.key;
  62.  
  63. return this;
  64.  
  65. }
  66.  
  67. /**
  68. * Clones this octant identifier.
  69. *
  70. * @return {WorldOctantId} The cloned octant identifier.
  71. */
  72.  
  73. clone() {
  74.  
  75. return new this.constructor().copy(this);
  76.  
  77. }
  78.  
  79. }