use of buildcraft.lib.misc.PositionUtil.PathIterator2d in project BuildCraft by BuildCraft.
the class PatternShape2d method fillTemplate.
@Override
public boolean fillTemplate(IFilledTemplate filledTemplate, IStatementParameter[] params) {
PatternParameterAxis axis = getParam(0, params, PatternParameterAxis.Y);
PatternParameterRotation dir = getParam(2, params, PatternParameterRotation.NONE);
PathIterator2d iterator = getIterator(filledTemplate, axis);
int maxA = axis == PatternParameterAxis.X ? filledTemplate.getMax().getY() : filledTemplate.getMax().getX();
int maxB = axis == PatternParameterAxis.Z ? filledTemplate.getMax().getY() : filledTemplate.getMax().getZ();
int normMaxA = maxA;
int normMaxB = maxB;
if (dir.rotationCount % 2 == 1) {
int maxT = maxA;
maxA = maxB;
maxB = maxT;
final int max_b = maxB;
final PathIterator2d old = iterator;
iterator = (a, b) -> old.iterate(max_b - b, a);
}
if (dir.rotationCount > 1) {
final PathIterator2d old = iterator;
final int max_a = maxA;
final int max_b = maxB;
// Technically this is wrong... but it doesn't matter for any of
// the shapes that use this, as they are all symetrical
iterator = (a, b) -> old.iterate(max_a - a, max_b - b);
}
LineList list = new LineList(iterator);
genShape(maxA, maxB, list);
PatternParameterHollow filled = getParam(1, params, PatternParameterHollow.HOLLOW);
if (filled.filled) {
int fillA = list.fillInA;
int fillB = list.fillInB;
if (fillA != -1 && fillB != -1) {
maxA = normMaxA;
maxB = normMaxB;
if (dir.rotationCount % 2 == 1) {
int fillT = fillA;
fillA = fillB;
fillB = fillT;
}
if (dir.rotationCount > 1) {
fillA = maxA - fillA;
fillB = maxB - fillB;
}
iterator = getIterator(filledTemplate, axis);
PositionGetter getter = getFillGetter(filledTemplate, axis);
if (filled.outerFilled) {
iterator = (a, b) -> {
};
}
// Expand outwards from the point
Set<Point> visited = new HashSet<>();
List<Point> open = new ArrayList<>();
open.add(new Point(fillA, fillB));
while (!open.isEmpty()) {
List<Point> next = new ArrayList<>();
for (Point p : open) {
if (p.a < 0 || p.a > maxA) {
continue;
}
if (p.b < 0 || p.b > maxB) {
continue;
}
if (!visited.add(p)) {
continue;
}
if (getter.isFilled(p.a, p.b)) {
continue;
}
iterator.iterate(p.a, p.b);
next.add(new Point(p.a + 1, p.b));
next.add(new Point(p.a - 1, p.b));
next.add(new Point(p.a, p.b + 1));
next.add(new Point(p.a, p.b - 1));
}
open = next;
}
if (filled.outerFilled) {
iterator = getIterator(filledTemplate, axis);
for (int a = 0; a <= maxA; a++) {
for (int b = 0; b <= maxB; b++) {
if (visited.contains(new Point(a, b))) {
continue;
}
iterator.iterate(a, b);
}
}
}
}
}
return true;
}
Aggregations