Example usage for java.awt.geom Point2D equals

List of usage examples for java.awt.geom Point2D equals

Introduction

In this page you can find the example usage for java.awt.geom Point2D equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Determines whether or not two points are equal.

Usage

From source file:de.bund.bfr.jung.JungUtils.java

static Line2D getLineInMiddle(Shape edgeShape) {
    GeneralPath path = new GeneralPath(edgeShape);
    float[] seg = new float[6];
    List<Point2D> points = new ArrayList<>();

    for (PathIterator i = path.getPathIterator(null, 1); !i.isDone(); i.next()) {
        i.currentSegment(seg);//from w w w  .j  av a 2s .co m
        points.add(new Point2D.Float(seg[0], seg[1]));
    }

    Point2D first = points.get(0);
    Point2D last = points.get(points.size() - 1);

    if (first.equals(last)) {
        Point2D minP = points.stream().min((p1, p2) -> Double.compare(p1.getY(), p2.getY())).get();

        return new Line2D.Float(minP, new Point2D.Float((float) (minP.getX() + 1.0), (float) minP.getY()));
    } else {
        for (int i = 0; i < points.size() - 1; i++) {
            Point2D p1 = points.get(i);
            Point2D p2 = points.get(i + 1);

            if (p2.distance(last) < p2.distance(first)) {
                Line2D ortho = getOrthogonal(new Line2D.Float(first, last));
                Point2D pp1 = getIntersection(new Line2D.Float(p1, p2), ortho);
                Point2D pp2 = new Point2D.Float((float) (pp1.getX() + last.getX() - first.getX()),
                        (float) (pp1.getY() + last.getY() - first.getY()));

                return new Line2D.Float(pp1, pp2);
            }
        }

        return null;
    }
}