"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _analysisLayer = _interopRequireDefault(require("@vtx/ol-map/lib/analysis-layer"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
var CollisionAnalysis = exports["default"] = /*#__PURE__*/function (_AnalysisLayer) {
  function CollisionAnalysis(props) {
    var _this;
    _classCallCheck(this, CollisionAnalysis);
    _this = _callSuper(this, CollisionAnalysis, [props]);
    _this.map = props.map;
    _this.key = 'CollisionAnalysis'; // 相应的分析标识
    return _this;
  }
  _inherits(CollisionAnalysis, _AnalysisLayer);
  return _createClass(CollisionAnalysis, [{
    key: "calculateDistances",
    value: function calculateDistances(_ref) {
      var p1 = _ref.p1,
        q1 = _ref.q1,
        p2 = _ref.p2,
        q2 = _ref.q2;
      // 计算两条线的方向向量
      var v1 = [q1[0] - p1[0], q1[1] - p1[1], q1[2] - p1[2]];
      var v2 = [q2[0] - p2[0], q2[1] - p2[1], q2[2] - p2[2]];

      // 计算公垂线向量
      var n = [v1[1] * v2[2] - v1[2] * v2[1], v1[2] * v2[0] - v1[0] * v2[2], v1[0] * v2[1] - v1[1] * v2[0]];

      // 计算公垂线长度
      var length = Math.sqrt(Math.pow(n[0], 2) + Math.pow(n[1], 2) + Math.pow(n[2], 2));

      // 单位化公垂线向量
      var u = [n[0] / length, n[1] / length, n[2] / length];

      // 计算公垂足点
      var dotProduct1 = v1[0] * (p2[0] - p1[0]) + v1[1] * (p2[1] - p1[1]) + v1[2] * (p2[2] - p1[2]);
      var dotProduct2 = v2[0] * (p1[0] - p2[0]) + v2[1] * (p1[1] - p2[1]) + v2[2] * (p1[2] - p2[2]);
      var s = dotProduct1 / (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]);
      var t = dotProduct2 / (v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]);
      var p = [p1[0] + s * v1[0], p1[1] + s * v1[1], p1[2] + s * v1[2]];

      // 计算水平净距和垂直净距
      var q = [p[0] + t * u[0], p[1] + t * u[1], p[2] + t * u[2]];
      var horizontalDistance = Math.min(Math.sqrt(Math.pow(q[0] - q1[0], 2) + Math.pow(q[1] - q1[1], 2) + Math.pow(q[2] - q1[2], 2)), Math.sqrt(Math.pow(q[0] - q2[0], 2) + Math.pow(q[1] - q2[1], 2) + Math.pow(q[2] - q2[2], 2)));
      var verticalDistance = Math.sqrt(Math.pow(p[0] - q[0], 2) + Math.pow(p[1] - q[1], 2) + Math.pow(p[2] - q[2], 2));
      return {
        horizontalDistance: Number.isNaN(horizontalDistance) ? 0 : horizontalDistance,
        verticalDistance: Number.isNaN(verticalDistance) ? 0 : verticalDistance
      };
    }
  }, {
    key: "getFeatureData",
    value: function getFeatureData(feature) {
      var startPointLngLat, endPointLngLat;
      var values = (feature === null || feature === void 0 ? void 0 : feature.getProperties()) || {};
      var dataJson = {};
      if (values !== null && values !== void 0 && values.data_json) dataJson = JSON.parse(values.data_json);
      if (feature) {
        var _feature$getGeometry;
        var _feature$getGeometry$ = feature === null || feature === void 0 || (_feature$getGeometry = feature.getGeometry()) === null || _feature$getGeometry === void 0 ? void 0 : _feature$getGeometry.getCoordinates(),
          _feature$getGeometry$2 = _slicedToArray(_feature$getGeometry$, 2),
          start = _feature$getGeometry$2[0],
          end = _feature$getGeometry$2[1];
        startPointLngLat = start.join(',');
        endPointLngLat = end.join(',');
      }
      return _objectSpread(_objectSpread({
        feature: feature,
        code: values.code,
        startPointLngLat: startPointLngLat,
        endPointLngLat: endPointLngLat,
        startZ: dataJson.start_z,
        endZ: dataJson.end_z
      }, values), dataJson);
    }
  }]);
}(_analysisLayer["default"]);
//# sourceMappingURL=CollisionAnalysis.js.map
