Skip to content

Commit

Permalink
Simplifies some OpenGL geometrical operations
Browse files Browse the repository at this point in the history
- uses copy() rather than clone() for geometries
- closes lighting/wireframe between layers or between objects
  • Loading branch information
AlexisDrogoul committed Mar 28, 2022
1 parent cffcbb2 commit d590dc7
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 217 deletions.
Expand Up @@ -110,7 +110,7 @@ protected MinimalAgent(final IPopulation<? extends IAgent> population, final int
} else {
// If the agent is different, we do not copy the attributes present in the shape passed as argument (see
// Issue #2053).
newLocalGeom = new GamaShape((Geometry) newGeometry.getInnerGeometry().clone());
newLocalGeom = new GamaShape(newGeometry.getInnerGeometry().copy());
newLocalGeom.copyShapeAttributesFrom(newGeometry);
}
topology.normalizeLocation(newGeomLocation, false);
Expand Down
75 changes: 23 additions & 52 deletions msi.gama.core/src/msi/gama/metamodel/shape/GamaProxyGeometry.java
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* GamaProxyGeometry.java, in msi.gama.core, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* GamaProxyGeometry.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.metamodel.shape;

Expand Down Expand Up @@ -70,16 +70,15 @@ public abstract class GamaProxyGeometry implements IShape, Cloneable {
/**
* Instantiates a new gama proxy geometry.
*
* @param loc the loc
* @param loc
* the loc
*/
public GamaProxyGeometry(final GamaPoint loc) {
setLocation(loc);
}

@Override
public IType getGamlType() {
return Types.GEOMETRY;
}
public IType getGamlType() { return Types.GEOMETRY; }

@Override
public void forEachAttribute(final BiConsumerWithPruning<String, Object> visitor) {
Expand All @@ -104,9 +103,7 @@ public GamaPoint setLocation(final GamaPoint loc) {
* @see msi.gama.common.interfaces.ILocated#getLocation()
*/
@Override
public GamaPoint getLocation() {
return absoluteLocation;
}
public GamaPoint getLocation() { return absoluteLocation; }

/**
* Method stringValue()
Expand Down Expand Up @@ -251,14 +248,10 @@ public void setGeometry(final IShape g) {
* @see msi.gama.metamodel.shape.IShape#isPoint()
*/
@Override
public boolean isPoint() {
return getReferenceGeometry().isPoint();
}
public boolean isPoint() { return getReferenceGeometry().isPoint(); }

@Override
public boolean isLine() {
return getReferenceGeometry().isLine();
}
public boolean isLine() { return getReferenceGeometry().isLine(); }

/**
* Method getInnerGeometry()
Expand All @@ -267,7 +260,7 @@ public boolean isLine() {
*/
@Override
public Geometry getInnerGeometry() {
final Geometry copy = (Geometry) getReferenceGeometry().getInnerGeometry().clone();
final Geometry copy = getReferenceGeometry().getInnerGeometry().copy();
translate(copy, getReferenceGeometry().getLocation(), getLocation());
return copy;
}
Expand Down Expand Up @@ -346,13 +339,12 @@ public double euclidianDistanceTo(final GamaPoint g) {
public boolean intersects(final IShape g) {
return getInnerGeometry().intersects(g.getInnerGeometry());
}

@Override
public boolean touches(final IShape g) {
return getInnerGeometry().touches(g.getInnerGeometry());
}



@Override
public boolean partiallyOverlaps(final IShape g) {
return getInnerGeometry().overlaps(g.getInnerGeometry());
Expand All @@ -364,9 +356,7 @@ public boolean partiallyOverlaps(final IShape g) {
* @see msi.gama.metamodel.shape.IShape#getPerimeter()
*/
@Override
public double getPerimeter() {
return getReferenceGeometry().getPerimeter();
}
public double getPerimeter() { return getReferenceGeometry().getPerimeter(); }

/**
* Method setInnerGeometry()
Expand All @@ -388,9 +378,7 @@ public void dispose() {
}

@Override
public Type getGeometricalType() {
return getReferenceGeometry().getGeometricalType();
}
public Type getGeometricalType() { return getReferenceGeometry().getGeometricalType(); }

/**
* Method getPoints()
Expand All @@ -401,9 +389,7 @@ public Type getGeometricalType() {
public IList<GamaPoint> getPoints() {
final IList<GamaPoint> result = GamaListFactory.create(Types.POINT);
final Coordinate[] points = getInnerGeometry().getCoordinates();
for (final Coordinate c : points) {
result.add(new GamaPoint(c));
}
for (final Coordinate c : points) { result.add(new GamaPoint(c)); }
return result;
}

Expand All @@ -423,19 +409,15 @@ public void setDepth(final double depth) {
* @see msi.gama.metamodel.shape.IShape#getArea()
*/
@Override
public Double getArea() {
return getReferenceGeometry().getArea();
}
public Double getArea() { return getReferenceGeometry().getArea(); }

/**
* Method getVolume()
*
* @see msi.gama.metamodel.shape.IShape#getVolume()
*/
@Override
public Double getVolume() {
return getReferenceGeometry().getVolume();
}
public Double getVolume() { return getReferenceGeometry().getVolume(); }

/**
* Method getHoles()
Expand All @@ -446,8 +428,7 @@ public Double getVolume() {
public IList<GamaShape> getHoles() {
final IList<GamaShape> holes = GamaListFactory.create(Types.GEOMETRY);
final Geometry g = getInnerGeometry();
if (g instanceof Polygon) {
final Polygon p = (Polygon) g;
if (g instanceof Polygon p) {
final int n = p.getNumInteriorRing();
for (int i = 0; i < n; i++) {
holes.add(new GamaShape(
Expand All @@ -463,9 +444,7 @@ public IList<GamaShape> getHoles() {
* @see msi.gama.metamodel.shape.IShape#getCentroid()
*/
@Override
public GamaPoint getCentroid() {
return absoluteLocation;
}
public GamaPoint getCentroid() { return absoluteLocation; }

/**
* Method getExteriorRing()
Expand All @@ -483,38 +462,30 @@ public GamaShape getExteriorRing(final IScope scope) {
* @see msi.gama.metamodel.shape.IShape#getWidth()
*/
@Override
public Double getWidth() {
return getReferenceGeometry().getWidth();
}
public Double getWidth() { return getReferenceGeometry().getWidth(); }

/**
* Method getHeight()
*
* @see msi.gama.metamodel.shape.IShape#getHeight()
*/
@Override
public Double getHeight() {
return getReferenceGeometry().getHeight();
}
public Double getHeight() { return getReferenceGeometry().getHeight(); }

/**
* Method getDepth()
*
* @see msi.gama.metamodel.shape.IShape#getDepth()
*/
@Override
public Double getDepth() {
return getReferenceGeometry().getDepth();
}
public Double getDepth() { return getReferenceGeometry().getDepth(); }

/**
* Method getGeometricEnvelope()
*
* @see msi.gama.metamodel.shape.IShape#getGeometricEnvelope()
*/
@Override
public GamaShape getGeometricEnvelope() {
return new GamaShape(getEnvelope().toGeometry());
}
public GamaShape getGeometricEnvelope() { return new GamaShape(getEnvelope().toGeometry()); }

}
45 changes: 23 additions & 22 deletions msi.gama.core/src/msi/gama/metamodel/shape/GamaShape.java
@@ -1,12 +1,11 @@
/*******************************************************************************************************
*
* GamaShape.java, in msi.gama.core, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* GamaShape.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.metamodel.shape;

Expand Down Expand Up @@ -58,27 +57,28 @@ public class GamaShape implements IShape {
* The Class ShapeData.
*/
private static class ShapeData {

/** The depth. */
private Double depth;

/** The type. */
private Type type;
}

/** The geometry. */
protected Geometry geometry;

/** The agent. */
private IAgent agent;

/** The attributes. */
protected IMap<String, Object> attributes;

/**
* Instantiates a new gama shape.
*
* @param geom the geom
* @param geom
* the geom
*/
public GamaShape(final Geometry geom) {
setInnerGeometry(geom);
Expand All @@ -90,7 +90,8 @@ public GamaShape(final Geometry geom) {
/**
* Instantiates a new gama shape.
*
* @param env the env
* @param env
* the env
*/
public GamaShape(final Envelope3D env) {
this(env == null ? null : env.toGeometry());
Expand All @@ -99,7 +100,8 @@ public GamaShape(final Envelope3D env) {
/**
* Instantiates a new gama shape.
*
* @param geom the geom
* @param geom
* the geom
*/
public GamaShape(final IShape geom) {
this(geom, null);
Expand All @@ -116,7 +118,7 @@ public GamaShape(final IShape geom) {
*/

public GamaShape(final IShape source, final Geometry geom) {
this((Geometry) (geom == null ? source.getInnerGeometry().clone() : geom));
this(geom == null ? source.getInnerGeometry().copy() : geom);
mixAttributes(source);
}

Expand All @@ -130,8 +132,7 @@ private void mixAttributes(final IShape source) {
if (source == null) return;
// final GamaMap<String, Object> attr = (GamaMap<String, Object>) source.getAttributes();
copyShapeAttributesFrom(source);
if (source instanceof GamaShape) {
final GamaShape shape = (GamaShape) source;
if (source instanceof GamaShape shape) {
if (shape.attributes != null) {
getOrCreateAttributes();
shape.attributes.forEach((key, val) -> { if (val != source) { attributes.put(key, val); } });
Expand All @@ -152,8 +153,7 @@ private void mixAttributes(final IShape source) {

@Override
public void copyAttributesOf(final IAttributed source) {
if (source instanceof GamaShape) {
final GamaShape shape = (GamaShape) source;
if (source instanceof GamaShape shape) {
if (shape.attributes != null) {
getOrCreateAttributes();
attributes.putAll(shape.attributes);
Expand Down Expand Up @@ -329,8 +329,10 @@ public GamaPoint setLocation(final GamaPoint l) {
/**
* Translated to.
*
* @param scope the scope
* @param target the target
* @param scope
* the scope
* @param target
* the target
* @return the gama shape
*/
public GamaShape translatedTo(final IScope scope, final GamaPoint target) {
Expand Down Expand Up @@ -417,8 +419,7 @@ public GamaShape getExteriorRing(final IScope scope) {
result = ((Polygon) result).getExteriorRing();
} else

if (result instanceof MultiPolygon) {
final MultiPolygon mp = (MultiPolygon) result;
if (result instanceof MultiPolygon mp) {
final LineString lines[] = new LineString[mp.getNumGeometries()];
for (int i = 0; i < mp.getNumGeometries(); i++) {
lines[i] = ((Polygon) mp.getGeometryN(i)).getExteriorRing();
Expand All @@ -432,7 +433,8 @@ public GamaShape getExteriorRing(final IScope scope) {
/**
* Gets the data.
*
* @param createIt the create it
* @param createIt
* the create it
* @return the data
*/
private ShapeData getData(final boolean createIt) {
Expand Down Expand Up @@ -556,8 +558,7 @@ public int hashCode() {

@Override
public GamaShape copy(final IScope scope) {
final Geometry gg = (Geometry) geometry.clone();
return new GamaShape(this, gg);
return new GamaShape(this, geometry.copy());
}

/**
Expand Down

0 comments on commit d590dc7

Please sign in to comment.