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