From cf47772278e3d04d6683ee712cdd79a2a23191e7 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Tue, 16 Nov 2021 17:33:05 -0500 Subject: [PATCH] Corrected the "grow-euclidean" option for grow/shrink/bloat-or so that it correctly lands on a grid limit boundary (which the previous commit did not do). Note that work is still ongoing to detect some pathological cases where the shapes end up off-grid where two non-manhattan shapes intersect at different angles (such as an inside corner). --- cif/CIFgen.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/cif/CIFgen.c b/cif/CIFgen.c index 71b6b39c..9885f2ab 100644 --- a/cif/CIFgen.c +++ b/cif/CIFgen.c @@ -187,6 +187,39 @@ SetBoxGrid(area) } } +/* + * ---------------------------------------------------------------------------- + * SetValueGrid --- + * + * Adjust the given distance to the nearest CIF minimum grid. + * + * Returns: The adjusted value. + * + * Side Effects: None. + * + * Notes: Value is assumed to be a distance, therefore always positive. + * + * ---------------------------------------------------------------------------- + */ + +int +SetValueGrid(value) + int value; +{ + int limit; + int delta; + + limit = CIFCurStyle->cs_gridLimit; + + if (CIFCurStyle && (limit > 1)) + { + delta = value % limit; + if (delta > 0) + value += limit - delta; + } + return value; +} + /* * ---------------------------------------------------------------------------- * SetMinBoxGrid --- @@ -571,8 +604,12 @@ cifGrowEuclideanFunc(tile, table) width = area.r_xtop - area.r_xbot; height = area.r_ytop - area.r_ybot; hyp = sqrt((double)(width * width + height * height)); - growDistanceY = ceil((growDistance * (hyp - height)) / width); - growDistanceX = ceil((growDistance * (hyp - width)) / height); + growDistanceY = ceil((double)(growDistance * width) / hyp); + growDistanceX = ceil((double)(growDistance * height) / hyp); + + /* Adjust for grid limit */ + growDistanceX = SetValueGrid(growDistanceX); + growDistanceY = SetValueGrid(growDistanceY); /* Draw vertical tile to distance X */ @@ -581,7 +618,6 @@ cifGrowEuclideanFunc(tile, table) if (!(growDirs & GROW_WEST)) rtmp.r_xbot = rtmp.r_xtop - growDistanceX; if (!(growDirs & GROW_SOUTH)) rtmp.r_ybot -= growDistance; if (!(growDirs & GROW_NORTH)) rtmp.r_ytop += growDistance; - SetBoxGrid(&rtmp); DBPaintPlane(cifPlane, &rtmp, table, (PaintUndoInfo *) NULL); /* Draw horizontal tile to distance Y */ @@ -591,7 +627,6 @@ cifGrowEuclideanFunc(tile, table) if (!(growDirs & GROW_WEST)) rtmp.r_xbot -= growDistance; if (!(growDirs & GROW_SOUTH)) rtmp.r_ybot = rtmp.r_ytop - growDistanceY; if (!(growDirs & GROW_NORTH)) rtmp.r_ytop = rtmp.r_ybot + growDistanceY; - SetBoxGrid(&rtmp); DBPaintPlane(cifPlane, &rtmp, table, (PaintUndoInfo *) NULL); /* Finally, translate, resize, and paint the diagonal tile */ @@ -615,7 +650,6 @@ cifGrowEuclideanFunc(tile, table) else rtmp.r_xbot += growDistanceX; - SetBoxGrid(&rtmp); DBNMPaintPlane(cifPlane, oldType, &rtmp, table, (PaintUndoInfo *) NULL); oldType = (growDirs & GROW_EAST) ? TiGetRightType(tile) : TiGetLeftType(tile);