text: "use strict";
  /**
   * Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
   *
   * @author Alexander Rose <alexander.rose@weirdbyte.de>
   */
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.PlaneRepresentation = exports.PlaneParams = void 0;
  var tslib_1 = require("tslib");
  var param_definition_1 = require("../../../mol-util/param-definition");
  var names_1 = require("../../../mol-util/color/names");
  var representation_1 = require("../representation");
  var representation_2 = require("../../representation");
  var shape_1 = require("../../../mol-model/shape");
  var mesh_1 = require("../../../mol-geo/geometry/mesh/mesh");
  var mesh_builder_1 = require("../../../mol-geo/geometry/mesh/mesh-builder");
  var label_1 = require("../../../mol-theme/label");
  var linear_algebra_1 = require("../../../mol-math/linear-algebra");
  var marker_action_1 = require("../../../mol-util/marker-action");
  var plane_1 = require("../../../mol-geo/primitive/plane");
  var structure_1 = require("../../../mol-model/structure");
  var geometry_1 = require("../../../mol-math/geometry");
  var _PlaneParams = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, mesh_1.Mesh.Params), { color: param_definition_1.ParamDefinition.Color(names_1.ColorNames.orange), scaleFactor: param_definition_1.ParamDefinition.Numeric(1, { min: 0.1, max: 10, step: 0.1 }) });
  var PlaneVisuals = {
      'plane': function (ctx, getParams) { return (0, representation_1.ShapeRepresentation)(getPlaneShape, mesh_1.Mesh.Utils); },
  };
  exports.PlaneParams = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, _PlaneParams), { visuals: param_definition_1.ParamDefinition.MultiSelect(['plane'], param_definition_1.ParamDefinition.objectToOptions(PlaneVisuals)) });
  //
  function getPlaneName(locis) {
      var label = (0, label_1.structureElementLociLabelMany)(locis, { countsOnly: true });
      return "Best Fit Plane of ".concat(label);
  }
  var tmpMat = (0, linear_algebra_1.Mat4)();
  var tmpV = (0, linear_algebra_1.Vec3)();
  function buildPlaneMesh(data, props, mesh) {
      var state = mesh_builder_1.MeshBuilder.createState(256, 128, mesh);
      var principalAxes = structure_1.StructureElement.Loci.getPrincipalAxesMany(data.locis);
      var axes = principalAxes.boxAxes;
      var plane = (0, plane_1.Plane)();
      linear_algebra_1.Vec3.add(tmpV, axes.origin, axes.dirC);
      linear_algebra_1.Mat4.targetTo(tmpMat, tmpV, axes.origin, axes.dirB);
      linear_algebra_1.Mat4.scale(tmpMat, tmpMat, geometry_1.Axes3D.size(tmpV, axes));
      linear_algebra_1.Mat4.scaleUniformly(tmpMat, tmpMat, props.scaleFactor);
      linear_algebra_1.Mat4.setTranslation(tmpMat, axes.origin);
      state.currentGroup = 0;
      mesh_builder_1.MeshBuilder.addPrimitive(state, tmpMat, plane);
      mesh_builder_1.MeshBuilder.addPrimitiveFlipped(state, tmpMat, plane);
      return mesh_builder_1.MeshBuilder.getMesh(state);
  }
  function getPlaneShape(ctx, data, props, shape) {
      var mesh = buildPlaneMesh(data, props, shape && shape.geometry);
      var name = getPlaneName(data.locis);
      return shape_1.Shape.create(name, data, mesh, function () { return props.color; }, function () { return 1; }, function () { return name; });
  }
  function PlaneRepresentation(ctx, getParams) {
      var repr = representation_2.Representation.createMulti('Plane', ctx, getParams, representation_2.Representation.StateBuilder, PlaneVisuals);
      repr.setState({ markerActions: marker_action_1.MarkerActions.Highlighting });
      return repr;
  }
  exports.PlaneRepresentation = PlaneRepresentation;
  //# sourceMappingURL=plane.js.map