BBGamelib.CGAffineTransform.CGRectApplyAffineTransform C# (CSharp) Method

CGRectApplyAffineTransform() public static method

public static CGRectApplyAffineTransform ( Rect rect, CGAffineTransform transform ) : Rect
rect UnityEngine.Rect
transform CGAffineTransform
return UnityEngine.Rect
		public static Rect CGRectApplyAffineTransform(Rect rect, CGAffineTransform transform)
		{
			float xMin = rect.position.x;
			float xMax = rect.position.x + rect.size.x;
			float yMin = rect.position.y;
			float yMax = rect.position.y + rect.size.y;
			
			Vector2[] points = new Vector2[4]{
				CGPointApplyAffineTransform(new Vector2(xMin, yMin), transform),
				CGPointApplyAffineTransform(new Vector2(xMin, yMax), transform),
				CGPointApplyAffineTransform(new Vector2(xMax, yMin), transform),
				CGPointApplyAffineTransform(new Vector2(xMax, yMax), transform),
			};
			
			float newXMin =  float.MaxValue;
			float newXMax =  float.MinValue;
			float newYMin =  float.MaxValue;
			float newYMax =  float.MinValue;
			
			for (int i = 0; i < 4; i++) {
				newXMax = Mathf.Max(newXMax, points[i].x);
				newYMax = Mathf.Max(newYMax, points[i].y);
				newXMin = Mathf.Min(newXMin, points[i].x);
				newYMin = Mathf.Min(newYMin, points[i].y);
			}
			
			Rect result = new Rect(newXMin, newYMin, newXMax - newXMin, newYMax - newYMin);
			
			return result;
		}
	}

Usage Example

        public Rect getBounds()
        {
            Rect rect = new Rect();

            for (var ent = _tiles.head; ent != null; ent = ent.next)
            {
                Vector2 sptSize = ent.obj.spriteFrame.originalSize / UIWindow.PIXEL_PER_UNIT;
                Rect    sptRect = new Rect(-sptSize / 2, sptSize);
                sptRect = CGAffineTransform.CGRectApplyAffineTransform(sptRect, ent.obj.transform);
                rect    = ccUtils.RectUnion(rect, sptRect);
            }
            rect.position *= UIWindow.PIXEL_PER_UNIT;
            rect.size     *= UIWindow.PIXEL_PER_UNIT;
            return(rect);
        }
All Usage Examples Of BBGamelib.CGAffineTransform::CGRectApplyAffineTransform