Skip to content

Commit 6c7b59f

Browse files
committed
reduce to a single par of clamping operations
1 parent dd705eb commit 6c7b59f

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,9 @@ protected override void OnFrameApply(ImageFrame<TPixelBg> source)
9696
top = 0;
9797
}
9898

99-
if (left > source.Width - foregroundRectangle.Width)
100-
{
101-
// will overhange, lets trim it down
102-
int diff = (left + foregroundRectangle.Width) - source.Width;
103-
foregroundRectangle.Width -= diff;
104-
}
105-
106-
if (top > source.Height - foregroundRectangle.Height)
107-
{
108-
// will overhange, lets trim it down
109-
int diff = (top + foregroundRectangle.Height) - source.Height;
110-
foregroundRectangle.Height -= diff;
111-
}
99+
// clamp the height/width to the availible space left to prevent overflowing
100+
foregroundRectangle.Width = Math.Min(source.Width - left, foregroundRectangle.Width);
101+
foregroundRectangle.Height = Math.Min(source.Height - top, foregroundRectangle.Height);
112102

113103
int width = foregroundRectangle.Width;
114104
int height = foregroundRectangle.Height;

0 commit comments

Comments
 (0)