1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | 1× 1× 100× 100× 100× 26× 26× 26× 26× 21× 21× 26× 1× 1× 1× 1× 23× 23× 23× 23× 23× 1× 1× 1× 1× 1× | /** * @module montage/core/geometry/point * @requires montage/core/core */ var Montage = require("../core").Montage; /** * @class Point * @extends Montage */ var Point = exports.Point = Montage.specialize( /** @lends Point# */ { init: { enumerable: false, value: function (x, y) { this.x = x === null ? 0 : x; this.y = y === null ? 0 : y; return this; } }, /** * The x axis point. * @type {number} * @default 0 */ x: { enumerable: true, value: 0 }, /** * The y axis point. * @type {number} * @default 0 */ y: { enumerable: true, value: 0 } }, { /** * Interpolates between two points. * @function * @param {Axis} percent The interpolation percentage. * @param {Axis} point0 The 0 interpolation point. * @param {Axis} point1 The 1 interpolation point. * @param {Axis} precision The interpolation precision. * @returns new Point().init(xValue, yValue) */ interpolate: { enumerable: false, value: function (percent, point0, point1, precision) { var xValue, yValue; xValue = point0.x + (point1.x - point0.x) * percent; yValue = point0.y + (point1.y - point0.y) * percent; if (precision > 0) { xValue = Math.round(xValue * precision) / precision; yValue = Math.round(yValue * precision) / precision; } return new exports.Point().init(xValue, yValue); } } }); var _offsetForElement = function (element) { var boundingClientRect, elementsDocument = element.ownerDocument, elementsDocumentElement, elementsBody, elementsWindow; if ( element && elementsDocument ) { elementsDocumentElement = elementsDocument.documentElement; elementsBody = elementsDocument.body; elementsWindow = elementsDocument.defaultView; if ( element !== elementsBody ) { boundingClientRect = element.getBoundingClientRect(); if ( elementsDocumentElement.parentOf(element) ) { var clientTop = elementsDocumentElement.clientTop || elementsBody.clientTop || 0, clientLeft = elementsDocumentElement.clientLeft || elementsBody.clientLeft || 0, scrollTop = elementsWindow.pageYOffset || elementsDocumentElement.scrollTop || elementsBody.scrollTop, scrollLeft = elementsWindow.pageXOffset || elementsDocumentElement.scrollLeft || elementsBody.scrollLeft, top = boundingClientRect.top + scrollTop - clientTop, left = boundingClientRect.left + scrollLeft - clientLeft; return { top: top, left: left }; } else { return { top: boundingClientRect.top, left: boundingClientRect.left }; } } else { return { top: elementsBody.offsetTop, left: elementsBody.offsetLeft }; } } else { return null; } }; var _webKitPoint = null; var webkitImplementation = function () { Point.convertPointFromNodeToPage = function (element, point) { Iif(point) { _webKitPoint.x = point.x; _webKitPoint.y = point.y; } else { _webKitPoint.x = 0; _webKitPoint.y = 0; } point = webkitConvertPointFromNodeToPage(element, _webKitPoint); return point ? new Point().init(point.x, point.y) : null; }; Point.convertPointFromPageToNode = function (element, point) { if(point) { _webKitPoint.x = point.x; _webKitPoint.y = point.y; } else { _webKitPoint.x = 0; _webKitPoint.y = 0; } point = webkitConvertPointFromPageToNode(element, _webKitPoint); return point ? new Point().init(point.x, point.y) : null; }; }; var shimImplementation = function () { Point.convertPointFromNodeToPage = function (element, point) { if (!element || typeof element.x !== "undefined") { return null; } var offset; if (offset =_offsetForElement(element)) { return new Point().init((point ? point.x:0)+offset.left, (point ? point.y:0)+offset.top); } else { return new Point().init((point ? point.x:0), (point ? point.y:0)); } }; Point.convertPointFromPageToNode = function (element, point) { if (!element || typeof element.x !== "undefined") { return null; } var offset; if (offset =_offsetForElement(element)) { return new Point().init((point ? point.x:0)-offset.left, (point ? point.y:0)-offset.top); } else { return new Point().init((point ? point.x:0), (point ? point.y:0)); } }; }; Eif (typeof WebKitPoint !== "undefined") { _webKitPoint = new WebKitPoint(0,0); webkitImplementation(); } else { shimImplementation(); } |