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