1 /* File Curve2D.java
2 *
3 * Project : Java Geometry Library
4 *
5 * ===========================================
6 *
7 * This library is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 2.1 of the License, or (at
10 * your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library. if not, write to :
20 * The Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24 // package
25
26 package math.geom2d.curve;
27
28 // Imports
29 import java.awt.Graphics2D;
30 import java.awt.Shape;
31 import java.util.Collection;
32
33 import math.geom2d.AffineTransform2D;
34 import math.geom2d.Box2D;
35 import math.geom2d.Point2D;
36 import math.geom2d.Shape2D;
37 import math.geom2d.line.LinearShape2D;
38
39 /**
40 * <p>Interface for piecewise smooth curves, like polylines, conics, straight
41 * lines, line segments...</p>
42 * <p>Several interfaces exist to use more explicit type of curves:
43 * {@link ContinuousCurve2D ContinuousCurve2D} for finite or infinite
44 * continuous curves, {@link SmoothCurve2D SmoothCurve2D} for curves that
45 * admit a derivative (and hence a tangent, a curvature...) at each point,
46 * {@link math.geom2d.domain.OrientedCurve2D OrientedCurve2D} that are used to
47 * define the {@link math.geom2d.domain.Boundary2D boundary} of a
48 * {@link math.geom2d.domain.Domain2D domain}...</p>
49 * <p>
50 * Points on curves are identified using curve parameterization.
51 * This parameterization is left to the implementation.
52 */
53 public interface Curve2D extends Shape2D, Cloneable {
54
55 // ===================================================================
56 // class variables
57
58 // ===================================================================
59 // constructors
60
61 // ===================================================================
62 // accessors
63
64 /**
65 * Get value of parameter t for the first point of the curve. It can be
66 * -Infinity, in this case the piece of curve is not bounded.
67 */
68 public abstract double getT0();
69
70 /**
71 * Get value of parameter t for the last point of the curve. It can be
72 * +Infinity, in this case the piece of curve is not bounded.
73 */
74 public abstract double getT1();
75
76 /**
77 * Gets the point from a parametric representation of the curve. If the
78 * parameter lies outside the definition range, the parameter corresponding
79 * to the closest bound is used instead. This method can be used to draw an
80 * approximated outline of a curve, by selecting multiple values for t and
81 * drawing lines between them.
82 */
83 public abstract Point2D getPoint(double t);
84
85 /**
86 * Get the first point of the curve. It must returns the same result as
87 * <code>getPoint(getT0())</code>.
88 *
89 * @return the first point of the curve
90 */
91 public abstract Point2D getFirstPoint();
92
93 /**
94 * Get the last point of the curve. It must returns the same result as
95 * <code>getPoint(getT1())</code>.
96 *
97 * @return the last point of the curve.
98 */
99 public abstract Point2D getLastPoint();
100
101 /**
102 * Returns a set of singular points, i. e. which do not locally admit
103 * derivative.
104 *
105 * @return a collection of Point2D.
106 */
107 public abstract Collection<Point2D> getSingularPoints();
108
109 /**
110 * Checks if a point is singular.
111 *
112 * @param pos the position of the point on the curve
113 * @return true if the point at this location is singular
114 */
115 public abstract boolean isSingular(double pos);
116
117 /**
118 * Get position of the point on the curve. If the point does not belong to
119 * the curve, return Double.NaN.
120 *
121 * @param point a point belonging to the curve
122 * @return the position of the point on the curve
123 */
124 public abstract double getPosition(java.awt.geom.Point2D point);
125
126 /**
127 * Returns the position of the closest orthogonal projection of the point on
128 * the curve, or of the closest singular point. This function should always
129 * returns a valid value.
130 *
131 * @param point a point to project
132 * @return the position of the closest orthogonal projection
133 */
134 public abstract double project(java.awt.geom.Point2D point);
135
136 /**
137 * Returns the intersection points of the curve with the specified line. The
138 * length of the result array is the number of intersection points.
139 */
140 public abstract Collection<Point2D> getIntersections(LinearShape2D line);
141
142 /**
143 * Return the path for tracing the curve, when cursor is already located at
144 * the beginning of the curve. Using this method allows to concatenate
145 * curves and to draw polycurves.
146 *
147 * @return the path for tracing the curve.
148 */
149 // public abstract java.awt.geom.GeneralPath getInnerPath();
150 /**
151 * Returns the curve with same trace on the plane with parametrization in
152 * reverse order.
153 */
154 public abstract Curve2D getReverseCurve();
155
156 /**
157 * Returns the collection of continuous curves which constitute this curve.
158 *
159 * @return a collection of continuous curves.
160 */
161 public abstract Collection<? extends ContinuousCurve2D> getContinuousCurves();
162
163 /**
164 * Returns a portion of the original curve, delimited by two positions on
165 * the curve.
166 *
167 * @param t0 position of the start of the sub-curve
168 * @param t1 position of the end of the sub-curve
169 * @return the portion of original curve comprised between t0 and t1.
170 */
171 public abstract Curve2D getSubCurve(double t0, double t1);
172
173 /**
174 * Transforms the curve by an affine transform. The result is an instance of
175 * Curve2D.
176 */
177 //TODO: specifies orientation of transformed curve. Should we invert curve
178 // when transform is not direct ?
179 public abstract Curve2D transform(AffineTransform2D trans);
180
181 /**
182 * When a curve is clipped, the result is a set of curves.
183 */
184 public abstract CurveSet2D<? extends Curve2D> clip(Box2D box);
185
186 /**
187 * @since 0.7.1
188 * @return the shape corresponding to this curve
189 */
190 public java.awt.Shape getAsAWTShape() ;
191
192 /**
193 * Draws the curve on the given Graphics2D object.
194 *
195 * @param g2 the graphics to draw the curve
196 * @since 0.6.3
197 */
198 public abstract void draw(Graphics2D g2);
199
200 /**
201 * Overrides Object declaration to ensure Curve2D implementation are
202 * cloned as Curve2D.
203 * @return the cloned curve
204 */
205 public abstract Curve2D clone();
206
207 }