/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
'use strict';

var queries = require('./queries-H2G-7sak.js');
var controller = require('./controller-Bdoxn5mz.js');
var row = require('./row-Cet6xXup.js');
var types = require('./types-UbZMN9nQ.js');
var cursors = require('./cursors-BjfBRMe4.js');
var entities$1 = require('./entities-C1pFrpRu.js');
var model = require('./model-CNYtD2Ho.js');
var overlays = require('./overlays-CxiJArpE.js');
var results = require('./results-BDTeOJrm.js');
var bundle = require('./bundle-BhTmftd-.js');
var controller$1 = require('./controller--9H9sVbo.js');
var util = require('./util-DVmfE0QI.js');
var streamAttributes = require('./streamAttributes-ce88H9XR.js');
var entities = require('./entities-BhIrCJqA.js');
var markup = require('./markup-BqWReWlC.js');
var viewport = require('./viewport-ZSVJIQTY.js');
var model$1 = require('./model-DPwH082N.js');
require('./bundle-96sYCpzz.js');
require('./_commonjsHelpers-CBbBosIU.js');
require('./errors-C-mfaQwO.js');
require('./wrappers_pb-DCb8h8QZ.js');
require('./representation_pb-BLtsGtEC.js');
require('./wrappers_pb-Dupo3Hcb.js');
require('./grpc-BsWFEUrc.js');
require('./bundle-Dsc8KJRQ.js');
require('./geometry_pb-C1IfJb14.js');

const ALMOST_ONE = 0.9999;
/**
 * For any single normal vector, there are an infinite number of potential orthogonal vectors. This function will
 * calculate a single vector evaluating the length of two candidates, and picking the one with the higher squared magnitude
 * @param normal
 * @returns
 */
function calculateOrthogonalCoordinate(norm) {
    const orthogonalCandidate0 = bundle.vector3.create(0, norm.z, -norm.y);
    const orthogonalCandidate1 = bundle.vector3.create(-norm.z, 0, norm.x);
    const theChosenOne = bundle.vector3.magnitudeSquared(orthogonalCandidate0) >
        bundle.vector3.magnitudeSquared(orthogonalCandidate1)
        ? orthogonalCandidate0
        : orthogonalCandidate1;
    return bundle.vector3.normalize(bundle.vector3.cross(norm, theChosenOne));
}
/**
 * Computes the rotation matrix for two normals. If both normals are neither parallel nor anti-parallel,
 * this will compute the rotation matrix delta based on the angle from both normals.
 * If the normals are anti-parallel, the identity matrix will be returned, as no rotation is necessary in this case.
 * If the normals are parallel, an axis direction based on a chosen orthogonal vector will be used
 * to compute the rotation matrix to rotate the plane 180 degrees.
 * @param normal1
 * @param normal2
 * @returns an anti-parallel rotation Matrix4 between the given normals
 */
function computeRotationMatrix(normal1, normal2) {
    const dot = bundle.vector3.dot(normal1, normal2);
    // the angle is almost 0 in this case.
    if (dot > ALMOST_ONE) {
        const axisDirection = calculateOrthogonalCoordinate(normal1);
        const quaternion = bundle.quaternion.fromAxisAngle(axisDirection, Math.PI);
        return bundle.matrix4.makeRotation(quaternion);
    }
    // the angle is almost 180 in this case.
    else if (dot <= -ALMOST_ONE) {
        return bundle.matrix4.makeIdentity();
    }
    // the angle is between 0 & 180
    else {
        const angle = bundle.vector3.angleTo(normal2, normal1);
        const axisDirection = bundle.vector3.normalize(bundle.vector3.cross(normal1, normal2));
        return bundle.matrix4.makeRotation(bundle.quaternion.fromAxisAngle(axisDirection, angle + Math.PI));
    }
}
/**
 * Computes the translation & rotation matrix delta between two world positions and two normals.
 * such that the computed translation matrix will be the delta between position 1 and position 2,
 * and the rotation will be rotated to be anti-parallel.
 *
 * @param normal1
 * @param position1
 * @param normal2
 * @param position2
 *
 * @returns Matrix4 translation matrix delta from position1 to
 * position2 & an anti-parallel rotation delta.
 */
function computeTransformationDelta(normal1, position1, normal2, position2) {
    const rotationMatrix = computeRotationMatrix(normal1, normal2);
    const translationDeltaMatrix = bundle.matrix4.makeTranslation(position2);
    return bundle.matrix4.multiply(bundle.matrix4.multiply(translationDeltaMatrix, rotationMatrix), bundle.matrix4.makeTranslation(bundle.vector3.negate(position1)));
}

