View Javadoc
1   package org.djutils.draw;
2   
3   import java.io.Serializable;
4   import java.util.Iterator;
5   
6   import org.djutils.draw.point.Point;
7   
8   /**
9    * Drawable is an interface to indicate zero or more points can be retrieved to draw the object.
10   * <p>
11   * Copyright (c) 2020-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://djutils.org/docs/current/djutils/licenses.html">DJUTILS License</a>.
13   * </p>
14   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16   * @param <P> The point type (2d or 3d)
17   */
18  public interface Drawable<P extends Point<P>> extends Serializable
19  {
20      /**
21       * Retrieve, or generate all points that make up the object.
22       * @return Iterable&lt;Point2d&gt;; an iterator that generates all points that make up the object
23       */
24      Iterator<? extends P> getPoints();
25  
26      /**
27       * Retrieve the number of points that make up the object.
28       * @return int; the number of points that make up the object
29       */
30      int size();
31  
32      /**
33       * Return the number of dimensions.
34       * @return int; the number of dimensions
35       */
36      int getDimensions();
37      
38      /**
39       * Produce a string describing the Drawable using default conversion for the (double) coordinate values. Regrettably, it is
40       * not allowed to provide a default implementation here.
41       * @return String; a string describing the Drawable
42       */
43      @Override
44      String toString();
45  
46      /**
47       * Produce a String describing the Drawable.
48       * @param doubleFormat String; a format string (something like "%6.3f") which will be used to render every coordinate value)
49       * @param doNotIncludeClassName boolean; if true; the output of toString is <b>not</b> prefixed by the class name. This is
50       *            useful for concatenating the textual representation of lots of Drawables (e.g. an array, or a List).
51       * @return String; textual representation of the Drawable
52       */
53      String toString(String doubleFormat, boolean doNotIncludeClassName);
54  
55      /**
56       * Produce a String describing the Drawable.
57       * @param doubleFormat String; a format string (something like "%6.3f") which will be used to render every coordinate value)
58       * @return String; textual representation of the Drawable
59       */
60      default String toString(final String doubleFormat)
61      {
62          return toString(doubleFormat, false);
63      }
64  
65      /**
66       * Produce a String describing the Drawable.
67       * @param doNotIncludeClassName boolean; if true; the output of toString is <b>not</b> prefixed by the class name. This is
68       *            useful for concatenating the textual representation of lots of Drawables (e.g. an array, or a List).
69       * @return String; textual representation of the Drawable
70       */
71      default String toString(final boolean doNotIncludeClassName)
72      {
73          return toString("%f", doNotIncludeClassName);
74      }
75  
76  }