Commit d163d7c4 authored by Matthias Betz's avatar Matthias Betz
Browse files

removing adjacency list for polygons. Redundant with adjacency list with linear rings

parent adbb58d1
Pipeline #1374 passed with stage
in 2 minutes and 18 seconds
......@@ -409,11 +409,11 @@ public class ConcretePolygon extends Polygon {
if (isLinkedTo()) {
Geometry geom2 = linkedFromPolygon.getParent();
for (Vertex v : lr.getVertices()) {
v.removeAdjacency(lr, this, geom2);
v.removeAdjacency(lr, geom2);
}
}
for (Vertex v : lr.getVertices()) {
v.removeAdjacency(lr, this, parent);
v.removeAdjacency(lr, parent);
}
}
......
......@@ -344,7 +344,7 @@ public class Geometry extends GmlElement {
v.clearAdjacentRings(this);
}
// add ring to adjacent rings of vertex
v.addAdjacentRing(p, ring, this);
v.addAdjacentRing(ring, this);
}
}
......
......@@ -204,17 +204,17 @@ public class LinearRing extends GmlElement {
return;
}
if (parent.isLinkedTo()) {
v.addAdjacentRing(parent.getLinkedFromPolygon(), this, parent.getLinkedFromPolygon().getParent());
v.addAdjacentRing(this, parent.getLinkedFromPolygon().getParent());
}
v.addAdjacentRing(parent, this, parent.getParent());
v.addAdjacentRing(this, parent.getParent());
}
public void addVertex(int i, Vertex v) {
vertices.add(i, v);
if (parent.isLinkedTo()) {
v.addAdjacentRing(parent.getLinkedFromPolygon(), this, parent.getLinkedFromPolygon().getParent());
v.addAdjacentRing(this, parent.getLinkedFromPolygon().getParent());
}
v.addAdjacentRing(parent, this, parent.getParent());
v.addAdjacentRing(this, parent.getParent());
}
@Override
......
......@@ -47,11 +47,11 @@ public class LinkedPolygon extends Polygon {
this.poly = poly;
poly.setLinkedTo(this);
for (Vertex v : poly.getExteriorRing().getVertices()) {
v.addAdjacentRing(this, poly.getExteriorRing(), parent);
v.addAdjacentRing(poly.getExteriorRing(), parent);
}
for (LinearRing lr : poly.getInnerRings()) {
for (Vertex v : lr.getVertices()) {
v.addAdjacentRing(this, lr, parent);
v.addAdjacentRing(lr, parent);
}
}
}
......
......@@ -37,7 +37,6 @@ public class Vertex extends Vector3d {
private static final long serialVersionUID = -5525361920397934892L;
private List<SerializablePair<Geometry, HashSet<Polygon>>> adjacentPolygons = new ArrayList<>(2);
private List<SerializablePair<Geometry, HashSet<LinearRing>>> adjacentRings = new ArrayList<>(2);
private List<Vertex> neighbors;
......@@ -91,9 +90,8 @@ public class Vertex extends Vector3d {
throw new IllegalStateException("Requested adjacent rings with Geometry not containing this vertex");
}
void addAdjacentRing(Polygon poly, LinearRing ring, Geometry geom) {
void addAdjacentRing(LinearRing ring, Geometry geom) {
findAdjacentRingsForGeometry(geom).add(ring);
findAdjacentPolygonsForGeometry(geom).add(poly);
}
private Set<LinearRing> findAdjacentRingsForGeometry(Geometry geom) {
......@@ -110,42 +108,32 @@ public class Vertex extends Vector3d {
return adjacendRingsSet;
}
private Set<Polygon> findAdjacentPolygonsForGeometry(Geometry geom) {
HashSet<Polygon> adjacendPolygonsSet = null;
for (SerializablePair<Geometry, HashSet<Polygon>> adjacency : adjacentPolygons) {
if (adjacency.getValue0() == geom) {
adjacendPolygonsSet = adjacency.getValue1();
}
}
if (adjacendPolygonsSet == null) {
adjacendPolygonsSet = new HashSet<>(4);
adjacentPolygons.add(new SerializablePair<>(geom, adjacendPolygonsSet));
}
return adjacendPolygonsSet;
}
public Set<Polygon> getAdjacentPolygonsWithoutNeighbor(Geometry geom) {
for (SerializablePair<Geometry, HashSet<Polygon>> adjacency : adjacentPolygons) {
private Set<Polygon> getAdjacentPolygonsWithoutNeighbor(Geometry geom) {
for (SerializablePair<Geometry, HashSet<LinearRing>> adjacency : adjacentRings) {
if (adjacency.getValue0() == geom) {
return adjacency.getValue1();
Set<Polygon> polygons = new HashSet<>();
for (LinearRing lr : adjacency.getValue1()) {
polygons.add(lr.getParent());
}
return polygons;
}
}
throw new IllegalStateException("Requested adjacent polygons with Geometry not containing this vertex");
}
public Set<Polygon> getAdjacentPolygons(Geometry geom) {
for (SerializablePair<Geometry, HashSet<Polygon>> adjacency : adjacentPolygons) {
if (adjacency.getValue0() == geom) {
if (neighbors == null || neighbors.isEmpty()) {
return adjacency.getValue1();
} else {
Set<Polygon> polygons = new HashSet<>();
polygons.addAll(adjacency.getValue1());
for (SerializablePair<Geometry, HashSet<LinearRing>> adjecency : adjacentRings) {
if (adjecency.getValue0() == geom) {
Set<Polygon> polygons = new HashSet<>();
for (LinearRing lr : adjecency.getValue1()) {
polygons.add(lr.getParent());
}
if (neighbors != null && !neighbors.isEmpty()) {
for (Vertex neighbor : neighbors) {
polygons.addAll(neighbor.getAdjacentPolygonsWithoutNeighbor(geom));
}
return polygons;
}
return polygons;
}
}
throw new IllegalStateException("Requested adjacent polygons with Geometry not containing this vertex");
......@@ -176,11 +164,9 @@ public class Vertex extends Vector3d {
public void clearAdjacentRings(Geometry geometry) {
findAdjacentRingsForGeometry(geometry).clear();
findAdjacentPolygonsForGeometry(geometry).clear();
}
void removeAdjacency(LinearRing lr, Polygon p, Geometry geom) {
findAdjacentPolygonsForGeometry(geom).remove(p);
void removeAdjacency(LinearRing lr, Geometry geom) {
findAdjacentRingsForGeometry(geom).remove(lr);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment