import { Vector3 } from "three/src/math/Vector3";
import { CoreGeometryOperationHexagon } from "@polygonjs/polygonjs/dist/src/core/geometry/operation/Hexagon";
import { CoreTransform } from "@polygonjs/polygonjs/dist/src/core/Transform";
const DIR_ORIGIN = new Vector3(0, 1, 0);
const DIR_DEST = new Vector3(0, 0, 1);
export class MapboxPlaneHexagonsController {
  constructor(node) {
    this.node = node;
    this._coreTransform = new CoreTransform();
  }
  geometry(plane_dimensions, segments_counts) {
    const hexagons_radius = Math.max(plane_dimensions.x / segments_counts.x, plane_dimensions.y / segments_counts.y);
    let hexagons_scale_compensate;
    if (!this.node.pv.mapboxTransform) {
      const new_plane_dimensions = {
        x: segments_counts.x * hexagons_radius,
        y: segments_counts.y * hexagons_radius
      };
      hexagons_scale_compensate = new Vector3(1, plane_dimensions.y / new_plane_dimensions.y, 1);
      plane_dimensions.x = new_plane_dimensions.x;
      plane_dimensions.y = new_plane_dimensions.y;
    }
    const operation = new CoreGeometryOperationHexagon(plane_dimensions, hexagons_radius, true);
    const geometry = operation.process();
    this._coreTransform.rotateGeometry(geometry, DIR_ORIGIN, DIR_DEST);
    if (!this.node.pv.mapboxTransform && hexagons_scale_compensate) {
      geometry.scale(hexagons_scale_compensate.x, hexagons_scale_compensate.y, hexagons_scale_compensate.z);
    }
    return geometry;
  }
}
