From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- .../ui/nearest-neighbor-component-search.js | 232 +++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 node_modules/montage/ui/nearest-neighbor-component-search.js (limited to 'node_modules/montage/ui/nearest-neighbor-component-search.js') diff --git a/node_modules/montage/ui/nearest-neighbor-component-search.js b/node_modules/montage/ui/nearest-neighbor-component-search.js new file mode 100644 index 00000000..ed247a7a --- /dev/null +++ b/node_modules/montage/ui/nearest-neighbor-component-search.js @@ -0,0 +1,232 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +var Montage = require("montage").Montage; + +var NearestNeighborComponentSearch = exports.NearestNeighborComponentSearch = Montage.create(Montage, { + + _componentList: { + enumerable: false, + value: null + }, + + componentList: { + get: function () { + return this._componentList; + }, + set: function (value) { + var i; + + this._componentList=value; + } + }, + + _pointerPosition: { + enumerable: false, + value: null + }, + + pointerPosition: { + get: function () { + return this._pointerPosition; + }, + set: function (value) { + var nearest = null; + + this._pointerPosition=value; + if ((this._componentList)&&(this._componentList.length)) { + var target = value.target, + nearest; + + for (i=0; i1e-10) { + u=q[i+1]*a-q[i]*b; + if (u<0) { + x=q[i]; + y=q[i+1]; + } else if (u>div) { + x=q[i]+b; + y=q[i+1]-a; + } else { + u/=div; + x=q[i]+u*b; + y=q[i+1]-u*a; + } + iDist=x*x+y*y; + if (iDist>1; + point.y=element.offsetHeight>>1; + v=convert(element, point); + iDistance=(pageX-v.x)*(pageX-v.x)+(pageY-v.y)*(pageY-v.y); + if (iDistance < distance) { + distance=iDistance; + //nearest=this._componentList[i]; + nearest=i; + } + } + return nearest; + } + }, + + _nearestNeighborComponent: { + enumerable: false, + value: null + }, + + nearestNeighborComponent: { + get: function () { + return this._nearestNeighborComponent; + }, + set: function (value) { + this._nearestNeighborComponent=value; + } + } +}); \ No newline at end of file -- cgit v1.2.3