View Javadoc
1   package demo;
2   
3   import java.util.Collection;
4   import java.util.Iterator;
5   import java.util.LinkedHashSet;
6   
7   import org.djutils.draw.Drawable2d;
8   import org.djutils.draw.bounds.Bounds2d;
9   import org.djutils.draw.line.LineSegment2d;
10  import org.djutils.draw.line.PolyLine2d;
11  import org.djutils.draw.line.Ray2d;
12  import org.djutils.draw.point.Point2d;
13  
14  /**
15   * BoundsDemos.java.
16   * <p>
17   * Copyright (c) 2021-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="https://djutils.org/docs/current/djutils/licenses.html">DJUTILS License</a>.
19   * </p>
20   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
22   */
23  public final class BoundsDemos
24  {
25      /**
26       * Do not instantiate.
27       */
28      private BoundsDemos()
29      {
30          // Do not instantiate.
31      }
32  
33      /**
34       * Demonstrate the Bounds classes.
35       * @param args String[]; the command line arguments; not used
36       */
37      public static void main(final String[] args)
38      {
39          Bounds2d b1 = new Bounds2d(3.4, 6.7, -5.6, 2.3); // Arguments are the absolute minimum and maximum values
40          System.out.println("b1: " + b1);
41          Bounds2d b2 = new Bounds2d(12.3, 23.4); // Arguments are ranges, symmetrically around 0.0
42          System.out.println("b2: " + b2);
43          PolyLine2d line = new PolyLine2d(new Point2d(1, 2), new Point2d(3, 4), new Point2d(-5, 12));
44          Bounds2d b3 = new Bounds2d(line.getPoints()); // Argument is Iterator&lt;Point2d&gt;
45          System.out.println("b3: " + b3);
46          Bounds2d b4 = line.getBounds(); // Of course, the PolyLine2d can create a Bounds2d by itself
47          System.out.println("b4: " + b4);
48          Point2d[] pointArray = new Point2d[] { new Point2d(1, 2), new Point2d(3, 4), new Point2d(-5, 12) };
49          Bounds2d b5 = new Bounds2d(pointArray);
50          System.out.println("b5: " + b5);
51          Collection<Drawable2d> drawableCollection = new LinkedHashSet<>();
52          drawableCollection.add(new Point2d(1, 2));
53          drawableCollection.add(new Point2d(3, 4));
54          drawableCollection.add(new Point2d(-5, 12));
55          Bounds2d b6 = new Bounds2d(drawableCollection);
56          System.out.println("b6: " + b6);
57          Bounds2d b7 = new Bounds2d(new Point2d(1, 2), new LineSegment2d(3, 4, -5, 12));
58          System.out.println("b7: " + b7);
59  
60          Bounds2d bounds = new Bounds2d(new Ray2d(1, 2, Math.toRadians(45)));
61          for (Iterator<Point2d> iterator = bounds.getPoints(); iterator.hasNext();)
62          {
63              System.out.println(iterator.next());
64          }
65      }
66  }