use of com.slimjars.dist.gnu.trove.list.TLongList in project osm4j-geometry by topobyte.
the class ChainOfNodes method resolveNodeIntersections.
/**
* Build a new set of rings by splitting at node intersections.
*/
public List<ChainOfNodes> resolveNodeIntersections() {
List<ChainOfNodes> results = new ArrayList<>();
// Walk along the nodes in the ring and put them on the stack. Once an
// id is encountered that is already on the stack somewhere, we found an
// intersection. We track back by popping elements off the stack until
// we reach the previous occurrence of the id, building a ring on the
// way.
LongSetStack stack = new LongSetStack();
int size = nodeIds.size();
for (int i = 0; i < size; i++) {
long id = nodeIds.get(i);
if (!stack.contains(id)) {
// No intersection, just put on the stack
stack.push(id);
} else {
// Intersection, track back
TLongList list = new TLongArrayList();
list.add(id);
while (true) {
long popped = stack.pop();
list.add(popped);
if (popped == id) {
break;
}
}
results.add(new ChainOfNodes(list));
// We need to push the current id to restore the state of the
// structures as if the ring we just created had not existed at
// all.
stack.push(id);
}
}
// element on the stack. In that case, add a last non-closed ring.
if (stack.size() > 1) {
TLongList list = new TLongArrayList();
while (!stack.isEmpty()) {
list.add(stack.pop());
}
results.add(new ChainOfNodes(list));
}
return results;
}
use of com.slimjars.dist.gnu.trove.list.TLongList in project osm4j-core by topobyte.
the class ImplUtil method clone.
public static Way clone(OsmWay way) {
List<? extends OsmTag> tags = cloneTags(way);
OsmMetadata metadata = cloneMetadata(way);
TLongList nodes = new TLongArrayList(way.getNumberOfNodes());
for (int i = 0; i < way.getNumberOfNodes(); i++) {
nodes.add(way.getNodeId(i));
}
return new Way(way.getId(), nodes, tags, metadata);
}
use of com.slimjars.dist.gnu.trove.list.TLongList in project osm4j-geometry by topobyte.
the class ChainOfWays method toSegmentRing.
public ChainOfNodes toSegmentRing() {
if (segments.isEmpty()) {
return new ChainOfNodes(new TLongArrayList());
}
int len = getLengthNonEmpty();
TLongList ids = new TLongArrayList(len);
for (int i = 0; i < segments.size(); i++) {
WaySegment segment = segments.get(i);
OsmWay way = segment.getWay();
for (int k = 0; k < way.getNumberOfNodes(); k++) {
if (k > 0 || i == 0) {
ids.add(segment.getNodeId(k));
}
}
}
return new ChainOfNodes(ids);
}
Aggregations