Skip to content

Commit 05ecd3d

Browse files
committed
Reuse existing contract/expand extensions
1 parent 3709e68 commit 05ecd3d

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

src/Synercoding.Primitives/Extensions/RectangleExtensions.cs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,37 @@ namespace Synercoding.Primitives.Extensions;
55
/// </summary>
66
public static class RectangleExtensions
77
{
8+
/// <summary>
9+
/// Contract a given <see cref="Rectangle"/> (make smaller).
10+
/// </summary>
11+
/// <param name="rectangle">The <see cref="Rectangle"/> to contract.</param>
12+
/// <param name="value">The amount to contract of each side of the <see cref="Size"/></param>
13+
/// <returns>A new contracted <see cref="Rectangle"/>.</returns>
14+
public static Rectangle Contract(this Rectangle rectangle, Value value)
15+
=> rectangle.Contract(new Spacing(value));
16+
17+
/// <summary>
18+
/// Expand a given <see cref="Rectangle"/> (make bigger).
19+
/// </summary>
20+
/// <param name="rectangle">The <see cref="Rectangle"/> to expand.</param>
21+
/// <param name="value">The amount to expand to each side of the <see cref="Size"/></param>
22+
/// <returns>A new expanded <see cref="Rectangle"/>.</returns>
23+
public static Rectangle Expand(this Rectangle rectangle, Value value)
24+
=> rectangle.Expand(new Spacing(value));
25+
826
/// <summary>
927
/// Contract a given <see cref="Rectangle"/> (make smaller).
1028
/// </summary>
1129
/// <param name="rectangle">The <see cref="Rectangle"/> to contract.</param>
1230
/// <param name="spacing">The amount of <see cref="Spacing"/> to contract on the sides.</param>
13-
/// <returns>A new contacted <see cref="Rectangle"/>.</returns>
31+
/// <returns>A new contracted <see cref="Rectangle"/>.</returns>
1432
public static Rectangle Contract(this Rectangle rectangle, Spacing spacing)
1533
=> new Rectangle(
1634
llx: rectangle.LLX + spacing.Left,
1735
lly: rectangle.LLY + spacing.Bottom,
1836
urx: rectangle.URX - spacing.Right,
1937
ury: rectangle.URY - spacing.Top);
2038

21-
/// <summary>
22-
/// Contract a given <see cref="Rectangle"/> (make smaller).
23-
/// </summary>
24-
/// <param name="rectangle">The <see cref="Rectangle"/> to contract.</param>
25-
/// <param name="value">The amount of <see cref="Value"/> to contract on all sides.</param>
26-
/// <returns>A new contacted <see cref="Rectangle"/>.</returns>
27-
public static Rectangle Contract(this Rectangle rectangle, Value value)
28-
=> new Rectangle(
29-
llx: rectangle.LLX + value,
30-
lly: rectangle.LLY + value,
31-
urx: rectangle.URX - value,
32-
ury: rectangle.URY - value);
33-
3439
/// <summary>
3540
/// Expand a given <see cref="Rectangle"/> (make bigger).
3641
/// </summary>
@@ -44,19 +49,6 @@ public static Rectangle Expand(this Rectangle rectangle, Spacing spacing)
4449
urx: rectangle.URX + spacing.Right,
4550
ury: rectangle.URY + spacing.Top);
4651

47-
/// <summary>
48-
/// Expand a given <see cref="Rectangle"/> (make bigger).
49-
/// </summary>
50-
/// <param name="rectangle">The rectangle to expand</param>
51-
/// <param name="value">The amount of <see cref="Value"/> to expand on all sides.</param>
52-
/// <returns>A new expanded <see cref="Rectangle"/>.</returns>
53-
public static Rectangle Expand(this Rectangle rectangle, Value value)
54-
=> new Rectangle(
55-
llx: rectangle.LLX - value,
56-
lly: rectangle.LLY - value,
57-
urx: rectangle.URX + value,
58-
ury: rectangle.URY + value);
59-
6052
/// <summary>
6153
/// Get the raw values representing this <see cref="Rectangle"/> in a provided unit.
6254
/// </summary>

src/Synercoding.Primitives/Extensions/SizeExtensions.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,30 @@ namespace Synercoding.Primitives.Extensions;
55
/// </summary>
66
public static class SizeExtensions
77
{
8+
/// <summary>
9+
/// Contract a given <see cref="Size"/> (make smaller).
10+
/// </summary>
11+
/// <param name="size">The <see cref="Size"/> to contract.</param>
12+
/// <param name="value">The amount to contract of each side of the <see cref="Size"/></param>
13+
/// <returns>A new contracted <see cref="Size"/>.</returns>
14+
public static Size Contract(this Size size, Value value)
15+
=> size.Contract(new Spacing(value));
16+
17+
/// <summary>
18+
/// Expand a given <see cref="Size"/> (make bigger).
19+
/// </summary>
20+
/// <param name="size">The <see cref="Size"/> to expand.</param>
21+
/// <param name="value">The amount to expand to each side of the <see cref="Size"/></param>
22+
/// <returns>A new expanded <see cref="Size"/>.</returns>
23+
public static Size Expand(this Size size, Value value)
24+
=> size.Expand(new Spacing(value));
25+
826
/// <summary>
927
/// Contract a given <see cref="Size"/> (make smaller).
1028
/// </summary>
1129
/// <param name="size">The <see cref="Size"/> to contract.</param>
1230
/// <param name="spacing">The amount of <see cref="Spacing"/> to contract on the sides.</param>
13-
/// <returns>A new contacted <see cref="Size"/>.</returns>
31+
/// <returns>A new contracted <see cref="Size"/>.</returns>
1432
public static Size Contract(this Size size, Spacing spacing)
1533
=> new Size(
1634
width: size.Width - spacing.Left - spacing.Right,

0 commit comments

Comments
 (0)