Package ru.dubov.primitives

Examples of ru.dubov.primitives.Point


   
    public void testClosestPair_Example() {
        // Boundary case - X coordinates are equal
        ArrayList<Point> points = new ArrayList<Point>();
        points.add(new Point(100, 100));
        points.add(new Point(100, 102));
        points.add(new Point(100, 103));
        points.add(new Point(100, 105));
        points.add(new Point(100, 107));
       
        checkClosestPair(points);
       
        // Boundary case - Y coordinates are equal
        points = new ArrayList();
        points.add(new Point(100, 100));
        points.add(new Point(102, 100));
        points.add(new Point(103, 100));
        points.add(new Point(105, 100));
        points.add(new Point(107, 100));
       
        checkClosestPair(points);
       
    }
View Full Code Here


       
        for (int n = 3; n <= 100; n++) {
            ArrayList<Point> points = new ArrayList<Point>();
           
            for(int i = 0; i < n; i++) {
                points.add(new Point(rand.nextDouble()*100,
                                     rand.nextDouble()*100));
            }
       
            checkClosestPair(points);
        }
View Full Code Here

        jPanel1.repaint();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MousePressed
        if (state == 0) {
            Point pi = new Point(evt.getX(), jPanel1.getHeight() - evt.getY());
            points.add(pi);
        }
       
        jPanel1.repaint();
    }//GEN-LAST:event_jPanel1MousePressed
View Full Code Here

        jPanel1.repaint();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MousePressed
        if (state == 0) {
            Point pi = new Point(evt.getX(), jPanel1.getHeight() - evt.getY());
            points.add(pi);
        }
       
        jPanel1.repaint();
    }//GEN-LAST:event_jPanel1MousePressed
View Full Code Here

   
    /**
     * Finds the pair of closest points using a naive method in O(n^2).
     */
    public static ArrayList<Point> Naive(ArrayList<Point> points) {
        Point p0 = points.get(0);
        Point p1 = points.get(1);
       
        for (int i = 0; i < points.size() - 1; i++) {
            for (int j = i + 1; j < points.size(); j++) {
                if(dist(points.get(i), points.get(j)) < dist(p0, p1)) {
                    p0 = points.get(i);
View Full Code Here

            // все точки уходят налево (например, если у них равны координаты X)
            // TODO: Потенциально деградация до O(n^2), если все точки на оси Y.
            if (XR.size() == 0) {
                // Пока что решение - просто перекидываем
                // крайнюю справа точку из XL направо, в XR
                Point repl = XL.get(XL.size()-1);
               
                XL.remove(repl);
                XR.add(repl);
               
                YL.remove(repl);
View Full Code Here

        // Проходимся по Y2 в поисках ближайших точек
        if (Y2.size() < 2) {
            return null;
        }

        Point p1 = Y2.get(0);
        Point p2 = Y2.get(1);

        // Достаточно просмотреть 7 точек
        for (int i = 0; i < Y2.size() - 1; i++) {
            for (int j = i + 1; j <= Math.min(i + 8, Y2.size() - 1); j++)
                if (dist(Y2.get(i), Y2.get(j)) < dist(p1, p2)) {
View Full Code Here

        jPanel1.repaint();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MousePressed
        if (state == 0) {
            Point pi = new Point(evt.getX(), jPanel1.getHeight() - evt.getY());
            points.add(pi);
        }
       
        jPanel1.repaint();
    }//GEN-LAST:event_jPanel1MousePressed
View Full Code Here

public class VanGoghAlgorithmTest extends TestCase {

    public void testFast() {
        Polygon p = new Polygon();
        p.add(new Point(0,0));
        p.add(new Point(1,1));
        p.add(new Point(2,0));
        p.add(new Point(3,1));
        p.add(new Point(4,0));
        p.add(new Point(4,4));
        p.add(new Point(0,4));
       
        VanGoghAlgorithm.fast(p);
    }
View Full Code Here

TOP

Related Classes of ru.dubov.primitives.Point

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.