"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(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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(arr) { if (Array.isArray(arr)) return arr; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(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 _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var CollisionAnalysis = exports["default"] = /*#__PURE__*/function (_AnalysisLayer) {
  _inherits(CollisionAnalysis, _AnalysisLayer);
  var _super = _createSuper(CollisionAnalysis);
  function CollisionAnalysis(props) {
    var _this;
    _classCallCheck(this, CollisionAnalysis);
    _this = _super.call(this, props);
    _this.map = props.map;
    _this.key = 'CollisionAnalysis'; // 相应的分析标识
    return _this;
  }
  _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: horizontalDistance,
        verticalDistance: verticalDistance
      };
    }
  }, {
    key: "getFeatureData",
    value: function getFeatureData(feature, key, callBack) {
      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
      }, values), dataJson);
    }
  }]);
  return CollisionAnalysis;
}(_analysisLayer["default"]);
//# sourceMappingURL=CollisionAnalysis.js.map
