modeling_vertex.js

import oc from "../opencascade/initializer";
import cachedGetters from "../utils/cache";
import {Vector} from "../math";

/**
 * Represents a vertex in 3D space.
 * @memberof modeling
 * @alias Vertex
 */
export class Vertex {
  #wrapped;
  #point;

  /**
   * @hideconstructor
   */
  constructor(wrapped) {
    this.#wrapped = oc.TopoDS.Vertex_1(wrapped);
  }

  /**
   * Returns the wrapped OpenCascade object.
   * @private
   */
  get wrapped() {
    return this.#wrapped;
  }

  /**
   * Retrieves the position of the vertex.
   * @returns {Vector} A `Vector` object representing the vertex's position.
   */
  get position() {
    const point = this.#asPoint();
    return new Vector({x: point.X(), y: point.Y(), z: point.Z()});
  }

  /**
   * Checks if this vertex is equal to another vertex.
   * @param {Vertex} vertex - The vertex to compare with.
   * @returns {boolean} `true` if the vertices are equal, `false` otherwise.
   */
  isEqual(vertex) {
    return this.#wrapped.IsSame(vertex.wrapped);
  }

  #asPoint() {
    if (!this.#point) {
      this.#point = oc.BRep_Tool.Pnt(this.#wrapped);
    }
    return this.#point;
  }
}

cachedGetters({object: Vertex, properties: ["position"]});