Package geometry.java

Examples of geometry.java.Pair


        }
        Point[] inputA = points.toArray(new Point[points.size()]);
        Arrays.sort(inputA, Point.COMPARE_X);
        Point[] inputB = Arrays.copyOf(inputA, inputA.length);
       
        Pair divide = Points.divideAndConquer(inputA);
        Pair force = bruteForce(inputB);
       
        assertEquals(force, divide);
    }
View Full Code Here


     * Return the closest pair of points using the brute force method of comparing each
     * pair of points
     * @param points unordered points
     */
    private Pair bruteForce(Point... points) {
        Pair closest = new Pair(null, null);
        for (int i = 0; i < points.length - 1; i++)
            for (int j = i + 1; j < points.length; j++) {
                Pair pair = new Pair(points[i], points[j]);
                if (pair.dist < closest.dist) closest = pair;
            }
        return closest;
    }
View Full Code Here

    public void testOptimizedBruteForce() {
        Point a = new Point(0.0, 2.0);
        Point b = new Point(2, 0);
        Point c = new Point(0.0, 2.0);
       
        Pair closest = Points.optimizedBruteForce(new Point[]{a, b, c});
        assertEquals(new Pair(a,c), closest);
    }
View Full Code Here

    }
    @Test
    public void testClosestInStrip() {
        Point[] strip = { new Point(0, 1.2), new Point(0, 0.8), new Point(1, 0.9),
                new Point(1, 1.1), new Point(2, 1.3), new Point(2, 0.9) };
        Pair res = Points.closestInStrip(strip, 1.0);
        Pair exp = new Pair(new Point(1, 0.9), new Point(1, 1.1));
        assertEquals(exp, res);
    }
View Full Code Here

    }
    @Test
    public void testClosestPairSimple() {
        Point a = new Point(0, 0);
        Point b = new Point(0, 3);
        Pair res = Points.divideAndConquer(a, b);
        assertEquals(new Pair(a, b), res);
        Point c = new Point(3, 4);
        res = Points.divideAndConquer(a, b, c);
        assertEquals(new Pair(a, b), res);
    }
View Full Code Here

TOP

Related Classes of geometry.java.Pair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.