1 package org.opentrafficsim.animation.data;
2
3 import java.awt.Color;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.djutils.draw.bounds.Bounds2d;
7 import org.djutils.draw.line.PolyLine2d;
8 import org.djutils.draw.line.Polygon2d;
9 import org.djutils.draw.point.OrientedPoint2d;
10 import org.opentrafficsim.base.geometry.OtsLocatable;
11 import org.opentrafficsim.base.geometry.OtsShape;
12 import org.opentrafficsim.draw.ClickableLocatable;
13 import org.opentrafficsim.draw.road.ConflictAnimation.ConflictData;
14 import org.opentrafficsim.road.network.lane.conflict.Conflict;
15
16
17
18
19
20
21
22
23
24 public class AnimationConflictData implements ConflictData
25 {
26
27
28 private final Conflict conflict;
29
30
31 private OtsShape shape;
32
33
34
35
36
37 public AnimationConflictData(final Conflict conflict)
38 {
39 this.conflict = conflict;
40 }
41
42 @Override
43 public Length getLaneWidth()
44 {
45 return this.conflict.getLane().getWidth(this.conflict.getLongitudinalPosition());
46 }
47
48 @Override
49 public OrientedPoint2d getLocation()
50 {
51 return this.conflict.getLocation();
52 }
53
54 @Override
55 public String getId()
56 {
57 return this.conflict.getFullId();
58 }
59
60 @Override
61 public Color getColor()
62 {
63 switch (this.conflict.conflictPriority())
64 {
65 case SPLIT:
66 return Color.BLUE;
67 case PRIORITY:
68 return Color.GREEN;
69 case YIELD:
70 return Color.ORANGE;
71 default:
72 return Color.RED;
73 }
74 }
75
76 @Override
77 public Bounds2d getBounds()
78 {
79 return ClickableLocatable.getBounds(this);
80 }
81
82 @Override
83 public Polygon2d getContour()
84 {
85 return this.conflict.getContour();
86 }
87
88 @Override
89 public OtsShape getShape()
90 {
91 if (this.shape == null)
92 {
93 this.shape = ConflictData.super.getShape();
94 }
95 return this.shape;
96 }
97
98 @Override
99 public PolyLine2d getLine()
100 {
101 return OtsLocatable.transformLine(this.conflict.getLine(), getLocation());
102 }
103
104 @Override
105 public boolean isCrossing()
106 {
107 return this.conflict.getConflictType().isCrossing();
108 }
109
110 @Override
111 public boolean isPermitted()
112 {
113 return this.conflict.isPermitted();
114 }
115
116
117
118
119
120 public Conflict getConflict()
121 {
122 return this.conflict;
123 }
124
125 @Override
126 public String toString()
127 {
128 return "Conflict " + this.conflict.getLane().getFullId() + " " + this.conflict.getLongitudinalPosition();
129 }
130
131 }