var transformationDelta = /*#__PURE__*/Object.freeze({
    __proto__: null,
    ALMOST_ONE: ALMOST_ONE,
    calculateOrthogonalCoordinate: calculateOrthogonalCoordinate,
    computeRotationMatrix: computeRotationMatrix,
    computeTransformationDelta: computeTransformationDelta
});

exports.Camera = queries.Camera;
exports.ColorMaterial = queries.colorMaterial;
exports.CrossSectioner = queries.CrossSectioner;
exports.ItemOperationBuilder = queries.ItemOperationBuilder;
exports.LoadableResource = queries.loadableResource;
exports.ModelViewController = queries.ModelViewController;
exports.PmiAnnotationOperationsBuilder = queries.PmiAnnotationOperationsBuilder;
exports.PmiAnnotationsQueryExecutor = queries.PmiAnnotationsQueryExecutor;
exports.PmiController = queries.PmiController;
exports.Raycaster = queries.Raycaster;
exports.RootQuery = queries.RootQuery;
exports.Scene = queries.Scene;
exports.SceneElementQueryExecutor = queries.SceneElementQueryExecutor;
exports.SceneElementsOperationExecutor = queries.SceneElementsOperationExecutor;
exports.SceneItemOperationsBuilder = queries.SceneItemOperationsBuilder;
exports.SceneItemQueryExecutor = queries.SceneItemQueryExecutor;
exports.SceneItemsOperationExecutor = queries.SceneItemsOperationExecutor;
exports.SceneViewStateIdentifier = queries.sceneViewStateIdentifier;
exports.SynchronizedClock = queries.SynchronizedClock;
exports.SceneTreeController = controller.SceneTreeController;
exports.fromNodeProto = row.fromNodeProto;
exports.isLoadedRow = row.isLoadedRow;
exports.SCENE_ITEM_NAME_METADATA_KEY = types.SCENE_ITEM_NAME_METADATA_KEY;
exports.CursorManager = cursors.CursorManager;
exports.boxQueryCursor = cursors.boxQueryCursor;
exports.labelPinCursor = cursors.labelPinCursor;
exports.measurementCursor = cursors.measurementCursor;
exports.measurementWithArrowCursor = cursors.measurementWithArrowCursor;
exports.pinCursor = cursors.pinCursor;
exports.MeasurementController = entities$1.MeasurementController;
exports.MeasurementEntity = entities$1.MeasurementEntity;
exports.MeasurementModel = model.MeasurementModel;
exports.MeasurementOverlayManager = overlays.MeasurementOverlayManager;
exports.makeMinimumDistanceResult = results.makeMinimumDistanceResult;
exports.TransformController = controller$1.TransformController;
exports.flattenPointArray = util.flattenPointArray;
exports.toDegreesTransform = util.toDegreesTransform;
exports.toLocalTransform = util.toLocalTransform;
exports.toMatrix = util.toMatrix;
exports.toRadiansTransform = util.toRadiansTransform;
exports.toTransform = util.toTransform;
exports.toWorldTransform = util.toWorldTransform;
exports.AngleUnits = streamAttributes.AngleUnits;
exports.AreaUnits = streamAttributes.AreaUnits;
exports.CrossSectioning = streamAttributes.crossSectioning;
exports.DistanceUnits = streamAttributes.DistanceUnits;
exports.FrameCameraBase = streamAttributes.FrameCameraBase;
exports.Orientation = streamAttributes.Orientation;
exports.ReceivedFrame = streamAttributes.Frame;
exports.ReceivedFrameImage = streamAttributes.FrameImage;
exports.ReceivedFrameScene = streamAttributes.FrameScene;
exports.ReceivedOrthographicCamera = streamAttributes.FrameOrthographicCamera;
exports.ReceivedPerspectiveCamera = streamAttributes.FramePerspectiveCamera;
exports.StandardView = streamAttributes.StandardView;
Object.defineProperty(exports, "EntityType", {
    enumerable: true,
    get: function () { return entities.EntityType; }
});
exports.ArrowMarkup = markup.ArrowMarkup;
exports.CircleMarkup = markup.CircleMarkup;
exports.FreeformMarkup = markup.FreeformMarkup;
exports.Viewport = viewport.Viewport;
exports.VolumeIntersectionQueryController = model$1.VolumeIntersectionQueryController;
exports.VolumeIntersectionQueryModel = model$1.VolumeIntersectionQueryModel;
exports.TransformationDelta = transformationDelta;
//# sourceMappingURL=index.cjs.js.map

//# sourceMappingURL=index.cjs.js.map