Skip to content

Commit

Permalink
Optimise line thickness calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Oct 9, 2023
1 parent 58e9156 commit 2a09aaf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2587,7 +2587,7 @@ public int drawLine(Pattern pattern, List<BlockVector3> vectors, double radius,

Set<BlockVector3> vset = new HashSet<>();

for (int i = 0; vectors.size() != 0 && i < vectors.size() - 1; i++) {
for (int i = 0; !vectors.isEmpty() && i < vectors.size() - 1; i++) {
BlockVector3 pos1 = vectors.get(i);
BlockVector3 pos2 = vectors.get(i + 1);

Expand Down Expand Up @@ -2691,17 +2691,18 @@ public int drawSpline(Pattern pattern, List<BlockVector3> nodevectors, double te
return setBlocks(vset, pattern);
}

private static double hypot(double... pars) {
private static double hypotSquare(double... pars) {
double sum = 0;
for (double d : pars) {
sum += Math.pow(d, 2);
}
return Math.sqrt(sum);
return sum;
}

private static Set<BlockVector3> getBallooned(Set<BlockVector3> vset, double radius) {
Set<BlockVector3> returnset = new HashSet<>();
int ceilrad = (int) Math.ceil(radius);
double radiusSquare = Math.pow(radius, 2);

for (BlockVector3 v : vset) {
int tipx = v.getBlockX();
Expand All @@ -2711,7 +2712,7 @@ private static Set<BlockVector3> getBallooned(Set<BlockVector3> vset, double rad
for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) {
for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) {
for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) {
if (hypot(loopx - tipx, loopy - tipy, loopz - tipz) <= radius) {
if (hypotSquare(loopx - tipx, loopy - tipy, loopz - tipz) <= radiusSquare) {
returnset.add(BlockVector3.at(loopx, loopy, loopz));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ public int line(Actor actor, EditSession editSession,

List<BlockVector3> vectors;

if (region instanceof CuboidRegion) {
CuboidRegion cuboidRegion = (CuboidRegion) region;
if (region instanceof CuboidRegion cuboidRegion) {
vectors = ImmutableList.of(cuboidRegion.getPos1(), cuboidRegion.getPos2());
} else {
ConvexPolyhedralRegion convexRegion = (ConvexPolyhedralRegion) region;
Expand Down

0 comments on commit 2a09aaf

Please sign in to comment.