1 | package org.openstreetmap.josm.data.osm;
|
---|
2 |
|
---|
3 | import org.openstreetmap.josm.data.osm.visitor.Visitor;
|
---|
4 |
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * One way line segment consisting of a pair of nodes (from/to)
|
---|
8 | *
|
---|
9 | * @author imi
|
---|
10 | */
|
---|
11 | public class LineSegment extends OsmPrimitive {
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * The starting node of the line segment
|
---|
15 | */
|
---|
16 | public Node from;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * The ending node of the line segment
|
---|
20 | */
|
---|
21 | public Node to;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * If set to true, this object is incomplete, which means only the id
|
---|
25 | * and type is known (type is the objects instance class)
|
---|
26 | */
|
---|
27 | public boolean incomplete;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Create an line segment from the given starting and ending node
|
---|
31 | * @param from Starting node of the line segment.
|
---|
32 | * @param to Ending node of the line segment.
|
---|
33 | */
|
---|
34 | public LineSegment(Node from, Node to) {
|
---|
35 | this.from = from;
|
---|
36 | this.to = to;
|
---|
37 | incomplete = false;
|
---|
38 | }
|
---|
39 |
|
---|
40 | public LineSegment(long id) {
|
---|
41 | this.id = id;
|
---|
42 | incomplete = true;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public void visit(Visitor visitor) {
|
---|
47 | visitor.visit(this);
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * @return <code>true</code>, if the <code>ls</code> occupy
|
---|
52 | * exactly the same place as <code>this</code>.
|
---|
53 | */
|
---|
54 | public boolean equalPlace(LineSegment ls) {
|
---|
55 | if (equals(ls))
|
---|
56 | return true;
|
---|
57 | if (incomplete || ls.incomplete)
|
---|
58 | return incomplete == ls.incomplete;
|
---|
59 | return ((from.coor.equals(ls.from.coor) && to.coor.equals(ls.to.coor)) ||
|
---|
60 | (from.coor.equals(ls.to.coor) && to.coor.equals(ls.from.coor)));
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public String toString() {
|
---|
65 | String s = "{LineSegment id="+id;
|
---|
66 | if (incomplete)
|
---|
67 | return s+",incomplete}";
|
---|
68 | return s+",from="+from+",to="+to+"}";
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public void cloneFrom(OsmPrimitive osm) {
|
---|
73 | super.cloneFrom(osm);
|
---|
74 | LineSegment ls = ((LineSegment)osm);
|
---|
75 | from = ls.from;
|
---|
76 | to = ls.to;
|
---|
77 | incomplete = ls.incomplete;
|
---|
78 | }
|
---|
79 | }
|
---|