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.
This commit is contained in:
Robert de Bath 2021-04-11 08:07:10 +01:00
parent ab97043dd8
commit 848a0f8d2c
2 changed files with 7 additions and 7 deletions

View File

@ -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;

View File

@ -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;