Skip to content

Commit

Permalink
Merge branch 'issue-368'
Browse files Browse the repository at this point in the history
  • Loading branch information
maisonobe committed Jan 26, 2025
2 parents 2b5ed95 + c22c05e commit 2bd5f97
Show file tree
Hide file tree
Showing 61 changed files with 1,533 additions and 1,478 deletions.
6 changes: 6 additions & 0 deletions hipparchus-geometry/src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ If the output is not quite correct, check for invisible trailing spaces!
<title>Hipparchus Geometry Release Notes</title>
</properties>
<release version="4.0" date="TBD" description="TBD">
<action dev="luc" type="fix" issue="issues/368">
Added point type to geometry classes parameters
</action>
<action dev="luc" type="update" issue="issues/314">
Improved robustness of BSP tree operations
</action>
<action dev="vincent" type="update" issue="issues/285">
Migrated tests from JUnit 4 to JUnit 5
</action>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
*/
package org.hipparchus.geometry.euclidean.oned;

import org.hipparchus.geometry.Point;
import org.hipparchus.geometry.Vector;
import org.hipparchus.geometry.partitioning.Hyperplane;

/** This class represents a 1D oriented hyperplane.
* <p>An hyperplane in 1D is a simple point, its orientation being a
* boolean.</p>
* <p>Instances of this class are guaranteed to be immutable.</p>
*/
public class OrientedPoint implements Hyperplane<Euclidean1D> {
public class OrientedPoint implements Hyperplane<Euclidean1D, Vector1D> {

/** Vector location. */
private final Vector1D location;
Expand Down Expand Up @@ -63,18 +61,10 @@ public OrientedPoint copySelf() {
return this;
}

/** Get the offset (oriented distance) of a vector.
* @param vector vector to check
* @return offset of the vector
*/
public double getOffset(Vector<Euclidean1D, Vector1D> vector) {
return getOffset((Point<Euclidean1D>) vector);
}

/** {@inheritDoc} */
@Override
public double getOffset(final Point<Euclidean1D> point) {
final double delta = ((Vector1D) point).getX() - location.getX();
public double getOffset(final Vector1D point) {
final double delta = point.getX() - location.getX();
return direct ? delta : -delta;
}

Expand Down Expand Up @@ -121,14 +111,14 @@ public IntervalsSet wholeSpace() {

/** {@inheritDoc} */
@Override
public boolean sameOrientationAs(final Hyperplane<Euclidean1D> other) {
return !(direct ^ ((OrientedPoint) other).direct);
public boolean sameOrientationAs(final Hyperplane<Euclidean1D, Vector1D> other) {
return direct == ((OrientedPoint) other).direct;
}

/** {@inheritDoc}
*/
@Override
public Point<Euclidean1D> project(Point<Euclidean1D> point) {
public Vector1D project(Vector1D point) {
return location;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
* boolean.</p>
* <p>Instances of this class are guaranteed to be immutable.</p>
*/
public class SubOrientedPoint extends AbstractSubHyperplane<Euclidean1D, Euclidean1D> {
public class SubOrientedPoint extends AbstractSubHyperplane<Euclidean1D, Vector1D, Euclidean1D, Vector1D> {

/** Simple constructor.
* @param hyperplane underlying hyperplane
* @param remainingRegion remaining region of the hyperplane
*/
public SubOrientedPoint(final Hyperplane<Euclidean1D> hyperplane,
final Region<Euclidean1D> remainingRegion) {
public SubOrientedPoint(final Hyperplane<Euclidean1D, Vector1D> hyperplane,
final Region<Euclidean1D, Vector1D> remainingRegion) {
super(hyperplane, remainingRegion);
}

Expand All @@ -55,21 +55,22 @@ public boolean isEmpty() {

/** {@inheritDoc} */
@Override
protected AbstractSubHyperplane<Euclidean1D, Euclidean1D> buildNew(final Hyperplane<Euclidean1D> hyperplane,
final Region<Euclidean1D> remainingRegion) {
protected AbstractSubHyperplane<Euclidean1D, Vector1D, Euclidean1D, Vector1D>
buildNew(final Hyperplane<Euclidean1D, Vector1D> hyperplane,
final Region<Euclidean1D, Vector1D> remainingRegion) {
return new SubOrientedPoint(hyperplane, remainingRegion);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import org.hipparchus.exception.LocalizedCoreFormats;
import org.hipparchus.exception.MathIllegalArgumentException;
import org.hipparchus.geometry.Point;
import org.hipparchus.geometry.Vector;
import org.hipparchus.geometry.euclidean.oned.Euclidean1D;
import org.hipparchus.geometry.euclidean.oned.IntervalsSet;
import org.hipparchus.geometry.euclidean.oned.Vector1D;
Expand All @@ -44,7 +42,7 @@
* @see #fromDirection(Vector3D, Vector3D, double)
* @see #Line(Vector3D, Vector3D, double)
*/
public class Line implements Embedding<Euclidean3D, Euclidean1D> {
public class Line implements Embedding<Euclidean3D, Vector3D, Euclidean1D, Vector1D> {

/** Line direction. */
private Vector3D direction;
Expand Down Expand Up @@ -181,38 +179,20 @@ public Vector3D pointAt(final double abscissa) {
return new Vector3D(1.0, zero, abscissa, direction);
}

/** Transform a space point into a sub-space point.
* @param vector n-dimension point of the space
* @return (n-1)-dimension point of the sub-space corresponding to
* the specified space point
*/
public Vector1D toSubSpace(Vector<Euclidean3D, Vector3D> vector) {
return toSubSpace((Point<Euclidean3D>) vector);
}

/** Transform a sub-space point into a space point.
* @param vector (n-1)-dimension point of the sub-space
* @return n-dimension point of the space corresponding to the
* specified sub-space point
*/
public Vector3D toSpace(Vector<Euclidean1D, Vector1D> vector) {
return toSpace((Point<Euclidean1D>) vector);
}

/** {@inheritDoc}
* @see #getAbscissa(Vector3D)
*/
@Override
public Vector1D toSubSpace(final Point<Euclidean3D> point) {
return new Vector1D(getAbscissa((Vector3D) point));
public Vector1D toSubSpace(final Vector3D point) {
return new Vector1D(getAbscissa(point));
}

/** {@inheritDoc}
* @see #pointAt(double)
*/
@Override
public Vector3D toSpace(final Point<Euclidean1D> point) {
return pointAt(((Vector1D) point).getX());
public Vector3D toSpace(final Vector1D point) {
return pointAt(point.getX());
}

/** Check if the instance is similar to another line.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.util.ArrayList;

import org.hipparchus.geometry.Point;
import org.hipparchus.geometry.euclidean.twod.Euclidean2D;
import org.hipparchus.geometry.euclidean.twod.PolygonsSet;
import org.hipparchus.geometry.euclidean.twod.Vector2D;
Expand Down Expand Up @@ -123,7 +122,7 @@ private boolean pointIsBetween(final Vector2D[] loop, final int n, final int i)
}

/** Visitor projecting the boundary facets on a plane. */
private class BoundaryProjector implements BSPTreeVisitor<Euclidean3D> {
private class BoundaryProjector implements BSPTreeVisitor<Euclidean3D, Vector3D> {

/** Projection of the polyhedrons set on the plane. */
private PolygonsSet projected;
Expand All @@ -135,22 +134,22 @@ private class BoundaryProjector implements BSPTreeVisitor<Euclidean3D> {
* @param tolerance tolerance below which points are considered identical
*/
BoundaryProjector(final double tolerance) {
this.projected = new PolygonsSet(new BSPTree<Euclidean2D>(Boolean.FALSE), tolerance);
this.projected = new PolygonsSet(new BSPTree<>(Boolean.FALSE), tolerance);
this.tolerance = tolerance;
}

/** {@inheritDoc} */
@Override
public Order visitOrder(final BSPTree<Euclidean3D> node) {
public Order visitOrder(final BSPTree<Euclidean3D, Vector3D> node) {
return Order.MINUS_SUB_PLUS;
}

/** {@inheritDoc} */
@Override
public void visitInternalNode(final BSPTree<Euclidean3D> node) {
public void visitInternalNode(final BSPTree<Euclidean3D, Vector3D> node) {
@SuppressWarnings("unchecked")
final BoundaryAttribute<Euclidean3D> attribute =
(BoundaryAttribute<Euclidean3D>) node.getAttribute();
final BoundaryAttribute<Euclidean3D, Vector3D> attribute =
(BoundaryAttribute<Euclidean3D, Vector3D>) node.getAttribute();
if (attribute.getPlusOutside() != null) {
addContribution(attribute.getPlusOutside());
}
Expand All @@ -161,17 +160,17 @@ public void visitInternalNode(final BSPTree<Euclidean3D> node) {

/** {@inheritDoc} */
@Override
public void visitLeafNode(final BSPTree<Euclidean3D> node) {
public void visitLeafNode(final BSPTree<Euclidean3D, Vector3D> node) {
}

/** Add he contribution of a boundary facet.
* @param facet boundary facet
*/
private void addContribution(final SubHyperplane<Euclidean3D> facet) {
private void addContribution(final SubHyperplane<Euclidean3D, Vector3D> facet) {

// extract the vertices of the facet
final AbstractSubHyperplane<Euclidean3D, Euclidean2D> absFacet =
(AbstractSubHyperplane<Euclidean3D, Euclidean2D>) facet;
final AbstractSubHyperplane<Euclidean3D, Vector3D, Euclidean2D, Vector2D> absFacet =
(AbstractSubHyperplane<Euclidean3D, Vector3D, Euclidean2D, Vector2D>) facet;
final Plane plane = (Plane) facet.getHyperplane();

final double scal = plane.getNormal().dotProduct(w);
Expand Down Expand Up @@ -205,21 +204,21 @@ private void addContribution(final SubHyperplane<Euclidean3D> facet) {
}

// compute the projection of the facet in the outline plane
final ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<>();
final ArrayList<SubHyperplane<Euclidean2D, Vector2D>> edges = new ArrayList<>();
for (Vector2D[] loop : vertices) {
final boolean closed = loop[0] != null;
int previous = closed ? (loop.length - 1) : 1;
final Vector3D previous3D = plane.toSpace((Point<Euclidean2D>) loop[previous]);
final Vector3D previous3D = plane.toSpace(loop[previous]);
int current = (previous + 1) % loop.length;
Vector2D pPoint = new Vector2D(previous3D.dotProduct(u), previous3D.dotProduct(v));
while (current < loop.length) {

final Vector3D current3D = plane.toSpace((Point<Euclidean2D>) loop[current]);
final Vector3D current3D = plane.toSpace(loop[current]);
final Vector2D cPoint = new Vector2D(current3D.dotProduct(u),
current3D.dotProduct(v));
final org.hipparchus.geometry.euclidean.twod.Line line =
new org.hipparchus.geometry.euclidean.twod.Line(pPoint, cPoint, tolerance);
SubHyperplane<Euclidean2D> edge = line.wholeHyperplane();
SubHyperplane<Euclidean2D, Vector2D> edge = line.wholeHyperplane();

if (closed || (previous != 1)) {
// the previous point is a real vertex
Expand Down Expand Up @@ -249,7 +248,7 @@ private void addContribution(final SubHyperplane<Euclidean3D> facet) {
final PolygonsSet projectedFacet = new PolygonsSet(edges, tolerance);

// add the contribution of the facet to the global outline
projected = (PolygonsSet) new RegionFactory<Euclidean2D>().union(projected, projectedFacet);
projected = (PolygonsSet) new RegionFactory<Euclidean2D, Vector2D>().union(projected, projectedFacet);

}
}
Expand Down
Loading

0 comments on commit 2bd5f97

Please sign in to comment.