add more utilities: roundIn(), offsetTo()
git-svn-id: http://skia.googlecode.com/svn/trunk@6320 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
411bb7237e
commit
4d3038379d
@ -142,6 +142,16 @@ struct SK_API SkIRect {
|
||||
this->offset(delta.fX, delta.fY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset this rect such its new x() and y() will equal newX and newY.
|
||||
*/
|
||||
void offsetTo(int32_t newX, int32_t newY) {
|
||||
fRight += newX - fLeft;
|
||||
fBottom += newY - fTop;
|
||||
fLeft = newX;
|
||||
fTop = newY;
|
||||
}
|
||||
|
||||
/** Inset the rectangle by (dx,dy). If dx is positive, then the sides are moved inwards,
|
||||
making the rectangle narrower. If dx is negative, then the sides are moved outwards,
|
||||
making the rectangle wider. The same holds true for dy and the top and bottom.
|
||||
@ -519,6 +529,16 @@ struct SK_API SkRect {
|
||||
this->offset(delta.fX, delta.fY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset this rect such its new x() and y() will equal newX and newY.
|
||||
*/
|
||||
void offsetTo(SkScalar newX, SkScalar newY) {
|
||||
fRight += newX - fLeft;
|
||||
fBottom += newY - fTop;
|
||||
fLeft = newX;
|
||||
fTop = newY;
|
||||
}
|
||||
|
||||
/** Inset the rectangle by (dx,dy). If dx is positive, then the sides are
|
||||
moved inwards, making the rectangle narrower. If dx is negative, then
|
||||
the sides are moved outwards, making the rectangle wider. The same holds
|
||||
@ -656,8 +676,8 @@ struct SK_API SkRect {
|
||||
*/
|
||||
void round(SkIRect* dst) const {
|
||||
SkASSERT(dst);
|
||||
dst->set(SkScalarRound(fLeft), SkScalarRound(fTop),
|
||||
SkScalarRound(fRight), SkScalarRound(fBottom));
|
||||
dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
|
||||
SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -666,8 +686,8 @@ struct SK_API SkRect {
|
||||
*/
|
||||
void roundOut(SkIRect* dst) const {
|
||||
SkASSERT(dst);
|
||||
dst->set(SkScalarFloor(fLeft), SkScalarFloor(fTop),
|
||||
SkScalarCeil(fRight), SkScalarCeil(fBottom));
|
||||
dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
|
||||
SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -682,6 +702,19 @@ struct SK_API SkRect {
|
||||
SkScalarCeilToScalar(fBottom));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dst rectangle by rounding "in" this rectangle, choosing the
|
||||
* ceil of top and left, and the floor of right and bottom. This does *not*
|
||||
* call sort(), so it is possible that the resulting rect is inverted...
|
||||
* e.g. left >= right or top >= bottom. Call isEmpty() to detect that.
|
||||
*/
|
||||
void roundIn(SkIRect* dst) const {
|
||||
SkASSERT(dst);
|
||||
dst->set(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
|
||||
SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Swap top/bottom or left/right if there are flipped (i.e. if width()
|
||||
* or height() would have returned a negative value.) This should be called
|
||||
|
Loading…
Reference in New Issue
Block a user