UNPKG

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