Example usage for java.awt.geom Line2D ptSegDist

List of usage examples for java.awt.geom Line2D ptSegDist

Introduction

In this page you can find the example usage for java.awt.geom Line2D ptSegDist.

Prototype

public double ptSegDist(Point2D pt) 

Source Link

Document

Returns the distance from a Point2D to this line segment.

Usage

From source file:org.tellervo.desktop.graph.SkeletonPlot.java

public boolean contact(GraphSettings gInfo, Graph g, Point p, int bottom) {
    // snap to year
    int yearWidth = gInfo.getYearWidth();
    int firstYearIdx = (p.x / yearWidth) - 1;
    int nYears = 3;

    // Check three years' worth of data: the year prior to and after the year the mouse is inside
    Year startYear = gInfo.getDrawBounds().getStart().add(firstYearIdx);
    List<Point2D> points = this.getPointsFrom(gInfo, g, startYear, nYears, bottom);

    int nLines = points.size() - 1;
    for (int i = 0; i < nLines; i++) {
        Line2D line = new Line2D.Float(points.get(i), points.get(i + 1));

        int distance = Math.round((float) line.ptSegDist(p));
        if (distance <= NEAR)
            return true;
    }//from w w w.j  a v  a2  s .co  m

    return false;
}