// Find difference between rects as an nsMargin nsMargin nsRect::operator-(const nsRect& aRect) const { nsMargin margin; margin.left = aRect.x - x; margin.right = XMost() - aRect.XMost(); margin.top = aRect.y - y; margin.bottom = YMost() - aRect.YMost(); return margin; }
// scale the rect but round to smallest containing rect nsRect& nsRect::ScaleRoundOut(float aScale) { nscoord right = NSToCoordCeil(float(XMost()) * aScale); nscoord bottom = NSToCoordCeil(float(YMost()) * aScale); x = NSToCoordFloor(float(x) * aScale); y = NSToCoordFloor(float(y) * aScale); width = (right - x); height = (bottom - y); return *this; }
gfxRect gfxRect::Union(const gfxRect& aRect) const { if (IsEmpty()) return aRect; if (aRect.IsEmpty()) return *this; gfxFloat x = PR_MIN(aRect.X(), X()); gfxFloat xmost = PR_MAX(aRect.XMost(), XMost()); gfxFloat y = PR_MIN(aRect.Y(), Y()); gfxFloat ymost = PR_MAX(aRect.YMost(), YMost()); return gfxRect(x, y, xmost - x, ymost - y); }
void gfxRect::RoundOut() { gfxFloat x0 = floor(X()); gfxFloat y0 = floor(Y()); gfxFloat x1 = ceil(XMost()); gfxFloat y1 = ceil(YMost()); x = x0; y = y0; width = x1 - x0; height = y1 - y0; }
void gfxRect::RoundOut() { gfxFloat x0 = NS_floor(X()); gfxFloat y0 = NS_floor(Y()); gfxFloat x1 = NS_ceil(XMost()); gfxFloat y1 = NS_ceil(YMost()); pos.x = x0; pos.y = y0; size.width = x1 - x0; size.height = y1 - y0; }
void gfxRect::Round() { // Note that don't use NS_round here. See the comment for this method in gfxRect.h gfxFloat x0 = floor(X() + 0.5); gfxFloat y0 = floor(Y() + 0.5); gfxFloat x1 = floor(XMost() + 0.5); gfxFloat y1 = floor(YMost() + 0.5); x = x0; y = y0; width = x1 - x0; height = y1 - y0; }
gfxRect gfxRect::Intersect(const gfxRect& aRect) const { gfxRect result(0,0,0,0); gfxFloat x = PR_MAX(aRect.X(), X()); gfxFloat xmost = PR_MIN(aRect.XMost(), XMost()); if (x >= xmost) return result; gfxFloat y = PR_MAX(aRect.Y(), Y()); gfxFloat ymost = PR_MIN(aRect.YMost(), YMost()); if (y >= ymost) return result; result = gfxRect(x, y, xmost - x, ymost - y); return result; }
// Test of getting the band data PRBool MySpaceManager::TestGetBandData() { nsresult status; nscoord yMost; // Clear any existing regions ClearRegions(); NS_ASSERTION(mBandList.IsEmpty(), "clear regions failed"); // Make sure YMost() returns the correct result if (NS_ERROR_ABORT != YMost(yMost)) { printf("TestGetBandData: YMost() returned wrong result (#1)\n"); return PR_FALSE; } // Make a band with three rects status = AddRectRegion((nsIFrame*)0x01, nsRect(100, 100, 100, 100)); NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status"); status = AddRectRegion((nsIFrame*)0x02, nsRect(300, 100, 100, 100)); NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status"); status = AddRectRegion((nsIFrame*)0x03, nsRect(500, 100, 100, 100)); NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status"); // Verify that YMost() is correct if ((NS_OK != YMost(yMost)) || (yMost != 200)) { printf("TestGetBandData: YMost() returned wrong value (#2)\n"); return PR_FALSE; } // Get the band data using a very large clip rect and a band data struct // that's large enough nsBandData bandData; nsBandTrapezoid trapezoids[16]; bandData.mSize = 16; bandData.mTrapezoids = trapezoids; status = GetBandData(100, nsSize(10000,10000), bandData); NS_ASSERTION(NS_SUCCEEDED(status), "unexpected status"); // Verify that there are seven trapezoids if (bandData.mCount != 7) { printf("TestGetBandData: wrong trapezoid count (#3)\n"); return PR_FALSE; } // Get the band data using a very large clip rect and a band data struct // that's too small bandData.mSize = 3; status = GetBandData(100, nsSize(10000,10000), bandData); if (NS_SUCCEEDED(status)) { printf("TestGetBandData: ignored band data count (#4)\n"); return PR_FALSE; } // Make sure the count has been updated to reflect the number of trapezoids // required if (bandData.mCount <= bandData.mSize) { printf("TestGetBandData: bad band data count (#5)\n"); return PR_FALSE; } // XXX We need lots more tests here... return PR_TRUE; }
// Intersection. Returns TRUE if the receiver overlaps aRect and // FALSE otherwise PRBool nsRect::Intersects(const nsRect &aRect) const { return (PRBool) ((x < aRect.XMost()) && (y < aRect.YMost()) && (aRect.x < XMost()) && (aRect.y < YMost())); }
//Also Returns true if aRect is Empty PRBool nsRect::Contains(const nsRect &aRect) const { return aRect.IsEmpty() || ((PRBool) ((aRect.x >= x) && (aRect.y >= y) && (aRect.XMost() <= XMost()) && (aRect.YMost() <= YMost()))); }
// Containment PRBool nsRect::Contains(nscoord aX, nscoord aY) const { return (PRBool) ((aX >= x) && (aY >= y) && (aX < XMost()) && (aY < YMost())); }
PRBool gfxRect::Contains(const gfxPoint& aPoint) const { return aPoint.x >= X() && aPoint.x <= XMost() && aPoint.y >= Y() && aPoint.y <= YMost(); }
PRBool gfxRect::Contains(const gfxRect& aRect) const { return aRect.X() >= X() && aRect.XMost() <= XMost() && aRect.Y() >= Y() && aRect.YMost() <= YMost(); }