Example usage for java.awt.geom Line2D getP2

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

Introduction

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

Prototype

public abstract Point2D getP2();

Source Link

Document

Returns the end Point2D of this Line2D .

Usage

From source file:org.gumtree.vis.awt.JChartPanel.java

private void findSelectedMarker(Point point) {
    Line2D marker = null;//from w  ww.  j a v a 2  s.c o m
    double distance = Double.MAX_VALUE;
    double cDis;
    for (Entry<Line2D, Color> entry : domainMarkerMap.entrySet()) {
        Line2D line = entry.getKey();
        Point2D p2 = line.getP2();
        double height = p2.getY();
        cDis = Double.MAX_VALUE;
        if (height < 1e-4) {
            double xScr = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart()).getX();
            cDis = Math.abs(point.getX() - xScr);
        } else {
            Point2D newP2 = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart());
            if (newP2.getY() < point.getY()) {
                cDis = Math.abs(point.getX() - newP2.getX());
            } else {
                cDis = newP2.distance(point);
            }
        }
        if (cDis <= distance) {
            distance = cDis;
            marker = line;
        }
    }
    for (Entry<Line2D, Color> entry : rangeMarkerMap.entrySet()) {
        Line2D line = entry.getKey();
        Point2D p1 = line.getP1();
        Point2D p2 = line.getP2();
        double width = p2.getX();
        cDis = Double.MAX_VALUE;
        if (width < 1e-4) {
            double yScr = ChartMaskingUtilities.translateChartPoint(p1, getScreenDataArea(), getChart()).getY();
            cDis = Math.abs(point.getY() - yScr);
        } else {
            Point2D newP2 = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart());
            if (newP2.getX() > point.getX()) {
                cDis = Math.abs(point.getY() - newP2.getY());
            } else {
                cDis = newP2.distance(point);
            }
        }
        if (cDis <= distance) {
            distance = cDis;
            marker = line;
        }
    }
    for (Entry<Line2D, Color> entry : markerMap.entrySet()) {
        Line2D line = entry.getKey();
        Point2D p1 = line.getP1();
        p1 = ChartMaskingUtilities.translateChartPoint(p1, getScreenDataArea(), getChart());
        cDis = p1.distance(point);
        if (cDis <= distance) {
            distance = cDis;
            marker = line;
        }
    }
    if (distance < 5) {
        selectedMarker = marker;
    } else {
        selectedMarker = null;
    }
}

From source file:org.dwfa.ace.graph.AceGraphRenderer.java

/**
 * Passed Line's point2 must be inside the passed shape or
 * an IllegalArgumentException is thrown
 * //from  ww w  .ja  v  a2 s  .co m
 * @param line line to subdivide
 * @param shape shape to compare with line
 * @return a line that intersects the shape boundary
 * @throws IllegalArgumentException if the passed line's point1 is not
 *             inside the shape
 */
protected Line2D getLastOutsideSegment(Line2D line, Shape shape) {
    if (shape.contains(line.getP2()) == false) {
        String errorString = "line end point: " + line.getP2() + " is not contained in shape: "
                + shape.getBounds2D();
        throw new IllegalArgumentException(errorString);
        // return null;
    }
    Line2D left = new Line2D.Double();
    Line2D right = new Line2D.Double();
    // subdivide the line until its left segment intersects
    // the shape boundary
    int iterations = 0;
    do {
        subdivide(line, left, right);
        line = right;
    } while (shape.contains(line.getP1()) == false && iterations++ < MAX_ITERATIONS);
    // now that right is completely inside shape,
    // return left, which must be partially outside
    return left;
}