1
2
3
4
5
6
7
8
9 package math.geom2d.circulinear;
10
11 import java.util.ArrayList;
12 import java.util.Collection;
13
14 import math.geom2d.Shape2D;
15
16
17
18
19
20
21
22 public class CirculinearDomain2DUtils {
23
24 public final static CirculinearDomain2D computeBuffer(
25 CirculinearDomain2D domain, double dist) {
26
27 ArrayList<CirculinearContour2D> rings =
28 new ArrayList<CirculinearContour2D>();
29
30
31 for(CirculinearContour2D cont :
32 domain.getBoundary().getContinuousCurves()) {
33
34 for(CirculinearContinuousCurve2D simpleCurve :
35 CirculinearCurve2DUtils.splitContinuousCurve(cont)) {
36 CirculinearContour2D boundary =
37 new BoundaryPolyCirculinearCurve2D<CirculinearContinuousCurve2D>(
38 simpleCurve.getSmoothPieces());
39
40 rings.addAll(computeBufferSimpleRing(boundary, dist));
41 }
42 }
43
44
45
46 return new GenericCirculinearDomain2D(
47 new CirculinearBoundarySet2D<CirculinearContour2D>(rings));
48 }
49
50
51
52
53
54 public final static Collection<CirculinearContour2D>
55 computeBufferSimpleRing(CirculinearContour2D curve, double d) {
56
57
58 ArrayList<CirculinearContour2D> rings =
59 new ArrayList<CirculinearContour2D>();
60
61
62 CirculinearContinuousCurve2D parallel1 = curve.getParallel(d);
63
64
65 CirculinearCurveSet2D<CirculinearContinuousCurve2D> curves =
66 new CirculinearCurveSet2D<CirculinearContinuousCurve2D>();
67
68
69 for(CirculinearContinuousCurve2D split :
70 CirculinearCurve2DUtils.splitContinuousCurve(parallel1)) {
71 if(CirculinearCurve2DUtils.findIntersections(curve, split).size()==0)
72 curves.addCurve(split);
73 }
74
75
76 for(CirculinearContinuousCurve2D split : curves) {
77 rings.add(
78 new BoundaryPolyCirculinearCurve2D<CirculinearContinuousCurve2D>(
79 split.getSmoothPieces(), split.isClosed()));
80 }
81
82
83 ArrayList<CirculinearContour2D> rings2 =
84 new ArrayList<CirculinearContour2D>();
85
86
87 for(CirculinearContour2D ring : rings)
88
89 for(CirculinearContinuousCurve2D split :
90 CirculinearCurve2DUtils.splitContinuousCurve(ring)) {
91
92
93
94
95 double dist = CirculinearCurve2DUtils.getDistanceCurvePoints(
96 curve, split.getSingularPoints());
97
98
99 if(dist-d<-Shape2D.ACCURACY)
100 continue;
101
102
103 rings2.add(
104 new BoundaryPolyCirculinearCurve2D<CirculinearContinuousCurve2D>(
105 split.getSmoothPieces(), split.isClosed()));
106 }
107
108
109 return rings2;
110 }
111 }