@Override public byte getLeafSidesInNetwork(NetworkNode networkNode) { if (!hasLeafNode(networkNode)) throw new IllegalArgumentException("Cannot test nodes not in network"); if (networkingNodes.size() == 0) { // Degenerated network for (Side connectingOnSide : SideBitFlag.getSides(networkNode.connectionSides)) { Vector3i possibleLocation = networkNode.location.toVector3i(); possibleLocation.add(connectingOnSide.getVector3i()); for (NetworkNode node : leafNodes.get(new ImmutableBlockLocation(possibleLocation))) { if (SideBitFlag.hasSide(node.connectionSides, connectingOnSide.reverse())) { return SideBitFlag.getSide(connectingOnSide); } } } return 0; } else { byte result = 0; for (Side connectingOnSide : SideBitFlag.getSides(networkNode.connectionSides)) { Vector3i possibleLocation = networkNode.location.toVector3i(); possibleLocation.add(connectingOnSide.getVector3i()); for (NetworkNode node : networkingNodes.get(new ImmutableBlockLocation(possibleLocation))) { if (SideBitFlag.hasSide(node.connectionSides, connectingOnSide.reverse())) { result += SideBitFlag.getSide(connectingOnSide); } } } return result; } }
/** * Returns the network size - a number of nodes it spans. If the same node is added twice with * different connecting sides, it is counted twice. * * @return The sum of networking nodes and leaf nodes (count). */ @Override public int getNetworkSize() { return networkingNodes.size() + leafNodes.size(); }
private boolean isDegeneratedNetwork() { return networkingNodes.isEmpty() && leafNodes.size() == 1; }