1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17/**
18 * @author Denis M. Kishenko
19 * @version $Revision$
20 */
21
22package java.awt.geom;
23
24import java.awt.Rectangle;
25import java.awt.Shape;
26import java.util.NoSuchElementException;
27
28import org.apache.harmony.awt.internal.nls.Messages;
29
30/**
31 * The Class Line2D represents a line whose data is given in high-precision
32 * values appropriate for graphical operations.
33 *
34 * @since Android 1.0
35 */
36public abstract class Line2D implements Shape, Cloneable {
37
38    /**
39     * The Class Float is the subclass of Line2D that has all of its data values
40     * stored with float-level precision.
41     *
42     * @since Android 1.0
43     */
44    public static class Float extends Line2D {
45
46        /**
47         * The x coordinate of the starting point.
48         */
49        public float x1;
50
51        /**
52         * The y coordinate of the starting point.
53         */
54        public float y1;
55
56        /**
57         * The x coordinate of the end point.
58         */
59        public float x2;
60
61        /**
62         * The y coordinate of the end point.
63         */
64        public float y2;
65
66        /**
67         * Instantiates a new float-valued Line2D with its data values set to
68         * zero.
69         */
70        public Float() {
71        }
72
73        /**
74         * Instantiates a new float-valued Line2D with the specified endpoints.
75         *
76         * @param x1
77         *            the x coordinate of the starting point.
78         * @param y1
79         *            the y coordinate of the starting point.
80         * @param x2
81         *            the x coordinate of the end point.
82         * @param y2
83         *            the y coordinate of the end point.
84         */
85        public Float(float x1, float y1, float x2, float y2) {
86            setLine(x1, y1, x2, y2);
87        }
88
89        /**
90         * Instantiates a new float-valued Line2D with the specified endpoints.
91         *
92         * @param p1
93         *            the starting point.
94         * @param p2
95         *            the end point.
96         */
97        public Float(Point2D p1, Point2D p2) {
98            setLine(p1, p2);
99        }
100
101        @Override
102        public double getX1() {
103            return x1;
104        }
105
106        @Override
107        public double getY1() {
108            return y1;
109        }
110
111        @Override
112        public double getX2() {
113            return x2;
114        }
115
116        @Override
117        public double getY2() {
118            return y2;
119        }
120
121        @Override
122        public Point2D getP1() {
123            return new Point2D.Float(x1, y1);
124        }
125
126        @Override
127        public Point2D getP2() {
128            return new Point2D.Float(x2, y2);
129        }
130
131        @Override
132        public void setLine(double x1, double y1, double x2, double y2) {
133            this.x1 = (float)x1;
134            this.y1 = (float)y1;
135            this.x2 = (float)x2;
136            this.y2 = (float)y2;
137        }
138
139        /**
140         * Sets the data values that define the line.
141         *
142         * @param x1
143         *            the x coordinate of the starting point.
144         * @param y1
145         *            the y coordinate of the starting point.
146         * @param x2
147         *            the x coordinate of the end point.
148         * @param y2
149         *            the y coordinate of the end point.
150         */
151        public void setLine(float x1, float y1, float x2, float y2) {
152            this.x1 = x1;
153            this.y1 = y1;
154            this.x2 = x2;
155            this.y2 = y2;
156        }
157
158        public Rectangle2D getBounds2D() {
159            float rx, ry, rw, rh;
160            if (x1 < x2) {
161                rx = x1;
162                rw = x2 - x1;
163            } else {
164                rx = x2;
165                rw = x1 - x2;
166            }
167            if (y1 < y2) {
168                ry = y1;
169                rh = y2 - y1;
170            } else {
171                ry = y2;
172                rh = y1 - y2;
173            }
174            return new Rectangle2D.Float(rx, ry, rw, rh);
175        }
176    }
177
178    /**
179     * The Class Double is the subclass of Line2D that has all of its data
180     * values stored with double-level precision.
181     *
182     * @since Android 1.0
183     */
184    public static class Double extends Line2D {
185
186        /**
187         * The x coordinate of the starting point.
188         */
189        public double x1;
190
191        /**
192         * The y coordinate of the starting point.
193         */
194        public double y1;
195
196        /**
197         * The x coordinate of the end point.
198         */
199        public double x2;
200
201        /**
202         * The y coordinate of the end point.
203         */
204        public double y2;
205
206        /**
207         * Instantiates a new double-valued Line2D with its data values set to
208         * zero.
209         */
210        public Double() {
211        }
212
213        /**
214         * Instantiates a new double-valued Line2D with the specified endpoints.
215         *
216         * @param x1
217         *            the x coordinate of the starting point.
218         * @param y1
219         *            the y coordinate of the starting point.
220         * @param x2
221         *            the x coordinate of the end point.
222         * @param y2
223         *            the y coordinate of the end point.
224         */
225        public Double(double x1, double y1, double x2, double y2) {
226            setLine(x1, y1, x2, y2);
227        }
228
229        /**
230         * Instantiates a new double-valued Line2D with the specified endpoints.
231         *
232         * @param p1
233         *            the starting point.
234         * @param p2
235         *            the end point.
236         */
237        public Double(Point2D p1, Point2D p2) {
238            setLine(p1, p2);
239        }
240
241        @Override
242        public double getX1() {
243            return x1;
244        }
245
246        @Override
247        public double getY1() {
248            return y1;
249        }
250
251        @Override
252        public double getX2() {
253            return x2;
254        }
255
256        @Override
257        public double getY2() {
258            return y2;
259        }
260
261        @Override
262        public Point2D getP1() {
263            return new Point2D.Double(x1, y1);
264        }
265
266        @Override
267        public Point2D getP2() {
268            return new Point2D.Double(x2, y2);
269        }
270
271        @Override
272        public void setLine(double x1, double y1, double x2, double y2) {
273            this.x1 = x1;
274            this.y1 = y1;
275            this.x2 = x2;
276            this.y2 = y2;
277        }
278
279        public Rectangle2D getBounds2D() {
280            double rx, ry, rw, rh;
281            if (x1 < x2) {
282                rx = x1;
283                rw = x2 - x1;
284            } else {
285                rx = x2;
286                rw = x1 - x2;
287            }
288            if (y1 < y2) {
289                ry = y1;
290                rh = y2 - y1;
291            } else {
292                ry = y2;
293                rh = y1 - y2;
294            }
295            return new Rectangle2D.Double(rx, ry, rw, rh);
296        }
297    }
298
299    /*
300     * Line2D path iterator
301     */
302    /**
303     * The subclass of PathIterator to traverse a Line2D.
304     */
305    class Iterator implements PathIterator {
306
307        /**
308         * The x coordinate of the start line point.
309         */
310        double x1;
311
312        /**
313         * The y coordinate of the start line point.
314         */
315        double y1;
316
317        /**
318         * The x coordinate of the end line point.
319         */
320        double x2;
321
322        /**
323         * The y coordinate of the end line point.
324         */
325        double y2;
326
327        /**
328         * The path iterator transformation.
329         */
330        AffineTransform t;
331
332        /**
333         * The current segment index.
334         */
335        int index;
336
337        /**
338         * Constructs a new Line2D.Iterator for given line and transformation.
339         *
340         * @param l
341         *            the source Line2D object.
342         * @param at
343         *            the AffineTransform object to apply rectangle path.
344         */
345        Iterator(Line2D l, AffineTransform at) {
346            this.x1 = l.getX1();
347            this.y1 = l.getY1();
348            this.x2 = l.getX2();
349            this.y2 = l.getY2();
350            this.t = at;
351        }
352
353        public int getWindingRule() {
354            return WIND_NON_ZERO;
355        }
356
357        public boolean isDone() {
358            return index > 1;
359        }
360
361        public void next() {
362            index++;
363        }
364
365        public int currentSegment(double[] coords) {
366            if (isDone()) {
367                // awt.4B=Iterator out of bounds
368                throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$
369            }
370            int type;
371            if (index == 0) {
372                type = SEG_MOVETO;
373                coords[0] = x1;
374                coords[1] = y1;
375            } else {
376                type = SEG_LINETO;
377                coords[0] = x2;
378                coords[1] = y2;
379            }
380            if (t != null) {
381                t.transform(coords, 0, coords, 0, 1);
382            }
383            return type;
384        }
385
386        public int currentSegment(float[] coords) {
387            if (isDone()) {
388                // awt.4B=Iterator out of bounds
389                throw new NoSuchElementException(Messages.getString("awt.4B")); //$NON-NLS-1$
390            }
391            int type;
392            if (index == 0) {
393                type = SEG_MOVETO;
394                coords[0] = (float)x1;
395                coords[1] = (float)y1;
396            } else {
397                type = SEG_LINETO;
398                coords[0] = (float)x2;
399                coords[1] = (float)y2;
400            }
401            if (t != null) {
402                t.transform(coords, 0, coords, 0, 1);
403            }
404            return type;
405        }
406
407    }
408
409    /**
410     * Instantiates a new Line2D.
411     */
412    protected Line2D() {
413    }
414
415    /**
416     * Gets the x coordinate of the starting point.
417     *
418     * @return the x coordinate of the starting point.
419     */
420    public abstract double getX1();
421
422    /**
423     * Gets the y coordinate of the starting point.
424     *
425     * @return the y coordinate of the starting point.
426     */
427    public abstract double getY1();
428
429    /**
430     * Gets the x coordinate of the end point.
431     *
432     * @return the x2.
433     */
434    public abstract double getX2();
435
436    /**
437     * Gets the y coordinate of the end point.
438     *
439     * @return the y coordinate of the end point.
440     */
441    public abstract double getY2();
442
443    /**
444     * Gets the p the starting point.
445     *
446     * @return the p the starting point.
447     */
448    public abstract Point2D getP1();
449
450    /**
451     * Gets the p end point.
452     *
453     * @return the p end point.
454     */
455    public abstract Point2D getP2();
456
457    /**
458     * Sets the line's endpoints.
459     *
460     * @param x1
461     *            the x coordinate of the starting point.
462     * @param y1
463     *            the y coordinate of the starting point.
464     * @param x2
465     *            the x coordinate of the end point.
466     * @param y2
467     *            the y coordinate of the end point.
468     */
469    public abstract void setLine(double x1, double y1, double x2, double y2);
470
471    /**
472     * Sets the line's endpoints.
473     *
474     * @param p1
475     *            the starting point.
476     * @param p2
477     *            the end point.
478     */
479    public void setLine(Point2D p1, Point2D p2) {
480        setLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());
481    }
482
483    /**
484     * Sets the line's endpoints by copying the data from another Line2D.
485     *
486     * @param line
487     *            the Line2D to copy the endpoint data from.
488     */
489    public void setLine(Line2D line) {
490        setLine(line.getX1(), line.getY1(), line.getX2(), line.getY2());
491    }
492
493    public Rectangle getBounds() {
494        return getBounds2D().getBounds();
495    }
496
497    /**
498     * Tells where the point is with respect to the line segment, given the
499     * orientation of the line segment. If the ray found by extending the line
500     * segment from its starting point is rotated, this method tells whether the
501     * ray should rotate in a clockwise direction or a counter-clockwise
502     * direction to hit the point first. The return value is 0 if the point is
503     * on the line segment, it's 1 if the point is on the ray or if the ray
504     * should rotate in a counter-clockwise direction to get to the point, and
505     * it's -1 if the ray should rotate in a clockwise direction to get to the
506     * point or if the point is on the line determined by the line segment but
507     * not on the ray from the segment's starting point and through its end
508     * point.
509     *
510     * @param x1
511     *            the x coordinate of the starting point of the line segment.
512     * @param y1
513     *            the y coordinate of the starting point of the line segment.
514     * @param x2
515     *            the x coordinate of the end point of the line segment.
516     * @param y2
517     *            the y coordinate of the end point of the line segment.
518     * @param px
519     *            the x coordinate of the test point.
520     * @param py
521     *            the p coordinate of the test point.
522     * @return the value that describes where the point is with respect to the
523     *         line segment, given the orientation of the line segment.
524     */
525    public static int relativeCCW(double x1, double y1, double x2, double y2, double px, double py) {
526        /*
527         * A = (x2-x1, y2-y1) P = (px-x1, py-y1)
528         */
529        x2 -= x1;
530        y2 -= y1;
531        px -= x1;
532        py -= y1;
533        double t = px * y2 - py * x2; // PxA
534        if (t == 0.0) {
535            t = px * x2 + py * y2; // P*A
536            if (t > 0.0) {
537                px -= x2; // B-A
538                py -= y2;
539                t = px * x2 + py * y2; // (P-A)*A
540                if (t < 0.0) {
541                    t = 0.0;
542                }
543            }
544        }
545
546        return t < 0.0 ? -1 : (t > 0.0 ? 1 : 0);
547    }
548
549    /**
550     * Tells where the point is with respect to this line segment, given the
551     * orientation of this line segment. If the ray found by extending the line
552     * segment from its starting point is rotated, this method tells whether the
553     * ray should rotate in a clockwise direction or a counter-clockwise
554     * direction to hit the point first. The return value is 0 if the point is
555     * on the line segment, it's 1 if the point is on the ray or if the ray
556     * should rotate in a counter-clockwise direction to get to the point, and
557     * it's -1 if the ray should rotate in a clockwise direction to get to the
558     * point or if the point is on the line determined by the line segment but
559     * not on the ray from the segment's starting point and through its end
560     * point.
561     *
562     * @param px
563     *            the x coordinate of the test point.
564     * @param py
565     *            the p coordinate of the test point.
566     * @return the value that describes where the point is with respect to this
567     *         line segment, given the orientation of this line segment.
568     */
569    public int relativeCCW(double px, double py) {
570        return relativeCCW(getX1(), getY1(), getX2(), getY2(), px, py);
571    }
572
573    /**
574     * Tells where the point is with respect to this line segment, given the
575     * orientation of this line segment. If the ray found by extending the line
576     * segment from its starting point is rotated, this method tells whether the
577     * ray should rotate in a clockwise direction or a counter-clockwise
578     * direction to hit the point first. The return value is 0 if the point is
579     * on the line segment, it's 1 if the point is on the ray or if the ray
580     * should rotate in a counter-clockwise direction to get to the point, and
581     * it's -1 if the ray should rotate in a clockwise direction to get to the
582     * point or if the point is on the line determined by the line segment but
583     * not on the ray from the segment's starting point and through its end
584     * point.
585     *
586     * @param p
587     *            the test point.
588     * @return the value that describes where the point is with respect to this
589     *         line segment, given the orientation of this line segment.
590     */
591    public int relativeCCW(Point2D p) {
592        return relativeCCW(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
593    }
594
595    /**
596     * Tells whether the two line segments cross.
597     *
598     * @param x1
599     *            the x coordinate of the starting point of the first segment.
600     * @param y1
601     *            the y coordinate of the starting point of the first segment.
602     * @param x2
603     *            the x coordinate of the end point of the first segment.
604     * @param y2
605     *            the y coordinate of the end point of the first segment.
606     * @param x3
607     *            the x coordinate of the starting point of the second segment.
608     * @param y3
609     *            the y coordinate of the starting point of the second segment.
610     * @param x4
611     *            the x coordinate of the end point of the second segment.
612     * @param y4
613     *            the y coordinate of the end point of the second segment.
614     * @return true, if the two line segments cross.
615     */
616    public static boolean linesIntersect(double x1, double y1, double x2, double y2, double x3,
617            double y3, double x4, double y4) {
618        /*
619         * A = (x2-x1, y2-y1) B = (x3-x1, y3-y1) C = (x4-x1, y4-y1) D = (x4-x3,
620         * y4-y3) = C-B E = (x1-x3, y1-y3) = -B F = (x2-x3, y2-y3) = A-B Result
621         * is ((AxB) (AxC) <=0) and ((DxE) (DxF) <= 0) DxE = (C-B)x(-B) =
622         * BxB-CxB = BxC DxF = (C-B)x(A-B) = CxA-CxB-BxA+BxB = AxB+BxC-AxC
623         */
624
625        x2 -= x1; // A
626        y2 -= y1;
627        x3 -= x1; // B
628        y3 -= y1;
629        x4 -= x1; // C
630        y4 -= y1;
631
632        double AvB = x2 * y3 - x3 * y2;
633        double AvC = x2 * y4 - x4 * y2;
634
635        // Online
636        if (AvB == 0.0 && AvC == 0.0) {
637            if (x2 != 0.0) {
638                return (x4 * x3 <= 0.0)
639                        || ((x3 * x2 >= 0.0) && (x2 > 0.0 ? x3 <= x2 || x4 <= x2 : x3 >= x2
640                                || x4 >= x2));
641            }
642            if (y2 != 0.0) {
643                return (y4 * y3 <= 0.0)
644                        || ((y3 * y2 >= 0.0) && (y2 > 0.0 ? y3 <= y2 || y4 <= y2 : y3 >= y2
645                                || y4 >= y2));
646            }
647            return false;
648        }
649
650        double BvC = x3 * y4 - x4 * y3;
651
652        return (AvB * AvC <= 0.0) && (BvC * (AvB + BvC - AvC) <= 0.0);
653    }
654
655    /**
656     * Tells whether the specified line segments crosses this line segment.
657     *
658     * @param x1
659     *            the x coordinate of the starting point of the test segment.
660     * @param y1
661     *            the y coordinate of the starting point of the test segment.
662     * @param x2
663     *            the x coordinate of the end point of the test segment.
664     * @param y2
665     *            the y coordinate of the end point of the test segment.
666     * @return true, if the specified line segments crosses this line segment.
667     */
668    public boolean intersectsLine(double x1, double y1, double x2, double y2) {
669        return linesIntersect(x1, y1, x2, y2, getX1(), getY1(), getX2(), getY2());
670    }
671
672    /**
673     * Tells whether the specified line segments crosses this line segment.
674     *
675     * @param l
676     *            the test segment.
677     * @return true, if the specified line segments crosses this line segment.
678     * @throws NullPointerException
679     *             if l is null.
680     */
681    public boolean intersectsLine(Line2D l) {
682        return linesIntersect(l.getX1(), l.getY1(), l.getX2(), l.getY2(), getX1(), getY1(),
683                getX2(), getY2());
684    }
685
686    /**
687     * Gives the square of the distance between the point and the line segment.
688     *
689     * @param x1
690     *            the x coordinate of the starting point of the line segment.
691     * @param y1
692     *            the y coordinate of the starting point of the line segment.
693     * @param x2
694     *            the x coordinate of the end point of the line segment.
695     * @param y2
696     *            the y coordinate of the end point of the line segment.
697     * @param px
698     *            the x coordinate of the test point.
699     * @param py
700     *            the y coordinate of the test point.
701     * @return the the square of the distance between the point and the line
702     *         segment.
703     */
704    public static double ptSegDistSq(double x1, double y1, double x2, double y2, double px,
705            double py) {
706        /*
707         * A = (x2 - x1, y2 - y1) P = (px - x1, py - y1)
708         */
709        x2 -= x1; // A = (x2, y2)
710        y2 -= y1;
711        px -= x1; // P = (px, py)
712        py -= y1;
713        double dist;
714        if (px * x2 + py * y2 <= 0.0) { // P*A
715            dist = px * px + py * py;
716        } else {
717            px = x2 - px; // P = A - P = (x2 - px, y2 - py)
718            py = y2 - py;
719            if (px * x2 + py * y2 <= 0.0) { // P*A
720                dist = px * px + py * py;
721            } else {
722                dist = px * y2 - py * x2;
723                dist = dist * dist / (x2 * x2 + y2 * y2); // pxA/|A|
724            }
725        }
726        if (dist < 0) {
727            dist = 0;
728        }
729        return dist;
730    }
731
732    /**
733     * Gives the distance between the point and the line segment.
734     *
735     * @param x1
736     *            the x coordinate of the starting point of the line segment.
737     * @param y1
738     *            the y coordinate of the starting point of the line segment.
739     * @param x2
740     *            the x coordinate of the end point of the line segment.
741     * @param y2
742     *            the y coordinate of the end point of the line segment.
743     * @param px
744     *            the x coordinate of the test point.
745     * @param py
746     *            the y coordinate of the test point.
747     * @return the the distance between the point and the line segment.
748     */
749    public static double ptSegDist(double x1, double y1, double x2, double y2, double px, double py) {
750        return Math.sqrt(ptSegDistSq(x1, y1, x2, y2, px, py));
751    }
752
753    /**
754     * Gives the square of the distance between the point and this line segment.
755     *
756     * @param px
757     *            the x coordinate of the test point.
758     * @param py
759     *            the y coordinate of the test point.
760     * @return the the square of the distance between the point and this line
761     *         segment.
762     */
763    public double ptSegDistSq(double px, double py) {
764        return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), px, py);
765    }
766
767    /**
768     * Gives the square of the distance between the point and this line segment.
769     *
770     * @param p
771     *            the test point.
772     * @return the square of the distance between the point and this line
773     *         segment.
774     */
775    public double ptSegDistSq(Point2D p) {
776        return ptSegDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
777    }
778
779    /**
780     * Gives the distance between the point and this line segment.
781     *
782     * @param px
783     *            the x coordinate of the test point.
784     * @param py
785     *            the y coordinate of the test point.
786     * @return the distance between the point and this line segment.
787     */
788    public double ptSegDist(double px, double py) {
789        return ptSegDist(getX1(), getY1(), getX2(), getY2(), px, py);
790    }
791
792    /**
793     * Gives the distance between the point and this line segment.
794     *
795     * @param p
796     *            the test point.
797     * @return the distance between the point and this line segment.
798     */
799    public double ptSegDist(Point2D p) {
800        return ptSegDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
801    }
802
803    /**
804     * Gives the square of the distance between the point and the line.
805     *
806     * @param x1
807     *            the x coordinate of the starting point of the line segment.
808     * @param y1
809     *            the y coordinate of the starting point of the line segment.
810     * @param x2
811     *            the x coordinate of the end point of the line segment.
812     * @param y2
813     *            the y coordinate of the end point of the line segment.
814     * @param px
815     *            the x coordinate of the test point.
816     * @param py
817     *            the y coordinate of the test point.
818     * @return the square of the distance between the point and the line.
819     */
820    public static double ptLineDistSq(double x1, double y1, double x2, double y2, double px,
821            double py) {
822        x2 -= x1;
823        y2 -= y1;
824        px -= x1;
825        py -= y1;
826        double s = px * y2 - py * x2;
827        return s * s / (x2 * x2 + y2 * y2);
828    }
829
830    /**
831     * Gives the square of the distance between the point and the line.
832     *
833     * @param x1
834     *            the x coordinate of the starting point of the line segment.
835     * @param y1
836     *            the y coordinate of the starting point of the line segment.
837     * @param x2
838     *            the x coordinate of the end point of the line segment.
839     * @param y2
840     *            the y coordinate of the end point of the line segment.
841     * @param px
842     *            the x coordinate of the test point.
843     * @param py
844     *            the y coordinate of the test point.
845     * @return the square of the distance between the point and the line.
846     */
847    public static double ptLineDist(double x1, double y1, double x2, double y2, double px, double py) {
848        return Math.sqrt(ptLineDistSq(x1, y1, x2, y2, px, py));
849    }
850
851    /**
852     * Gives the square of the distance between the point and the line
853     * determined by this Line2D.
854     *
855     * @param px
856     *            the x coordinate of the test point.
857     * @param py
858     *            the y coordinate of the test point.
859     * @return the square of the distance between the point and the line
860     *         determined by this Line2D.
861     */
862    public double ptLineDistSq(double px, double py) {
863        return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), px, py);
864    }
865
866    /**
867     * Gives the square of the distance between the point and the line
868     * determined by this Line2D.
869     *
870     * @param p
871     *            the test point.
872     * @return the square of the distance between the point and the line
873     *         determined by this Line2D.
874     */
875    public double ptLineDistSq(Point2D p) {
876        return ptLineDistSq(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
877    }
878
879    /**
880     * Gives the distance between the point and the line determined by this
881     * Line2D.
882     *
883     * @param px
884     *            the x coordinate of the test point.
885     * @param py
886     *            the y coordinate of the test point.
887     * @return the distance between the point and the line determined by this
888     *         Line2D.
889     */
890    public double ptLineDist(double px, double py) {
891        return ptLineDist(getX1(), getY1(), getX2(), getY2(), px, py);
892    }
893
894    /**
895     * Gives the distance between the point and the line determined by this
896     * Line2D.
897     *
898     * @param p
899     *            the test point.
900     * @return the distance between the point and the line determined by this
901     *         Line2D.
902     */
903    public double ptLineDist(Point2D p) {
904        return ptLineDist(getX1(), getY1(), getX2(), getY2(), p.getX(), p.getY());
905    }
906
907    public boolean contains(double px, double py) {
908        return false;
909    }
910
911    public boolean contains(Point2D p) {
912        return false;
913    }
914
915    public boolean contains(Rectangle2D r) {
916        return false;
917    }
918
919    public boolean contains(double rx, double ry, double rw, double rh) {
920        return false;
921    }
922
923    public boolean intersects(double rx, double ry, double rw, double rh) {
924        return intersects(new Rectangle2D.Double(rx, ry, rw, rh));
925    }
926
927    public boolean intersects(Rectangle2D r) {
928        return r.intersectsLine(getX1(), getY1(), getX2(), getY2());
929    }
930
931    public PathIterator getPathIterator(AffineTransform at) {
932        return new Iterator(this, at);
933    }
934
935    public PathIterator getPathIterator(AffineTransform at, double flatness) {
936        return new Iterator(this, at);
937    }
938
939    @Override
940    public Object clone() {
941        try {
942            return super.clone();
943        } catch (CloneNotSupportedException e) {
944            throw new InternalError();
945        }
946    }
947
948}
949