Logo Search packages:      
Sourcecode: javamorph version File versions  Download package

int javamorph::CMeshDecorator::getIndex ( Point  p0  )  [inline, private]

Seek the index of that one mesh point which is nearest to the mouse cursor.

Parameters:
p0 on screen, scaled to picture coordinates.
Returns:
Index in point collection.

Definition at line 269 of file CMeshDecorator.java.

References mesh.

Referenced by mouseMoved().

                                  {
        int dx, dy, d, h = Integer.MAX_VALUE, n = -1;
        /* Seek nearest within all mesh points. */
        for(int i = 0; i < mesh.size(); ++i){
            Point p1 = mesh.get(i);
            dx = p0.x - p1.x;
            dy = p0.y - p1.y;
            d = dx * dx + dy * dy;
            /* Update if nearer. */
            if(d < h){
                n = i;
                h = d;
            }
        }
        return n;
    }


Generated by  Doxygen 1.6.0   Back to index