vendor: 4,904 bytes, lines 1-191
1import withAccessors from '../mixins/with-accessors'; 2import HasObservers from '../core/has-observers'; 3import { defined, MIN_NUM, MAX_NUM, round } from '../util'; 4import Matrix from './matrix'; 5import toMatrix from './to-matrix'; 6 7 8var Point = (function (superclass) { 9 function Point(x, y) { 10 superclass.call(this); 11 12 this.x = x || 0; 13 this.y = y || 0; 14 } 15 16 if ( superclass ) Point.__proto__ = superclass; 17 Point.prototype = Object.create( superclass && superclass.prototype ); 18 Point.prototype.constructor = Point; 19 20 var staticAccessors = { ZERO: { configurable: true } }; 21 22 Point.prototype.equals = function equals (other) { 23 return other && other.x === this.x && other.y === this.y; 24 }; 25 26 Point.prototype.clone = function clone () { 27 return new Point(this.x, this.y); 28 }; 29 30 Point.prototype.rotate = function rotate (angle, origin) { 31 var originPoint = Point.create(origin) || Point.ZERO; 32 33 return this.transform(Matrix.rotate(angle, originPoint.x, originPoint.y)); 34 }; 35 36 Point.prototype.translate = function translate (x, y) { 37 this.x += x; 38 this.y += y; 39 40 this.geometryChange(); 41 42 return this; 43 }; 44 45 Point.prototype.translateWith = function translateWith (point) { 46 return this.translate(point.x, point.y); 47 }; 48 49 Point.prototype.move = function move (x, y) { 50 this.x = this.y = 0; 51 return this.translate(x, y); 52 }; 53 54 Point.prototype.scale = function scale (scaleX, scaleY) { 55 if ( scaleY === void 0 ) scaleY = scaleX; 56 57 this.x *= scaleX; 58 this.y *= scaleY; 59 60 this.geometryChange(); 61 62 return this; 63 }; 64 65 Point.prototype.scaleCopy = function scaleCopy (scaleX, scaleY) { 66 return this.clone().scale(scaleX, scaleY); 67 }; 68 69 Point.prototype.transform = function transform (transformation) { 70 var matrix = toMatrix(transformation); 71 var ref = this; 72 var x = ref.x; 73 var y = ref.y; 74 75 this.x = matrix.a * x + matrix.c * y + matrix.e; 76 this.y = matrix.b * x + matrix.d * y + matrix.f; 77 78 this.geometryChange(); 79 80 return this; 81 }; 82 83 Point.prototype.transformCopy = function transformCopy (transformation) { 84 var point = this.clone(); 85 86 if (transformation) { 87 point.transform(transformation); 88 } 89 90 return point; 91 }; 92 93 Point.prototype.distanceTo = function distanceTo (point) { 94 var dx = this.x - point.x; 95 var dy = this.y - point.y; 96 97 return Math.sqrt(dx * dx + dy * dy); 98 }; 99 100 Point.prototype.round = function round$1 (digits) { 101 this.x = round(this.x, digits); 102 this.y = round(this.y, digits); 103 104 this.geometryChange(); 105 106 return this; 107 }; 108 109 Point.prototype.toArray = function toArray (digits) { 110 var doRound = defined(digits); 111 var x = doRound ? round(this.x, digits) : this.x; 112 var y = doRound ? round(this.y, digits) : this.y; 113 114 return [ x, y ]; 115 }; 116 117 Point.prototype.toString = function toString (digits, separator) { 118 if ( separator === void 0 ) separator = " "; 119 120 var ref = this; 121 var x = ref.x; 122 var y = ref.y; 123 124 if (defined(digits)) { 125 x = round(x, digits); 126 y = round(y, digits); 127 } 128 129 return x + separator + y; 130 }; 131 132 Point.create = function create (arg0, arg1) { 133 if (defined(arg0)) { 134 if (arg0 instanceof Point) { 135 return arg0; 136 } else if (arguments.length === 1 && arg0.length === 2) { 137 return new Point(arg0[0], arg0[1]); 138 } 139 140 return new Point(arg0, arg1); 141 } 142 }; 143 144 Point.min = function min () { 145 var arguments$1 = arguments; 146 147 var minX = MAX_NUM; 148 var minY = MAX_NUM; 149 150 for (var i = 0; i < arguments.length; i++) { 151 var point = arguments$1[i]; 152 minX = Math.min(point.x, minX); 153 minY = Math.min(point.y, minY); 154 } 155 156 return new Point(minX, minY); 157 }; 158 159 Point.max = function max () { 160 var arguments$1 = arguments; 161 162 var maxX = MIN_NUM; 163 var maxY = MIN_NUM; 164 165 for (var i = 0; i < arguments.length; i++) { 166 var point = arguments$1[i]; 167 maxX = Math.max(point.x, maxX); 168 maxY = Math.max(point.y, maxY); 169 } 170 171 return new Point(maxX, maxY); 172 }; 173 174 Point.minPoint = function minPoint () { 175 return new Point(MIN_NUM, MIN_NUM); 176 }; 177 178 Point.maxPoint = function maxPoint () { 179 return new Point(MAX_NUM, MAX_NUM); 180 }; 181 182 staticAccessors.ZERO.get = function () { 183 return new Point(0, 0); 184 }; 185 186 Object.defineProperties( Point, staticAccessors ); 187 188 return Point; 189}(withAccessors(HasObservers, [ "x", "y" ]))); 190 191export default Point;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.