From 848a0f8d2cb639b42e03d8f18c8486b13ca899b2 Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Sun, 11 Apr 2021 08:07:10 +0100 Subject: [PATCH] Fix wonky pyramids Previously the slope of the pyramid was cast into a double. This adds an error into the value that is provided as an exact rational number. This change keeps the value as a rational and only uses the double type where intermediate values may exceed the integer range. --- MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs | 8 ++++---- MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs b/MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs index 57c5fe140..1ad7cadd9 100644 --- a/MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs +++ b/MCGalaxy/Drawing/DrawOps/AdvConeDrawOps.cs @@ -48,7 +48,7 @@ namespace MCGalaxy.Drawing.Ops { int curHeight = Invert ? yy : height - yy; if (curHeight == 0) continue; - double curRadius = Radius * ((double)curHeight / (double)height); + double curRadius = Radius * (double)curHeight / (double)height; int dist = xx * xx + zz * zz; if (dist > curRadius * curRadius) continue; output(Place(x, y, z, brush)); @@ -80,7 +80,7 @@ namespace MCGalaxy.Drawing.Ops { int curHeight = Invert ? yy : height - yy; if (curHeight == 0) continue; - double curRadius = Radius * ((double)curHeight / (double)height); + double curRadius = Radius * (double)curHeight / (double)height; int dist = xx * xx + zz * zz; if (dist > curRadius * curRadius || dist < (curRadius - 1) * (curRadius - 1)) continue; output(Place(x, y, z, brush)); @@ -109,7 +109,7 @@ namespace MCGalaxy.Drawing.Ops { int curHeight = height - yy; if (curHeight == 0) continue; - double curRadius = Radius * ((double)curHeight / (double)height); + double curRadius = Radius * (double)curHeight / (double)height; int dist = xx * xx + zz * zz; if (dist > curRadius * curRadius) continue; @@ -119,4 +119,4 @@ namespace MCGalaxy.Drawing.Ops { } } } -} \ No newline at end of file +} diff --git a/MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs b/MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs index fdac2f3bf..391bc230e 100644 --- a/MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs +++ b/MCGalaxy/Drawing/DrawOps/AdvPyramidDrawOps.cs @@ -47,7 +47,7 @@ namespace MCGalaxy.Drawing.Ops { int curHeight = Invert ? yy : height - yy; if (curHeight == 0) continue; - double curRadius = Radius * ((double)curHeight / (double)height); + int curRadius = Radius * curHeight / height; if (Math.Abs(xx) > curRadius || Math.Abs(zz) > curRadius) continue; output(Place(x, y, z, brush)); } @@ -78,7 +78,7 @@ namespace MCGalaxy.Drawing.Ops { int curHeight = Invert ? yy : height - yy; if (curHeight == 0) continue; - double curRadius = Radius * ((double)curHeight / (double)height); + int curRadius = Radius * curHeight / height; int absx = Math.Abs(xx), absz = Math.Abs(zz); if (absx > curRadius || absz > curRadius) continue; if (absx < (curRadius - 1) && absz < (curRadius - 1)) continue; @@ -86,4 +86,4 @@ namespace MCGalaxy.Drawing.Ops { } } } -} \ No newline at end of file +}