/// <summary> /// shifts willBeIn so it is centered in uvRect1, then find a rect that encloses both /// </summary> /// <param name="uvRect1"></param> /// <param name="willBeIn"></param> /// <returns></returns> public static DRect GetEncapsulatingRectShifted(ref DRect uvRect1, ref DRect willBeIn) { DVector2 bc = uvRect1.center; DVector2 tfc = willBeIn.center; DVector2 diff = DVector2.Subtract(bc, tfc); double dx = Convert.ToInt32(diff.x); double dy = Convert.ToInt32(diff.y); DRect uvRect2 = new DRect(willBeIn); uvRect2.x += dx; uvRect2.y += dy; double smnx = uvRect1.x; double smny = uvRect1.y; double smxx = uvRect1.x + uvRect1.width; double smxy = uvRect1.y + uvRect1.height; double bmnx = uvRect2.x; double bmny = uvRect2.y; double bmxx = uvRect2.x + uvRect2.width; double bmxy = uvRect2.y + uvRect2.height; double minx, miny, maxx, maxy; minx = maxx = smnx; miny = maxy = smny; if (bmnx < minx) { minx = bmnx; } if (smnx < minx) { minx = smnx; } if (bmny < miny) { miny = bmny; } if (smny < miny) { miny = smny; } if (bmxx > maxx) { maxx = bmxx; } if (smxx > maxx) { maxx = smxx; } if (bmxy > maxy) { maxy = bmxy; } if (smxy > maxy) { maxy = smxy; } DRect uvRectCombined = new DRect(minx, miny, maxx - minx, maxy - miny); return(uvRectCombined); }
public static DRect GetShiftTransformToFitBinA(ref DRect A, ref DRect B) { DVector2 ac = A.center; DVector2 bc = B.center; DVector2 diff = DVector2.Subtract(ac, bc); double dx = Convert.ToInt32(diff.x); double dy = Convert.ToInt32(diff.y); return(new DRect(dx, dy, 1.0, 1.0)); }
/* * public static void InvertHierarchy(ref DRect uvRect, ref DRect matRect) * { * matRect.x = (uvRect.x * matRect.width + matRect.x - uvRect.x) / uvRect.width; * matRect.y = (uvRect.y * matRect.height + matRect.y - uvRect.y) / uvRect.height; * } */ public static bool RectContainsShifted(ref DRect bucket, ref DRect tryFit) { //get the centers of bucket and tryFit DVector2 bc = bucket.center; DVector2 tfc = tryFit.center; DVector2 diff = DVector2.Subtract(bc, tfc); double dx = Convert.ToInt32(diff.x); double dy = Convert.ToInt32(diff.y); DRect tmp = new DRect(tryFit); tmp.x += dx; tmp.y += dy; return(bucket.Encloses(tmp)); }