Search in sources :

Example 1 with End

use of com.revolsys.geometry.model.End in project com.revolsys.open by revolsys.

the class NodeRemovalVisitor method accept.

@Override
public void accept(final Node<Record> node) {
    if (node.getDegree() == 2) {
        final List<Edge<Record>> edges = node.getEdges();
        if (edges.size() == 2) {
            final Edge<Record> edge1 = edges.get(0);
            final Edge<Record> edge2 = edges.get(1);
            if (edge1 != edge2) {
                final Record object1 = edge1.getObject();
                final Record object2 = edge2.getObject();
                if (DataType.equal(object1, object2, this.excludedFieldNames)) {
                    final End end1 = edge1.getEnd(node);
                    if (end1 == edge2.getEnd(node)) {
                        // if (!fixReversedEdges(node, reversedEdges, edge1, edge2)) {
                        return;
                    // }
                    }
                    if (end1.isFrom()) {
                        this.graph.merge(node, edge2, edge1);
                    } else {
                        this.graph.merge(node, edge1, edge2);
                    }
                }
            }
        }
    }
}
Also used : Record(com.revolsys.record.Record) End(com.revolsys.geometry.model.End) Edge(com.revolsys.geometry.graph.Edge)

Example 2 with End

use of com.revolsys.geometry.model.End in project com.revolsys.open by revolsys.

the class PolygonNodeRemovalVisitor method accept.

@Override
public void accept(final Node<Record> node) {
    final Set<Edge<Record>> edges = new LinkedHashSet<>(node.getEdges());
    while (edges.size() > 1) {
        final Edge<Record> edge = edges.iterator().next();
        final Record object = edge.getObject();
        final Set<Edge<Record>> matchedEdges = new HashSet<>();
        final End end = edge.getEnd(node);
        for (final Edge<Record> matchEdge : edges) {
            final Record matchObject = matchEdge.getObject();
            if (edge != matchEdge) {
                final End matchEnd = matchEdge.getEnd(node);
                if (end != matchEnd) {
                    if (DataType.equal(object, matchObject, this.excludedAttributes)) {
                        matchedEdges.add(matchEdge);
                    }
                }
            }
        }
        if (matchedEdges.size() == 1) {
            final Edge<Record> matchedEdge = matchedEdges.iterator().next();
            if (end.isFrom()) {
                this.graph.merge(node, matchedEdge, edge);
            } else {
                this.graph.merge(node, edge, matchedEdge);
            }
        }
        edges.removeAll(matchedEdges);
        edges.remove(edge);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Record(com.revolsys.record.Record) End(com.revolsys.geometry.model.End) Edge(com.revolsys.geometry.graph.Edge) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Edge (com.revolsys.geometry.graph.Edge)2 End (com.revolsys.geometry.model.End)2 Record (com.revolsys.record.Record)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1