From 2a09aaf395e702a69010be1c725b8f969c1950d8 Mon Sep 17 00:00:00 2001 From: Madeline Miller Date: Mon, 9 Oct 2023 19:45:38 +1000 Subject: [PATCH] Optimise line thickness calculations --- .../src/main/java/com/sk89q/worldedit/EditSession.java | 9 +++++---- .../java/com/sk89q/worldedit/command/RegionCommands.java | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 34542d9e62..d06b7a291f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -2587,7 +2587,7 @@ public int drawLine(Pattern pattern, List vectors, double radius, Set 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); @@ -2691,17 +2691,18 @@ public int drawSpline(Pattern pattern, List 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 getBallooned(Set vset, double radius) { Set returnset = new HashSet<>(); int ceilrad = (int) Math.ceil(radius); + double radiusSquare = Math.pow(radius, 2); for (BlockVector3 v : vset) { int tipx = v.getBlockX(); @@ -2711,7 +2712,7 @@ private static Set getBallooned(Set 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)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index addf03c289..7425e59376 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -139,8 +139,7 @@ public int line(Actor actor, EditSession editSession, List 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;