diff --git a/msi.gama.core/src/msi/gama/common/geometry/Envelope3D.java b/msi.gama.core/src/msi/gama/common/geometry/Envelope3D.java index 31aa1623bc..0bcf12a362 100644 --- a/msi.gama.core/src/msi/gama/common/geometry/Envelope3D.java +++ b/msi.gama.core/src/msi/gama/common/geometry/Envelope3D.java @@ -20,7 +20,6 @@ import msi.gama.common.util.PoolUtils; import msi.gama.metamodel.shape.GamaPoint; import msi.gama.metamodel.shape.GamaShape; - import msi.gama.metamodel.shape.IShape; import msi.gaml.operators.Comparison; import msi.gaml.types.GamaGeometryType; @@ -35,10 +34,10 @@ * @adapted for GAMA by A. Drogoul * */ -public class Envelope3D extends Envelope implements IDisposable { +public class Envelope3D extends Envelope implements IDisposable, IIntersectable { private final static PoolUtils.ObjectPool POOL = - PoolUtils.create("Envelope 3D", true, () -> new Envelope3D(), (from, to) -> to.set(from), null); + PoolUtils.create("Envelope 3D", true, Envelope3D::new, (from, to) -> to.set(from), null); public static final Envelope3D EMPTY = create(); @@ -380,7 +379,7 @@ public GamaPoint centre() { @Override public boolean intersects(final Envelope other) { if (!super.intersects(other)) return false; - return !(getMinZOf(other) > maxz || getMaxZOf(other) < minz); + return getMinZOf(other) <= maxz && getMaxZOf(other) >= minz; } /** @@ -408,7 +407,7 @@ public boolean intersects(final Coordinate p) { */ protected boolean intersects(final double x, final double y, final double z) { if (isNull()) return false; - return intersects(x, y) && !(z < minz || z > maxz); + return intersects(x, y) && z >= minz && z <= maxz; } /** @@ -448,8 +447,7 @@ public boolean covers(final Coordinate p) { */ @Override public boolean covers(final Envelope other) { - if (isNull() || other.isNull()) return false; - if (!super.covers(other)) return false; + if (isNull() || other.isNull() || !super.covers(other)) return false; return getMinZOf(other) >= minz && getMaxZOf(other) <= maxz; } @@ -488,9 +486,7 @@ public double distance(final Envelope env) { // --------------------------------------------------------------------------------------------------------------- - private Envelope3D() { - super(); - } + private Envelope3D() {} /** * Computes the intersection of two {@link Envelope}s. diff --git a/msi.gama.core/src/msi/gama/common/geometry/IIntersectable.java b/msi.gama.core/src/msi/gama/common/geometry/IIntersectable.java new file mode 100644 index 0000000000..fd71dfa8fa --- /dev/null +++ b/msi.gama.core/src/msi/gama/common/geometry/IIntersectable.java @@ -0,0 +1,14 @@ +package msi.gama.common.geometry; + +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Envelope; + +import msi.gama.common.interfaces.IDisposable; + +public interface IIntersectable extends IDisposable { + + boolean intersects(Envelope env); + + boolean intersects(Coordinate env); + +} diff --git a/msi.gama.core/src/msi/gama/metamodel/shape/GamaPoint.java b/msi.gama.core/src/msi/gama/metamodel/shape/GamaPoint.java index 1c5b093ecb..62934fec58 100644 --- a/msi.gama.core/src/msi/gama/metamodel/shape/GamaPoint.java +++ b/msi.gama.core/src/msi/gama/metamodel/shape/GamaPoint.java @@ -14,11 +14,13 @@ import static msi.gaml.operators.Maths.round; import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Envelope; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.util.NumberUtil; import msi.gama.common.geometry.Envelope3D; import msi.gama.common.geometry.GeometryUtils; +import msi.gama.common.geometry.IIntersectable; import msi.gama.common.interfaces.BiConsumerWithPruning; import msi.gama.common.interfaces.IAttributed; import msi.gama.common.interfaces.IKeyword; @@ -56,7 +58,7 @@ name = IKeyword.Z, type = IType.FLOAT, doc = { @doc ("Returns the z ordinate of this point") }) }) -public class GamaPoint extends Coordinate implements IShape, ILocation { +public class GamaPoint extends Coordinate implements IShape, ILocation, IIntersectable { public GamaPoint() { x = 0.0d; @@ -664,4 +666,14 @@ public GamaPoint toGamaPoint() { return this; } + @Override + public boolean intersects(final Envelope env) { + return env.intersects(this); + } + + @Override + public boolean intersects(final Coordinate env) { + return this.equals3D(env); + } + }