UNPKG

cg-point

Version:

An object representing a point in a two-dimensional coordinate system.

1 lines 2.13 kB
"use strict";var _applyConstructor=function(t,n){var r=Object.create(t.prototype),e=t.apply(r,n);return null==e||"object"!=typeof e&&"function"!=typeof e?r:e},_toConsumableArray=function(t){if(Array.isArray(t)){for(var n=0,r=Array(t.length);n<t.length;n++)r[n]=t[n];return r}return Array.from(t)},_createClass=function(){function t(t,n){for(var r in n){var e=n[r];e.configurable=!0,e.value&&(e.writable=!0)}Object.defineProperties(t,n)}return function(n,r,e){return r&&t(n.prototype,r),e&&t(n,e),n}}(),_classCallCheck=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},_private=new WeakMap,CGPoint=function(){function t(){var n=void 0===arguments[0]?null:arguments[0],r=void 0===arguments[1]?null:arguments[1];_classCallCheck(this,t),this.x=n,this.y=r,_private.set(this,{x:n,y:r})}return _createClass(t,{_x:{get:function(){return _private.get(this).x},set:function(t){_private.set(this).x=this._cast(t),this.x=this._cast(t)}},_y:{get:function(){return _private.get(this).y},set:function(t){_private.set(this).y=this._cast(t),this.y=this._cast(t)}},isEmpty:{get:function(){var t=0===this._x&&0===this._y;return this.isNull||t}},isInfinite:{get:function(){var t=this._x===1/0||this._x===-(1/0),n=this._y===1/0||this._y===-(1/0);return t&&n}},isNull:{get:function(){return null===this._x&&null===this._y}},integral:{get:function(){var n=Math.floor(this._x),r=Math.floor(this._y);return this.isNull?t["null"]:new t(n,r)}},toString:{value:function(){return"{"+this._x+","+this._y+"}"}},equalTo:{value:function(n,r){if(n instanceof t){var e=this.isNull&&n.isNull,i=this._x===n._x,u=this._y===n._y,o=i&&u;return e||o}throw new TypeError("#equalTo(): Expects argument of type CGPoint")}}},{"null":{get:function(){var n=new t;return n.x=null,n.y=null,n}},zero:{get:function(){return new t(0,0)}},infinite:{get:function(){return new t(1/0,1/0)}},fromString:{value:function(){var n=void 0===arguments[0]?"":arguments[0],r=new RegExp("[-]?\\d+(\\.\\d+)?","g"),e=n.match(r),i=t.zero;if(e){var u=2===e.length;i=u?_applyConstructor(t,_toConsumableArray(e)):t["null"]}return i}}}),t}();module.exports=CGPoint;