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

int javamorph::CPolygonDecorator::getIndex ( Point  p  )  [inline, private]

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

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

Definition at line 436 of file CPolygonDecorator.java.

References polygon.

Referenced by mouseMoved().

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


Generated by  Doxygen 1.6.0   Back to index