public static CCRect CCRectFromString(string pszContent) { CCRect result = CCRect.Zero; do { if (pszContent == null) { break; } string content = pszContent; // find the first '{' and the third '}' int nPosLeft = content.IndexOf('{'); int nPosRight = content.IndexOf('}'); for (int i = 1; i < 3; ++i) { if (nPosRight == -1) { break; } nPosRight = content.IndexOf('}', nPosRight + 1); } if (nPosLeft == -1 || nPosRight == -1) { break; } content = content.Substring(nPosLeft + 1, nPosRight - nPosLeft - 1); int nPointEnd = content.IndexOf('}'); if (nPointEnd == -1) { break; } nPointEnd = content.IndexOf(',', nPointEnd); if (nPointEnd == -1) { break; } // get the point string and size string string pointStr = content.Substring(0, nPointEnd); string sizeStr = content.Substring(nPointEnd + 1); //, content.Length - nPointEnd // split the string with ',' List<string> pointInfo = new List<string>(); if (!CCUtils.SplitWithForm(pointStr, pointInfo)) { break; } List<string> sizeInfo = new List<string>(); if (!CCUtils.SplitWithForm(sizeStr, sizeInfo)) { break; } float x = CCUtils.CCParseFloat(pointInfo[0]); float y = CCUtils.CCParseFloat(pointInfo[1]); float width = CCUtils.CCParseFloat(sizeInfo[0]); float height = CCUtils.CCParseFloat(sizeInfo[1]); result = new CCRect(x, y, width, height); } while (false); return result; }
public static bool IntersetsRect(ref CCRect rectA, ref CCRect rectB) { return !(rectA.MaxX < rectB.MinX || rectB.MaxX < rectA.MinX || rectA.MaxY < rectB.MinY || rectB.MaxY < rectA.MinY); }
public bool Equals(CCRect rect) { return Origin.Equals(rect.Origin) && Size.Equals(rect.Size); }
public static bool ContainsPoint(ref CCRect rect, ref CCPoint point) { bool bRet = false; if (float.IsNaN(point.X)) { point.X = 0; } if (float.IsNaN(point.Y)) { point.Y = 0; } if (point.X >= rect.MinX && point.X <= rect.MaxX && point.Y >= rect.MinY && point.Y <= rect.MaxY) { bRet = true; } return bRet; }
public static bool Equal(ref CCRect rect1, ref CCRect rect2) { return rect1.Origin.Equals(rect2.Origin) && rect1.Size.Equals(rect2.Size); }
public bool IntersectsRect(ref CCRect rect) { return !(MaxX < rect.MinX || rect.MaxX < MinX || MaxY < rect.MinY || rect.MaxY < MinY); }
public CCRect Intersection(CCRect rect) { if (!IntersectsRect(rect)) { return (Zero); } /* +-------------+ * | | * | +---+-----+ * +-----+---+ | | | * | | | | | | * | | | +---+-----+ * | | | | * | | | | * +-----+---+ | * | | * +-------------+ */ float minx = 0, miny = 0, maxx = 0, maxy = 0; // X if (rect.MinX < MinX) { minx = MinX; } else if (rect.MinX < MaxX) { minx = rect.MinX; } if (rect.MaxX < MaxX) { maxx = rect.MaxX; } else if (rect.MaxX > MaxX) { maxx = MaxX; } // Y if (rect.MinY < MinY) { miny = MinY; } else if (rect.MinY < MaxY) { miny = rect.MinY; } if (rect.MaxY < MaxY) { maxy = rect.MaxY; } else if (rect.MaxY > MaxY) { maxy = MaxY; } return new CCRect(minx, miny, maxx - minx, maxy - miny); }
public CCRect Union(CCRect rect) { float minx = Math.Min(MinX, rect.MinX); float miny = Math.Min(MinY, rect.MinY); float maxx = Math.Max(MaxX, rect.MaxX); float maxy = Math.Max(MaxY, rect.MaxY); return (new CCRect(minx, miny, maxx - minx, maxy - miny)); }