Add SkIRect::adjust method
Change-Id: Ib18d1a82944524e20d5d72912d8db7a823c470de Reviewed-on: https://skia-review.googlesource.com/128884 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Cary Clark <caryclark@google.com>
This commit is contained in:
parent
dd8b1fc41b
commit
8f8d481b44
@ -1041,6 +1041,41 @@ describes an area: fLeft is less than fRight, and fTop is less than fBottom.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB)
|
||||
|
||||
#In Inset_Outset_Offset
|
||||
#Line # moves the sides independently relative to their original locations ##
|
||||
Adjusts IRect by adding dL to fLeft, dT to fTop, dR to fRight, and fB to fBottom.
|
||||
|
||||
If dL is positive, narrows IRect on the left. If negative, widens it on the left.
|
||||
If dT is positive, shrinks IRect on the top. If negative, lengthens it on the top.
|
||||
If dR is positive, narrows IRect on the right. If negative, widens it on the right.
|
||||
If dB is positive, shrinks IRect on the bottom. If negative, lengthens it on the bottom.
|
||||
|
||||
The resulting IRect is not checked for validity. Thus, if the resulting IRect left is
|
||||
greater than right, the IRect will be considered empty. Call sort() after this call
|
||||
if that is not the desired behavior.
|
||||
|
||||
#Param dL offset added to fLeft ##
|
||||
#Param dT offset added to fTop ##
|
||||
#Param dR offset added to fRight ##
|
||||
#Param dB offset added to fBottom ##
|
||||
|
||||
#Example
|
||||
SkIRect rect = { 8, 11, 19, 22 };
|
||||
rect.adjust(2, -1, 1, -2);
|
||||
SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
|
||||
#StdOut
|
||||
rect: 10, 10, 20, 20
|
||||
##
|
||||
##
|
||||
|
||||
#SeeAlso inset outset
|
||||
|
||||
##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method bool contains(int32_t x, int32_t y) const
|
||||
|
||||
#In Intersection
|
||||
|
@ -413,6 +413,25 @@ struct SK_API SkIRect {
|
||||
*/
|
||||
void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); }
|
||||
|
||||
/** Adjust SkIRect by adding dL to fLeft, dT to fTop, dR to fRight and fB to fBottom.
|
||||
|
||||
If dL is positive, narrows SkIRect on the left. If negative, widens it on the left.
|
||||
If dT is positive, shrinks SkIRect on the top. If negative, lengthens it on the top.
|
||||
If dR is positive, narrows SkIRect on the right. If negative, widens it on the right.
|
||||
If dB is positive, shrinks SkIRect on the bottom. If negative, lengthens it on the bottom.
|
||||
|
||||
@param dL offset added to fLeft
|
||||
@param dT offset added to fTop
|
||||
@param dR offset added to fRight
|
||||
@param dB offset added to fBottom
|
||||
*/
|
||||
void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB) {
|
||||
fLeft = Sk32_sat_add(fLeft, dL);
|
||||
fTop = Sk32_sat_add(fTop, dT);
|
||||
fRight = Sk32_sat_add(fRight, dR);
|
||||
fBottom = Sk32_sat_add(fBottom, dB);
|
||||
}
|
||||
|
||||
/** Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
|
||||
Returns false if SkIRect is empty.
|
||||
|
||||
|
@ -505,9 +505,8 @@ SkIRect SkImageFilter::DetermineRepeatedSrcBound(const SkIRect& srcBounds,
|
||||
const SkISize& filterSize,
|
||||
const SkIRect& originalSrcBounds) {
|
||||
SkIRect tmp = srcBounds;
|
||||
tmp.fRight = Sk32_sat_add(tmp.fRight, filterSize.fWidth);
|
||||
tmp.fBottom = Sk32_sat_add(tmp.fBottom, filterSize.fHeight);
|
||||
tmp.offset(-filterOffset.fX, -filterOffset.fY);
|
||||
tmp.adjust(-filterOffset.fX, -filterOffset.fY,
|
||||
filterSize.fWidth - filterOffset.fX, filterSize.fHeight - filterOffset.fY);
|
||||
|
||||
if (tmp.fLeft < originalSrcBounds.fLeft || tmp.fRight > originalSrcBounds.fRight) {
|
||||
tmp.fLeft = originalSrcBounds.fLeft;
|
||||
|
@ -452,12 +452,12 @@ SkIRect SkMatrixConvolutionImageFilter::onFilterNodeBounds(const SkIRect& src, c
|
||||
|
||||
SkIRect dst = src;
|
||||
int w = fKernelSize.width() - 1, h = fKernelSize.height() - 1;
|
||||
dst.fRight = Sk32_sat_add(dst.fRight, w);
|
||||
dst.fBottom = Sk32_sat_add(dst.fBottom, h);
|
||||
|
||||
if (kReverse_MapDirection == dir) {
|
||||
dst.offset(-fKernelOffset);
|
||||
dst.adjust(-fKernelOffset.fX, -fKernelOffset.fY,
|
||||
w - fKernelOffset.fX, h - fKernelOffset.fY);
|
||||
} else {
|
||||
dst.offset(fKernelOffset - SkIPoint::Make(w, h));
|
||||
dst.adjust(fKernelOffset.fX - w, fKernelOffset.fY - h, fKernelOffset.fX, fKernelOffset.fY);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user