Skip to content

Commit 333db67

Browse files
committed
Another round of types parameterization in geometry.
Fixes #368
1 parent 0e22bd7 commit 333db67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1131
-1006
lines changed

hipparchus-geometry/src/changes/changes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ If the output is not quite correct, check for invisible trailing spaces!
5050
</properties>
5151
<release version="4.0" date="TBD" description="TBD">
5252
<action dev="luc" type="fix" issue="issues/368">
53-
Added point type to geometry classes parameters
53+
Added point, hyperplane and sub-hyperplane types to geometry classes parameters
5454
</action>
5555
<action dev="luc" type="update" issue="issues/314">
5656
Improved robustness of BSP tree operations

hipparchus-geometry/src/main/java/org/hipparchus/geometry/euclidean/oned/IntervalsSet.java

Lines changed: 48 additions & 42 deletions
Large diffs are not rendered by default.

hipparchus-geometry/src/main/java/org/hipparchus/geometry/euclidean/oned/OrientedPoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* boolean.</p>
2929
* <p>Instances of this class are guaranteed to be immutable.</p>
3030
*/
31-
public class OrientedPoint implements Hyperplane<Euclidean1D, Vector1D> {
31+
public class OrientedPoint implements Hyperplane<Euclidean1D, Vector1D, OrientedPoint, SubOrientedPoint> {
3232

3333
/** Vector location. */
3434
private final Vector1D location;
@@ -111,8 +111,8 @@ public IntervalsSet wholeSpace() {
111111

112112
/** {@inheritDoc} */
113113
@Override
114-
public boolean sameOrientationAs(final Hyperplane<Euclidean1D, Vector1D> other) {
115-
return direct == ((OrientedPoint) other).direct;
114+
public boolean sameOrientationAs(final OrientedPoint other) {
115+
return direct == other.direct;
116116
}
117117

118118
/** {@inheritDoc}

hipparchus-geometry/src/main/java/org/hipparchus/geometry/euclidean/oned/SubOrientedPoint.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,23 @@
2222
package org.hipparchus.geometry.euclidean.oned;
2323

2424
import org.hipparchus.geometry.partitioning.AbstractSubHyperplane;
25-
import org.hipparchus.geometry.partitioning.Hyperplane;
2625
import org.hipparchus.geometry.partitioning.Region;
2726

2827
/** This class represents sub-hyperplane for {@link OrientedPoint}.
2928
* <p>An hyperplane in 1D is a simple point, its orientation being a
3029
* boolean.</p>
3130
* <p>Instances of this class are guaranteed to be immutable.</p>
3231
*/
33-
public class SubOrientedPoint extends AbstractSubHyperplane<Euclidean1D, Vector1D, Euclidean1D, Vector1D> {
32+
public class SubOrientedPoint
33+
extends AbstractSubHyperplane<Euclidean1D, Vector1D, OrientedPoint, SubOrientedPoint,
34+
Euclidean1D, Vector1D, OrientedPoint, SubOrientedPoint> {
3435

3536
/** Simple constructor.
3637
* @param hyperplane underlying hyperplane
3738
* @param remainingRegion remaining region of the hyperplane
3839
*/
39-
public SubOrientedPoint(final Hyperplane<Euclidean1D, Vector1D> hyperplane,
40-
final Region<Euclidean1D, Vector1D> remainingRegion) {
40+
public SubOrientedPoint(final OrientedPoint hyperplane,
41+
final Region<Euclidean1D, Vector1D, OrientedPoint, SubOrientedPoint> remainingRegion) {
4142
super(hyperplane, remainingRegion);
4243
}
4344

@@ -55,16 +56,15 @@ public boolean isEmpty() {
5556

5657
/** {@inheritDoc} */
5758
@Override
58-
protected AbstractSubHyperplane<Euclidean1D, Vector1D, Euclidean1D, Vector1D>
59-
buildNew(final Hyperplane<Euclidean1D, Vector1D> hyperplane,
60-
final Region<Euclidean1D, Vector1D> remainingRegion) {
59+
protected SubOrientedPoint buildNew(final OrientedPoint hyperplane,
60+
final Region<Euclidean1D, Vector1D, OrientedPoint, SubOrientedPoint> remainingRegion) {
6161
return new SubOrientedPoint(hyperplane, remainingRegion);
6262
}
6363

6464
/** {@inheritDoc} */
6565
@Override
66-
public SplitSubHyperplane<Euclidean1D, Vector1D> split(final Hyperplane<Euclidean1D, Vector1D> hyperplane) {
67-
final double global = hyperplane.getOffset(((OrientedPoint) getHyperplane()).getLocation());
66+
public SplitSubHyperplane<Euclidean1D, Vector1D, OrientedPoint, SubOrientedPoint> split(final OrientedPoint hyperplane) {
67+
final double global = hyperplane.getOffset(getHyperplane().getLocation());
6868
if (global < -hyperplane.getTolerance()) {
6969
return new SplitSubHyperplane<>(null, this);
7070
} else if (global > hyperplane.getTolerance()) {

hipparchus-geometry/src/main/java/org/hipparchus/geometry/euclidean/threed/OutlineExtractor.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import java.util.ArrayList;
2525

2626
import org.hipparchus.geometry.euclidean.twod.Euclidean2D;
27+
import org.hipparchus.geometry.euclidean.twod.Line;
2728
import org.hipparchus.geometry.euclidean.twod.PolygonsSet;
29+
import org.hipparchus.geometry.euclidean.twod.SubLine;
2830
import org.hipparchus.geometry.euclidean.twod.Vector2D;
29-
import org.hipparchus.geometry.partitioning.AbstractSubHyperplane;
3031
import org.hipparchus.geometry.partitioning.BSPTree;
3132
import org.hipparchus.geometry.partitioning.BSPTreeVisitor;
3233
import org.hipparchus.geometry.partitioning.BoundaryAttribute;
3334
import org.hipparchus.geometry.partitioning.RegionFactory;
34-
import org.hipparchus.geometry.partitioning.SubHyperplane;
3535
import org.hipparchus.util.FastMath;
3636
import org.hipparchus.util.MathUtils;
3737

@@ -123,7 +123,7 @@ private boolean pointIsBetween(final Vector2D[] loop, final int n, final int i)
123123
}
124124

125125
/** Visitor projecting the boundary facets on a plane. */
126-
private class BoundaryProjector implements BSPTreeVisitor<Euclidean3D, Vector3D> {
126+
private class BoundaryProjector implements BSPTreeVisitor<Euclidean3D, Vector3D, Plane, SubPlane> {
127127

128128
/** Projection of the polyhedrons set on the plane. */
129129
private PolygonsSet projected;
@@ -141,16 +141,16 @@ private class BoundaryProjector implements BSPTreeVisitor<Euclidean3D, Vector3D>
141141

142142
/** {@inheritDoc} */
143143
@Override
144-
public Order visitOrder(final BSPTree<Euclidean3D, Vector3D> node) {
144+
public Order visitOrder(final BSPTree<Euclidean3D, Vector3D, Plane, SubPlane> node) {
145145
return Order.MINUS_SUB_PLUS;
146146
}
147147

148148
/** {@inheritDoc} */
149149
@Override
150-
public void visitInternalNode(final BSPTree<Euclidean3D, Vector3D> node) {
150+
public void visitInternalNode(final BSPTree<Euclidean3D, Vector3D, Plane, SubPlane> node) {
151151
@SuppressWarnings("unchecked")
152-
final BoundaryAttribute<Euclidean3D, Vector3D> attribute =
153-
(BoundaryAttribute<Euclidean3D, Vector3D>) node.getAttribute();
152+
final BoundaryAttribute<Euclidean3D, Vector3D, Plane, SubPlane> attribute =
153+
(BoundaryAttribute<Euclidean3D, Vector3D, Plane, SubPlane>) node.getAttribute();
154154
if (attribute.getPlusOutside() != null) {
155155
addContribution(attribute.getPlusOutside());
156156
}
@@ -161,23 +161,18 @@ public void visitInternalNode(final BSPTree<Euclidean3D, Vector3D> node) {
161161

162162
/** {@inheritDoc} */
163163
@Override
164-
public void visitLeafNode(final BSPTree<Euclidean3D, Vector3D> node) {
164+
public void visitLeafNode(final BSPTree<Euclidean3D, Vector3D, Plane, SubPlane> node) {
165165
}
166166

167167
/** Add he contribution of a boundary facet.
168168
* @param facet boundary facet
169169
*/
170-
private void addContribution(final SubHyperplane<Euclidean3D, Vector3D> facet) {
170+
private void addContribution(final SubPlane facet) {
171171

172-
// extract the vertices of the facet
173-
final AbstractSubHyperplane<Euclidean3D, Vector3D, Euclidean2D, Vector2D> absFacet =
174-
(AbstractSubHyperplane<Euclidean3D, Vector3D, Euclidean2D, Vector2D>) facet;
175-
final Plane plane = (Plane) facet.getHyperplane();
176-
177-
final double scal = plane.getNormal().dotProduct(w);
172+
final double scal = facet.getHyperplane().getNormal().dotProduct(w);
178173
if (FastMath.abs(scal) > 1.0e-3) {
179174
Vector2D[][] vertices =
180-
((PolygonsSet) absFacet.getRemainingRegion()).getVertices();
175+
((PolygonsSet) facet.getRemainingRegion()).getVertices();
181176

182177
if (scal < 0) {
183178
// the facet is seen from the back of the plane,
@@ -205,21 +200,21 @@ private void addContribution(final SubHyperplane<Euclidean3D, Vector3D> facet) {
205200
}
206201

207202
// compute the projection of the facet in the outline plane
208-
final ArrayList<SubHyperplane<Euclidean2D, Vector2D>> edges = new ArrayList<>();
203+
final ArrayList<SubLine> edges = new ArrayList<>();
209204
for (Vector2D[] loop : vertices) {
210205
final boolean closed = loop[0] != null;
211206
int previous = closed ? (loop.length - 1) : 1;
212-
final Vector3D previous3D = plane.toSpace(loop[previous]);
207+
final Vector3D previous3D = facet.getHyperplane().toSpace(loop[previous]);
213208
int current = (previous + 1) % loop.length;
214209
Vector2D pPoint = new Vector2D(previous3D.dotProduct(u), previous3D.dotProduct(v));
215210
while (current < loop.length) {
216211

217-
final Vector3D current3D = plane.toSpace(loop[current]);
212+
final Vector3D current3D = facet.getHyperplane().toSpace(loop[current]);
218213
final Vector2D cPoint = new Vector2D(current3D.dotProduct(u),
219214
current3D.dotProduct(v));
220215
final org.hipparchus.geometry.euclidean.twod.Line line =
221216
new org.hipparchus.geometry.euclidean.twod.Line(pPoint, cPoint, tolerance);
222-
SubHyperplane<Euclidean2D, Vector2D> edge = line.wholeHyperplane();
217+
SubLine edge = line.wholeHyperplane();
223218

224219
if (closed || (previous != 1)) {
225220
// the previous point is a real vertex
@@ -249,7 +244,8 @@ private void addContribution(final SubHyperplane<Euclidean3D, Vector3D> facet) {
249244
final PolygonsSet projectedFacet = new PolygonsSet(edges, tolerance);
250245

251246
// add the contribution of the facet to the global outline
252-
projected = (PolygonsSet) new RegionFactory<Euclidean2D, Vector2D>().union(projected, projectedFacet);
247+
final RegionFactory<Euclidean2D, Vector2D, Line, SubLine> factory = new RegionFactory<>();
248+
projected = (PolygonsSet) factory.union(projected, projectedFacet);
253249

254250
}
255251
}

hipparchus-geometry/src/main/java/org/hipparchus/geometry/euclidean/threed/Plane.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.hipparchus.geometry.euclidean.oned.Vector1D;
2727
import org.hipparchus.geometry.euclidean.twod.Euclidean2D;
2828
import org.hipparchus.geometry.euclidean.twod.PolygonsSet;
29+
import org.hipparchus.geometry.euclidean.twod.SubLine;
2930
import org.hipparchus.geometry.euclidean.twod.Vector2D;
3031
import org.hipparchus.geometry.partitioning.Embedding;
3132
import org.hipparchus.geometry.partitioning.Hyperplane;
@@ -35,8 +36,8 @@
3536
/** The class represent planes in a three dimensional space.
3637
*/
3738
public class Plane
38-
implements Hyperplane<Euclidean3D, Vector3D>,
39-
Embedding<Euclidean3D, Vector3D, Euclidean2D, Vector2D> {
39+
implements Hyperplane<Euclidean3D, Vector3D, Plane, SubPlane>,
40+
Embedding<Euclidean3D, Vector3D, Euclidean2D, Vector2D> {
4041

4142
/** Offset of the origin with respect to the plane. */
4243
private double originOffset;
@@ -414,7 +415,8 @@ public SubPlane wholeHyperplane() {
414415
/** {@inheritDoc} */
415416
@Override
416417
public SubPlane emptyHyperplane() {
417-
return new SubPlane(this, new RegionFactory<Euclidean2D, Vector2D>().getComplement(new PolygonsSet(tolerance)));
418+
final RegionFactory<Euclidean2D, Vector2D, org.hipparchus.geometry.euclidean.twod.Line, SubLine> factory = new RegionFactory<>();
419+
return new SubPlane(this, factory.getComplement(new PolygonsSet(tolerance)));
418420
}
419421

420422
/** Build a region covering the whole space.
@@ -467,8 +469,8 @@ public double getOffset(final Vector3D point) {
467469
* the same orientation
468470
*/
469471
@Override
470-
public boolean sameOrientationAs(final Hyperplane<Euclidean3D, Vector3D> other) {
471-
return (((Plane) other).w).dotProduct(w) > 0.0;
472+
public boolean sameOrientationAs(final Plane other) {
473+
return other.w.dotProduct(w) > 0.0;
472474
}
473475

474476
}

0 commit comments

Comments
 (0)