aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/nearest-neighbor-component-search.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/ui/nearest-neighbor-component-search.js')
-rw-r--r--node_modules/montage/ui/nearest-neighbor-component-search.js122
1 files changed, 61 insertions, 61 deletions
diff --git a/node_modules/montage/ui/nearest-neighbor-component-search.js b/node_modules/montage/ui/nearest-neighbor-component-search.js
index 6ba155ea..8cc9e4c2 100644
--- a/node_modules/montage/ui/nearest-neighbor-component-search.js
+++ b/node_modules/montage/ui/nearest-neighbor-component-search.js
@@ -25,23 +25,23 @@ var NearestNeighborComponentSearch = exports.NearestNeighborComponentSearch = Mo
25 }, 25 },
26 26
27 _pointerPosition: { 27 _pointerPosition: {
28 enumerable: false, 28 enumerable: false,
29 value: null 29 value: null
30 }, 30 },
31 31
32 pointerPosition: { 32 pointerPosition: {
33 get: function () { 33 get: function () {
34 return this._pointerPosition; 34 return this._pointerPosition;
35 }, 35 },
36 set: function (value) { 36 set: function (value) {
37 var nearest = null; 37 var nearest = null;
38 38
39 this._pointerPosition=value; 39 this._pointerPosition=value;
40 if ((this._componentList)&&(this._componentList.length)) { 40 if ((this._componentList)&&(this._componentList.length)) {
41 var target = value.target, 41 var target = value.target,
42 nearest; 42 nearest;
43 43
44 for (i=0; i<this._componentList.length; i++) { 44 for (var i=0; i<this._componentList.length; i++) {
45 this._componentList[i]._element.setAttribute("data-nn-index", i); 45 this._componentList[i]._element.setAttribute("data-nn-index", i);
46 } 46 }
47 while ((target.tagName !== "BODY")&&!(nearest = target.getAttribute("data-nn-index"))) { 47 while ((target.tagName !== "BODY")&&!(nearest = target.getAttribute("data-nn-index"))) {
@@ -64,8 +64,8 @@ var NearestNeighborComponentSearch = exports.NearestNeighborComponentSearch = Mo
64 this.nearestNeighborComponent=null; 64 this.nearestNeighborComponent=null;
65 } 65 }
66 } 66 }
67 } 67 }
68 }, 68 },
69 69
70 _hasNearestNeighborComponentSearch: { 70 _hasNearestNeighborComponentSearch: {
71 enumerable: false, 71 enumerable: false,
@@ -94,7 +94,7 @@ var NearestNeighborComponentSearch = exports.NearestNeighborComponentSearch = Mo
94 get: function () { 94 get: function () {
95 return this._nearestNeighborComponentSearchMethod; 95 return this._nearestNeighborComponentSearchMethod;
96 }, 96 },
97 set: function (vale) { 97 set: function (value) {
98 if (value==="midpoint") { 98 if (value==="midpoint") {
99 this._nearestNeighborComponentSearchMethod=value; 99 this._nearestNeighborComponentSearchMethod=value;
100 } else { 100 } else {
@@ -106,43 +106,43 @@ var NearestNeighborComponentSearch = exports.NearestNeighborComponentSearch = Mo
106 _pointToQuadSquaredDistance: { 106 _pointToQuadSquaredDistance: {
107 enumerable: false, 107 enumerable: false,
108 value: function (pX, pY, q) { 108 value: function (pX, pY, q) {
109 var dist, iDist, 109 var iDist,
110 i, j, u, x, y, div, 110 i, j, u, x, y, div,
111 dist=1e20, a, b; 111 dist=1e20, a, b;
112 112
113 q[0]-=pX; q[1]-=pY; q[2]-=pX; q[3]-=pY; 113 q[0]-=pX; q[1]-=pY; q[2]-=pX; q[3]-=pY;
114 q[4]-=pX; q[5]-=pY; q[6]-=pX; q[7]-=pY; 114 q[4]-=pX; q[5]-=pY; q[6]-=pX; q[7]-=pY;
115 for (i=0; i<8; i+=2) { 115 for (i=0; i<8; i+=2) {
116 j=(i+2)%8; 116 j=(i+2)%8;
117 a=q[i+1]-q[j+1]; 117 a=q[i+1]-q[j+1];
118 b=q[j]-q[i]; 118 b=q[j]-q[i];
119 div=a*a+b*b; 119 div=a*a+b*b;
120 if (div>1e-10) { 120 if (div>1e-10) {
121 u=q[i+1]*a-q[i]*b; 121 u=q[i+1]*a-q[i]*b;
122 if (u<0) { 122 if (u<0) {
123 x=q[i]; 123 x=q[i];
124 y=q[i+1]; 124 y=q[i+1];
125 } else if (u>div) { 125 } else if (u>div) {
126 x=q[i]+b; 126 x=q[i]+b;
127 y=q[i+1]-a; 127 y=q[i+1]-a;
128 } else { 128 } else {
129 u/=div; 129 u/=div;
130 x=q[i]+u*b; 130 x=q[i]+u*b;
131 y=q[i+1]-u*a; 131 y=q[i+1]-u*a;
132 } 132 }
133 iDist=x*x+y*y; 133 iDist=x*x+y*y;
134 if (iDist<dist) { 134 if (iDist<dist) {
135 dist=iDist; 135 dist=iDist;
136 } 136 }
137 } 137 }
138 } 138 }
139 return dist; 139 return dist;
140 } 140 }
141 }, 141 },
142 142
143 _searchPreciseNearestNeighborComponent: { 143 _searchPreciseNearestNeighborComponent: {
144 enumerable: false, 144 enumerable: false,
145 value: function () { 145 value: function () {
146 var length=this._componentList.length, 146 var length=this._componentList.length,
147 point=new WebKitPoint(0, 0), 147 point=new WebKitPoint(0, 0),
148 v0, v1, v2, v3, i, 148 v0, v1, v2, v3, i,
@@ -182,12 +182,12 @@ var NearestNeighborComponentSearch = exports.NearestNeighborComponentSearch = Mo
182 } 182 }
183 } 183 }
184 return nearest; 184 return nearest;
185 } 185 }
186 }, 186 },
187 187
188 _searchMidpointNearestNeighborComponent: { 188 _searchMidpointNearestNeighborComponent: {
189 enumerable: false, 189 enumerable: false,
190 value: function () { 190 value: function () {
191 var length=this._componentList.length, 191 var length=this._componentList.length,
192 point=new WebKitPoint(0, 0), 192 point=new WebKitPoint(0, 0),
193 element, 193 element,
@@ -213,20 +213,20 @@ var NearestNeighborComponentSearch = exports.NearestNeighborComponentSearch = Mo
213 } 213 }
214 } 214 }
215 return nearest; 215 return nearest;
216 } 216 }
217 }, 217 },
218 218
219 _nearestNeighborComponent: { 219 _nearestNeighborComponent: {
220 enumerable: false, 220 enumerable: false,
221 value: null 221 value: null
222 }, 222 },
223 223
224 nearestNeighborComponent: { 224 nearestNeighborComponent: {
225 get: function () { 225 get: function () {
226 return this._nearestNeighborComponent; 226 return this._nearestNeighborComponent;
227 }, 227 },
228 set: function (value) { 228 set: function (value) {
229 this._nearestNeighborComponent=value; 229 this._nearestNeighborComponent=value;
230 } 230 }
231 } 231 }
232}); 232});