1    /*
2    Copyright 2000 by Ralph Hartley
3    This software is licenced under the terms of the
4    Gnu Public Licence
5    */
6    import java.awt.geom.*;
7    
8    public class LazyCubic extends CubicCurve2D {
9    
10     ViewTransform p1;
11     ViewTransform p2;
12     Point2D ctrlP1;
13     Point2D ctrlP2;
14   
15     public LazyCubic(ViewTransform p1,Point2D ctrlp1,Point2D ctrlp2,ViewTransform p2){
16       this.p1 = p1;
17       this.p2 = p2;
18       this.ctrlP1 = ctrlp1;
19       this.ctrlP2 = ctrlp2;
20     }
21   
22     public Point2D  getCtrlP1() {
23       return(ctrlP1);
24     }
25   
26     public double  getCtrlX1() {
27       return(ctrlP1.getX());
28     }
29   
30     public double  getCtrlY1() {
31       return(ctrlP1.getY());
32     }
33   
34     public Point2D  getCtrlP2() {
35       return(ctrlP2);
36     }
37   
38     public double  getCtrlX2() {
39       return(ctrlP2.getX());
40     }
41   
42     public double  getCtrlY2() {
43       return(ctrlP2.getY());
44     }
45   
46     public Point2D  getP1() {
47       return(p1.getTranslation());
48     }
49   
50     public double  getX1() {
51       return(p1.getTranslateX());
52     }
53   
54     public double  getY1() {
55       return(p1.getTranslateY());
56     }
57   
58     public Point2D  getP2() {
59       return(p2.getTranslation());
60     }
61   
62     public double  getX2() {
63       return(p2.getTranslateX());
64     }
65   
66     public double  getY2() {
67       return(p2.getTranslateY());
68     }
69   
70     public void setCurve(double x1, double y1, double ctrlx1, double ctrly1,
71           	double ctrlx2, double ctrly2, double x2, double y2) {
72       p1 = new ViewTransform(x1,y1);
73       p2 = new ViewTransform(x2,y2);
74       ctrlP1 = new Point2D.Double(ctrlx1,ctrly1);
75       ctrlP2 = new Point2D.Double(ctrlx2,ctrly2);
76     }
77   
78     public Rectangle2D getBounds2D() {
79       double minx = p1.getTranslateX();
80       double maxx = minx;
81       if (p2.getTranslateX()<minx) minx = p2.getTranslateX();
82       if (p2.getTranslateX()>maxx) maxx = p2.getTranslateX();
83       if (ctrlP1.getX()<minx) minx = ctrlP1.getX();
84       if (ctrlP1.getX()>maxx) maxx = ctrlP1.getX();
85       if (ctrlP2.getX()<minx) minx = ctrlP2.getX();
86       if (ctrlP2.getX()>maxx) maxx = ctrlP2.getX();
87   
88       double miny = p1.getTranslateY();
89       double maxy = miny;
90       if (p2.getTranslateY()<miny) miny = p2.getTranslateY();
91       if (p2.getTranslateY()>maxy) maxy = p2.getTranslateY();
92       if (ctrlP1.getY()<miny) miny = ctrlP1.getY();
93       if (ctrlP1.getY()>maxy) maxy = ctrlP1.getY();
94       if (ctrlP2.getY()<miny) miny = ctrlP2.getY();
95       if (ctrlP2.getY()>maxy) maxy = ctrlP2.getY();
96   
97       return new Rectangle2D.Double(minx,miny,maxx,maxy);
98     }
99   }
100  
101