1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.geometry.euclidean.threed;
18
19 import org.apache.commons.geometry.core.RegionLocation;
20 import org.apache.commons.geometry.core.internal.HyperplaneSubsets;
21 import org.apache.commons.geometry.euclidean.twod.BoundarySource2D;
22 import org.apache.commons.geometry.euclidean.twod.Bounds2D;
23 import org.apache.commons.geometry.euclidean.twod.Vector2D;
24
25
26
27
28 abstract class AbstractEmbeddedRegionPlaneSubset extends AbstractPlaneSubset implements PlaneSubset.Embedded {
29
30
31 private final EmbeddingPlane plane;
32
33
34
35
36 AbstractEmbeddedRegionPlaneSubset(final EmbeddingPlane plane) {
37 this.plane = plane;
38 }
39
40
41 @Override
42 public EmbeddingPlane getPlane() {
43 return plane;
44 }
45
46
47 @Override
48 public EmbeddingPlane getHyperplane() {
49 return getPlane();
50 }
51
52
53 @Override
54 public boolean isFull() {
55 return getSubspaceRegion().isFull();
56 }
57
58
59 @Override
60 public boolean isEmpty() {
61 return getSubspaceRegion().isEmpty();
62 }
63
64
65 @Override
66 public double getSize() {
67 return getSubspaceRegion().getSize();
68 }
69
70
71 @Override
72 public Vector3D getCentroid() {
73 final Vector2D subspaceCentroid = getSubspaceRegion().getCentroid();
74 if (subspaceCentroid != null) {
75 return getPlane().toSpace(subspaceCentroid);
76 }
77 return null;
78 }
79
80
81 @Override
82 public Vector3D toSpace(final Vector2D pt) {
83 return plane.toSpace(pt);
84 }
85
86
87 @Override
88 public Vector2D toSubspace(final Vector3D pt) {
89 return plane.toSubspace(pt);
90 }
91
92
93 @Override
94 public RegionLocation classify(final Vector3D pt) {
95 return HyperplaneSubsets.classifyAgainstEmbeddedRegion(pt, plane, getSubspaceRegion());
96 }
97
98
99 @Override
100 public Vector3D closest(final Vector3D pt) {
101 return HyperplaneSubsets.closestToEmbeddedRegion(pt, plane, getSubspaceRegion());
102 }
103
104
105 @Override
106 public String toString() {
107 final StringBuilder sb = new StringBuilder();
108 sb.append(getClass().getSimpleName())
109 .append("[plane= ")
110 .append(getPlane())
111 .append(", subspaceRegion= ")
112 .append(getSubspaceRegion())
113 .append(']');
114
115 return sb.toString();
116 }
117
118
119
120
121
122
123 protected Bounds3D getBoundsFromSubspace(final BoundarySource2D src) {
124 final Bounds2D subspaceBounds = src.getBounds();
125 if (subspaceBounds != null) {
126 final Vector3D min = plane.toSpace(subspaceBounds.getMin());
127 final Vector3D max = plane.toSpace(subspaceBounds.getMax());
128
129 return Bounds3D.builder()
130 .add(min)
131 .add(max)
132 .build();
133 }
134
135 return null;
136 }
137 }