Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.geom.Point2D;

import java.util.Comparator;

public class Main {
    /**
     * Create a comparator that compares against the distance from the specified point.
     *
     * Note: The comparator will continue to sort by distance from the origin point, even if the
     * origin point's coordinates are modified after the comparator is created.
     *
     * Used by positionRect().
     */
    public static <P extends Point2D> Comparator<P> createPointComparator(final P origin) {
        return new Comparator<P>() {
            public int compare(P p1, P p2) {
                double dist1 = origin.distance(p1);
                double dist2 = origin.distance(p2);
                return (dist1 > dist2) ? 1 : ((dist1 < dist2) ? -1 : 0);
            }
        };
    }
}