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 { ...@@ -409,11 +409,11 @@ public class ConcretePolygon extends Polygon {
if (isLinkedTo()) { if (isLinkedTo()) {
Geometry geom2 = linkedFromPolygon.getParent(); Geometry geom2 = linkedFromPolygon.getParent();
for (Vertex v : lr.getVertices()) { for (Vertex v : lr.getVertices()) {
v.removeAdjacency(lr, this, geom2); v.removeAdjacency(lr, geom2);
} }
} }
for (Vertex v : lr.getVertices()) { for (Vertex v : lr.getVertices()) {
v.removeAdjacency(lr, this, parent); v.removeAdjacency(lr, parent);
} }
} }
......
...@@ -344,7 +344,7 @@ public class Geometry extends GmlElement { ...@@ -344,7 +344,7 @@ public class Geometry extends GmlElement {
v.clearAdjacentRings(this); v.clearAdjacentRings(this);
} }
// add ring to adjacent rings of vertex // 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 { ...@@ -204,17 +204,17 @@ public class LinearRing extends GmlElement {
return; return;
} }
if (parent.isLinkedTo()) { 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) { public void addVertex(int i, Vertex v) {
vertices.add(i, v); vertices.add(i, v);
if (parent.isLinkedTo()) { 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 @Override
......
...@@ -47,11 +47,11 @@ public class LinkedPolygon extends Polygon { ...@@ -47,11 +47,11 @@ public class LinkedPolygon extends Polygon {
this.poly = poly; this.poly = poly;
poly.setLinkedTo(this); poly.setLinkedTo(this);
for (Vertex v : poly.getExteriorRing().getVertices()) { for (Vertex v : poly.getExteriorRing().getVertices()) {
v.addAdjacentRing(this, poly.getExteriorRing(), parent); v.addAdjacentRing(poly.getExteriorRing(), parent);
} }
for (LinearRing lr : poly.getInnerRings()) { for (LinearRing lr : poly.getInnerRings()) {
for (Vertex v : lr.getVertices()) { for (Vertex v : lr.getVertices()) {
v.addAdjacentRing(this, lr, parent); v.addAdjacentRing(lr, parent);
} }
} }
} }
......
...@@ -37,7 +37,6 @@ public class Vertex extends Vector3d { ...@@ -37,7 +37,6 @@ public class Vertex extends Vector3d {
private static final long serialVersionUID = -5525361920397934892L; 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<SerializablePair<Geometry, HashSet<LinearRing>>> adjacentRings = new ArrayList<>(2);
private List<Vertex> neighbors; private List<Vertex> neighbors;
...@@ -91,9 +90,8 @@ public class Vertex extends Vector3d { ...@@ -91,9 +90,8 @@ public class Vertex extends Vector3d {
throw new IllegalStateException("Requested adjacent rings with Geometry not containing this vertex"); 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); findAdjacentRingsForGeometry(geom).add(ring);
findAdjacentPolygonsForGeometry(geom).add(poly);
} }
private Set<LinearRing> findAdjacentRingsForGeometry(Geometry geom) { private Set<LinearRing> findAdjacentRingsForGeometry(Geometry geom) {
...@@ -110,42 +108,32 @@ public class Vertex extends Vector3d { ...@@ -110,42 +108,32 @@ public class Vertex extends Vector3d {
return adjacendRingsSet; return adjacendRingsSet;
} }
private Set<Polygon> findAdjacentPolygonsForGeometry(Geometry geom) { private Set<Polygon> getAdjacentPolygonsWithoutNeighbor(Geometry geom) {
HashSet<Polygon> adjacendPolygonsSet = null; for (SerializablePair<Geometry, HashSet<LinearRing>> adjacency : adjacentRings) {
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) {
if (adjacency.getValue0() == geom) { 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"); throw new IllegalStateException("Requested adjacent polygons with Geometry not containing this vertex");
} }
public Set<Polygon> getAdjacentPolygons(Geometry geom) { public Set<Polygon> getAdjacentPolygons(Geometry geom) {
for (SerializablePair<Geometry, HashSet<Polygon>> adjacency : adjacentPolygons) { for (SerializablePair<Geometry, HashSet<LinearRing>> adjecency : adjacentRings) {
if (adjacency.getValue0() == geom) { if (adjecency.getValue0() == geom) {
if (neighbors == null || neighbors.isEmpty()) { Set<Polygon> polygons = new HashSet<>();
return adjacency.getValue1(); for (LinearRing lr : adjecency.getValue1()) {
} else { polygons.add(lr.getParent());
Set<Polygon> polygons = new HashSet<>(); }
polygons.addAll(adjacency.getValue1()); if (neighbors != null && !neighbors.isEmpty()) {
for (Vertex neighbor : neighbors) { for (Vertex neighbor : neighbors) {
polygons.addAll(neighbor.getAdjacentPolygonsWithoutNeighbor(geom)); polygons.addAll(neighbor.getAdjacentPolygonsWithoutNeighbor(geom));
} }
return polygons;
} }
return polygons;
} }
} }
throw new IllegalStateException("Requested adjacent polygons with Geometry not containing this vertex"); throw new IllegalStateException("Requested adjacent polygons with Geometry not containing this vertex");
...@@ -176,11 +164,9 @@ public class Vertex extends Vector3d { ...@@ -176,11 +164,9 @@ public class Vertex extends Vector3d {
public void clearAdjacentRings(Geometry geometry) { public void clearAdjacentRings(Geometry geometry) {
findAdjacentRingsForGeometry(geometry).clear(); findAdjacentRingsForGeometry(geometry).clear();
findAdjacentPolygonsForGeometry(geometry).clear();
} }
void removeAdjacency(LinearRing lr, Polygon p, Geometry geom) { void removeAdjacency(LinearRing lr, Geometry geom) {
findAdjacentPolygonsForGeometry(geom).remove(p);
findAdjacentRingsForGeometry(geom).remove(lr); 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