1 | ;
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.isPoint = isPoint;
|
9 | exports.Point = void 0;
|
10 |
|
11 | var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
12 |
|
13 | var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
14 |
|
15 | var _util = require("./internal/util");
|
16 |
|
17 | /**
|
18 | * Copyright (c) 2002-2019 "Neo4j,"
|
19 | * Neo4j Sweden AB [http://neo4j.com]
|
20 | *
|
21 | * This file is part of Neo4j.
|
22 | *
|
23 | * Licensed under the Apache License, Version 2.0 (the "License");
|
24 | * you may not use this file except in compliance with the License.
|
25 | * You may obtain a copy of the License at
|
26 | *
|
27 | * http://www.apache.org/licenses/LICENSE-2.0
|
28 | *
|
29 | * Unless required by applicable law or agreed to in writing, software
|
30 | * distributed under the License is distributed on an "AS IS" BASIS,
|
31 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
32 | * See the License for the specific language governing permissions and
|
33 | * limitations under the License.
|
34 | */
|
35 | var POINT_IDENTIFIER_PROPERTY = '__isPoint__';
|
36 | /**
|
37 | * Represents a single two or three-dimensional point in a particular coordinate reference system.
|
38 | * Created `Point` objects are frozen with `Object.freeze()` in constructor and thus immutable.
|
39 | */
|
40 |
|
41 | var Point =
|
42 | /*#__PURE__*/
|
43 | function () {
|
44 | /**
|
45 | * @constructor
|
46 | * @param {Integer|number} srid - The coordinate reference system identifier.
|
47 | * @param {number} x - The `x` coordinate of the point.
|
48 | * @param {number} y - The `y` coordinate of the point.
|
49 | * @param {number} [z=undefined] - The `z` coordinate of the point or `undefined` if point has 2 dimensions.
|
50 | */
|
51 | function Point(srid, x, y, z) {
|
52 | (0, _classCallCheck2["default"])(this, Point);
|
53 |
|
54 | /**
|
55 | * The coordinate reference system identifier.
|
56 | * @type {Integer|number}
|
57 | */
|
58 | this.srid = (0, _util.assertNumberOrInteger)(srid, 'SRID');
|
59 | /**
|
60 | * The `x` coordinate of the point.
|
61 | * @type {number}
|
62 | */
|
63 |
|
64 | this.x = (0, _util.assertNumber)(x, 'X coordinate');
|
65 | /**
|
66 | * The `y` coordinate of the point.
|
67 | * @type {number}
|
68 | */
|
69 |
|
70 | this.y = (0, _util.assertNumber)(y, 'Y coordinate');
|
71 | /**
|
72 | * The `z` coordinate of the point or `undefined` if point is 2-dimensional.
|
73 | * @type {number}
|
74 | */
|
75 |
|
76 | this.z = z === null || z === undefined ? z : (0, _util.assertNumber)(z, 'Z coordinate');
|
77 | Object.freeze(this);
|
78 | }
|
79 | /**
|
80 | * @ignore
|
81 | */
|
82 |
|
83 |
|
84 | (0, _createClass2["default"])(Point, [{
|
85 | key: "toString",
|
86 | value: function toString() {
|
87 | return this.z || this.z === 0 ? "Point{srid=".concat(formatAsFloat(this.srid), ", x=").concat(formatAsFloat(this.x), ", y=").concat(formatAsFloat(this.y), ", z=").concat(formatAsFloat(this.z), "}") : "Point{srid=".concat(formatAsFloat(this.srid), ", x=").concat(formatAsFloat(this.x), ", y=").concat(formatAsFloat(this.y), "}");
|
88 | }
|
89 | }]);
|
90 | return Point;
|
91 | }();
|
92 |
|
93 | exports.Point = Point;
|
94 |
|
95 | function formatAsFloat(number) {
|
96 | return Number.isInteger(number) ? number + '.0' : number.toString();
|
97 | }
|
98 |
|
99 | Object.defineProperty(Point.prototype, POINT_IDENTIFIER_PROPERTY, {
|
100 | value: true,
|
101 | enumerable: false,
|
102 | configurable: false,
|
103 | writable: false
|
104 | });
|
105 | /**
|
106 | * Test if given object is an instance of {@link Point} class.
|
107 | * @param {Object} obj the object to test.
|
108 | * @return {boolean} `true` if given object is a {@link Point}, `false` otherwise.
|
109 | */
|
110 |
|
111 | function isPoint(obj) {
|
112 | return (obj && obj[POINT_IDENTIFIER_PROPERTY]) === true;
|
113 | } |
\ | No newline at end of file |