From 5c32cc17a2fb6780a5f5295a7b5338a881b0bab5 Mon Sep 17 00:00:00 2001 From: Hazel Trinity Date: Sun, 16 Aug 2020 01:11:12 -0700 Subject: [PATCH] Used Reparameterized Interpolation --- .../fawe/object/brush/sweep/SweepBrush.java | 46 +++---------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java index 250d2e956..27310d58b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java @@ -18,6 +18,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.interpolation.Interpolation; import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation; import com.sk89q.worldedit.math.interpolation.Node; +import com.sk89q.worldedit.math.interpolation.ReparametrisingInterpolation; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; @@ -41,22 +42,6 @@ public class SweepBrush implements Brush, ResettableTool { this.copies = copies > 0 ? copies : -1; } - private Vector3 getSidePos(Interpolation interpol, double position, Clipboard clipboard, boolean rightHand) { - Vector3 pos = interpol.getPosition(position); - Vector3 deriv = interpol.get1stDerivative(position); - double length = (rightHand ? 1 : -1) * Math.abs( - clipboard.getOrigin().getBlockZ() - clipboard.getRegion().getMinimumPoint().getBlockZ() - ); - - Vector3 cross = deriv.cross(Vector3.UNIT_Y); - if (cross.equals(Vector3.ZERO)) { - return null; - } - - Vector3 perpendicular = cross.normalize().multiply(length); - return pos.add(perpendicular); - } - @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { boolean visualization = editSession.getExtent() instanceof VisualExtent; @@ -82,7 +67,7 @@ public class SweepBrush implements Brush, ResettableTool { return; } - Interpolation interpol = new KochanekBartelsInterpolation(); + Interpolation interpol = new ReparametrisingInterpolation(new KochanekBartelsInterpolation()); List nodes = positions.stream().map(v -> { Node n = new Node(v.toVector3()); n.setTension(tension); @@ -114,29 +99,10 @@ public class SweepBrush implements Brush, ResettableTool { break; } case -1: { - double splineLength = interpol.arcLength(0D, 1D); - double blockDistance = 1d / splineLength; - double step = blockDistance / quality; - MutableVector3 lastLHS = new MutableVector3(getSidePos(interpol, 0, clipboard, false).round()); - MutableVector3 lastRHS = new MutableVector3(getSidePos(interpol, 0, clipboard, true).round()); - - for (double pos = 0D; pos <= 1D; pos += step) { - Vector3 lhs = getSidePos(interpol, pos, clipboard, false); - boolean doLeft = lhs == null || !lhs.round().equals(lastLHS); - if (doLeft && lhs != null) { - lastLHS.setComponents(lhs.round()); - } - - Vector3 rhs = getSidePos(interpol, pos, clipboard, true); - boolean doRight = rhs == null || !rhs.round().equals(lastRHS); - if (doRight && rhs != null) { - lastRHS.setComponents(rhs.round()); - } - - // Only paste if the edges have passed the previous edges - if (doLeft || doRight) { - spline.pastePosition(pos); - } + double length = interpol.arcLength(0, 1); + double step = 1 / (length * quality); + for (double pos = 0; pos <= 1; pos += step) { + spline.pastePosition(pos); } break; }