1 package org.opentrafficsim.base.geometry;
2
3 import java.util.Iterator;
4
5 import org.djutils.draw.Transform2d;
6 import org.djutils.draw.line.PolyLine2d;
7 import org.djutils.draw.line.Polygon2d;
8 import org.djutils.draw.point.OrientedPoint2d;
9 import org.djutils.draw.point.Point2d;
10
11
12
13
14
15
16
17
18
19 public class BoundingPolygon implements OtsBounds2d
20 {
21
22
23 private final Polygon2d polygon;
24
25
26
27
28
29 public BoundingPolygon(final Polygon2d polygon)
30 {
31 this.polygon = polygon;
32 }
33
34
35 @Override
36 public Polygon2d asPolygon()
37 {
38 return this.polygon;
39 }
40
41
42
43
44
45
46
47 public static BoundingPolygon geometryToBounds(final OrientedPoint2d location, final PolyLine2d geometry)
48 {
49 Transform2d transformation = OtsRenderable.toBoundsTransform(location);
50 Iterator<Point2d> itSource = geometry.getPoints();
51 Iterator<Point2d> itTarget = new Iterator<>()
52 {
53
54 @Override
55 public boolean hasNext()
56 {
57 return itSource.hasNext();
58 }
59
60
61 @Override
62 public Point2d next()
63 {
64 return transformation.transform(itSource.next());
65 }
66 };
67 BoundingPolygon b = new BoundingPolygon(new Polygon2d(itTarget));
68 return b;
69 }
70
71 }