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.*;
7    import java.awt.geom.*;
8    
9    class Line implements java.io.Serializable,Comparable {
10   
11     private static final long serialVersionUID = Version.getSUID();
12   
13           public VertexVertexstart
14   
15           public Line(Vertex v1,Vertex v2) {
16             if (v1.compareTo(v2)<0) { 
17               start=v1;
18               end=v2;
19             }else {
20               start=v2;
21               end=v1;
22             }
23           }
24   
25           public void draw(Graphics g,Matrix m) {
26             double[] spoint = m.XY(start.position);
27           	double[] fpoint = m.XY(end.position);
28           	g.drawLine((int)spoint[0],-(int)spoint[1],(int)fpoint[0],-(int)fpoint[1]);
29           }
30   
31     public void mapdraw(Graphics g, AffineTransform trans) {
32       Point2D point1 = start.mappos(trans);
33       Point2D point2 = end.mappos(trans);
34       g.drawLine((int)point1.getX(),(int)point1.getY(),(int)point2.getX(),(int)point2.getY());
35     }
36   
37     public void paint(View view) {
38       if (!view.visible.isMember(this)) return;
39       Point2D tpos1 = new Point2D.Double(start.position.X[0],start.position.X[1]);
40       Point2D tpos2 = new Point2D.Double(end.position.X[0],end.position.X[1]);
41       view.trans.transform(tpos1,tpos1);
42       view.trans.transform(tpos2,tpos2);
43       view.draw.drawLine((int)tpos1.getX(),(int)tpos1.getY(),
44           	       (int)tpos2.getX(),(int)tpos2.getY());
45     }
46   
47     public boolean equals(Object o) {
48       Line other = (Line)o;
49       return(other.start.equals(start) && other.end.equals(end));
50     }
51   
52     public int compareTo(Object o) {
53       Line other = (Line)o;
54       int res = start.compareTo(other.start);
55       if (res!= 0) return(res);
56       return(end.compareTo(other.end));
57     }
58   }
59   
60   ??????????????????????end?????????Line??????????????Vertex????????????????????????Vertex???????????compareTo??????????????draw??????????????????????????????Matrix????????????????????????XY???????????????????????????start?????????????????????????????????position???????????????????????XY??????????????????????????end??????????????????????????????position???????????????mapdraw??????????????????????start????????????????????????????mappos??????????????????????end??????????????????????????mappos???????????????paint?????????????????????View???????????????visible???????????????????????isMember????????????????????????????????????????start??????????????????????????????????????????????position???????????????????????????????????????????????????????X????????????????????????????????????????????????????????????start??????????????????????????????????????????????????????????????????position???????????????????????????????????????????????????????????????????????????X????????????????????????????????????????end????????????????????????????????????????????position?????????????????????????????????????????????????????X??????????????????????????????????????????????????????????end??????????????????????????????????????????????????????????????position???????????????????????????????????????????????????????????????????????X??????????trans??????????trans??????????draw??????????????????equals?????Line???????????????????Line??????????????????start????????????????????????equals???????????????????????????????start???????????????????????????????????????????????end???????????????????????????????????????????????????equals??????????????????????????????????????????????????????????end??????????????compareTo?????Line???????????????????Line???????????????start?????????????????????compareTo?????????????????????????????????????start????????????end????????????????compareTo????????????????????????????????end