UNPKG

@react-native-ohos/realm

Version:

Realm by MongoDB is an offline-first mobile database: an alternative to SQLite and key-value stores

102 lines 3.69 kB
"use strict"; //////////////////////////////////////////////////////////////////////////// // // Copyright 2023 Realm Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //////////////////////////////////////////////////////////////////////////// Object.defineProperty(exports, "__esModule", { value: true }); exports.miToRadians = exports.kmToRadians = exports.polygonToBindingGeospatial = exports.boxToBindingGeospatial = exports.circleToBindingGeospatial = exports.isGeoPolygon = exports.isGeoBox = exports.isGeoCircle = void 0; const binding_1 = require("./binding"); /** @internal */ function isGeoCircle(value) { return "center" in value && "distance" in value && typeof value.distance === "number"; } exports.isGeoCircle = isGeoCircle; /** @internal */ function isGeoBox(value) { return "bottomLeft" in value && "topRight" in value; } exports.isGeoBox = isGeoBox; /** @internal */ function isGeoPolygon(value) { return (("type" in value && value.type === "Polygon" && "coordinates" in value && Array.isArray(value.coordinates)) || ("outerRing" in value && Array.isArray(value.outerRing))); } exports.isGeoPolygon = isGeoPolygon; /** @internal */ function circleToBindingGeospatial(circle) { return binding_1.binding.Geospatial.makeFromCircle({ center: toBindingGeoPoint(circle.center), radiusRadians: circle.distance, }); } exports.circleToBindingGeospatial = circleToBindingGeospatial; /** @internal */ function boxToBindingGeospatial(box) { return binding_1.binding.Geospatial.makeFromBox({ lo: toBindingGeoPoint(box.bottomLeft), hi: toBindingGeoPoint(box.topRight), }); } exports.boxToBindingGeospatial = boxToBindingGeospatial; /** @internal */ function polygonToBindingGeospatial(polygon) { let points; if ("type" in polygon) { points = toBindingGeoPointArray(polygon.coordinates); } else { points = toBindingGeoPointArray([polygon.outerRing].concat(polygon.holes ?? [])); } return binding_1.binding.Geospatial.makeFromPolygon({ points, }); } exports.polygonToBindingGeospatial = polygonToBindingGeospatial; function toBindingGeoPoint(p) { if (Array.isArray(p)) { return { longitude: p[0], latitude: p[1], altitude: p[2] }; } else if ("type" in p) { return { longitude: p.coordinates[0], latitude: p.coordinates[1], altitude: p.coordinates[2] }; } else { return p; } } function toBindingGeoPointArray(arr) { return arr.map((ring) => ring.map((p) => toBindingGeoPoint(p))); } const earthRadiusKm = 6378.1; const earthRadiusMi = 3963.16760121; //earthRadiusKm / 1.609344 (km/mi) /** * Converts the input kilometer value in radians. * @param km - The kilometers to convert. * @returns The corresponding number of radians. */ function kmToRadians(km) { return km / earthRadiusKm; } exports.kmToRadians = kmToRadians; /** * Converts the input miles value in radians. * @param mi - The miles to convert. * @returns The corresponding number of radians. */ function miToRadians(mi) { return mi / earthRadiusMi; } exports.miToRadians = miToRadians; //# sourceMappingURL=GeoSpatial.js.map