|
1 | | -namespace Synercoding.Primitives.Extensions |
| 1 | +namespace Synercoding.Primitives.Extensions; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Extension class for <seealso cref="Size"/>. |
| 5 | +/// </summary> |
| 6 | +public static class SizeExtensions |
2 | 7 | { |
3 | 8 | /// <summary> |
4 | | - /// Extension class for <seealso cref="Size"/> |
| 9 | + /// Contract a given <see cref="Size"/> (make smaller). |
5 | 10 | /// </summary> |
6 | | - public static class SizeExtensions |
7 | | - { |
8 | | - /// <summary> |
9 | | - /// Contract a given size (make smaller) |
10 | | - /// </summary> |
11 | | - /// <param name="size">The size to contract</param> |
12 | | - /// <param name="spacing">The amount of space to contract on the sides</param> |
13 | | - /// <returns>A new contacted size</returns> |
14 | | - public static Size Contract(this Size size, Spacing spacing) |
15 | | - => new Size( |
16 | | - width: size.Width - spacing.Left - spacing.Right, |
17 | | - height: size.Height - spacing.Bottom - spacing.Top); |
18 | | - |
19 | | - /// <summary> |
20 | | - /// Expand a given size (make bigger) |
21 | | - /// </summary> |
22 | | - /// <param name="size">The size to expand</param> |
23 | | - /// <param name="spacing">The amount of space to expand on the sides</param> |
24 | | - /// <returns>A new expanded size</returns> |
25 | | - public static Size Expand(this Size size, Spacing spacing) |
26 | | - => new Size( |
27 | | - width: size.Width + spacing.Left + spacing.Right, |
28 | | - height: size.Height + spacing.Bottom + spacing.Top); |
| 11 | + /// <param name="size">The <see cref="Size"/> to contract.</param> |
| 12 | + /// <param name="spacing">The amount of <see cref="Spacing"/> to contract on the sides.</param> |
| 13 | + /// <returns>A new contacted <see cref="Size"/>.</returns> |
| 14 | + public static Size Contract(this Size size, Spacing spacing) |
| 15 | + => new Size( |
| 16 | + width: size.Width - spacing.Left - spacing.Right, |
| 17 | + height: size.Height - spacing.Bottom - spacing.Top); |
29 | 18 |
|
30 | | - /// <summary> |
31 | | - /// Get a <see cref="Rectangle"/> with an origin of 0,0 and Width and Height based upon <paramref name="size"/> |
32 | | - /// </summary> |
33 | | - /// <param name="size">The size to base the <see cref="Rectangle"/> on</param> |
34 | | - /// <returns>A new <see cref="Rectangle"/></returns> |
35 | | - public static Rectangle AsRectangle(this Size size) |
36 | | - => new Rectangle(new Value(0, size.Width.Unit), new Value(0, size.Height.Unit), size.Width, size.Height); |
| 19 | + /// <summary> |
| 20 | + /// Expand a given <see cref="Size"/> (make bigger). |
| 21 | + /// </summary> |
| 22 | + /// <param name="size">The <see cref="Size"/> to expand.</param> |
| 23 | + /// <param name="spacing">The amount of <see cref="Spacing"/> to expand on the sides.</param> |
| 24 | + /// <returns>A new expanded <see cref="Size"/>.</returns> |
| 25 | + public static Size Expand(this Size size, Spacing spacing) |
| 26 | + => new Size( |
| 27 | + width: size.Width + spacing.Left + spacing.Right, |
| 28 | + height: size.Height + spacing.Bottom + spacing.Top); |
37 | 29 |
|
38 | | - /// <summary> |
39 | | - /// Get a <see cref="Size"/> where the Width and Height are switched |
40 | | - /// </summary> |
41 | | - /// <param name="size">The size to base the new size on</param> |
42 | | - /// <returns>A new size with width and height switched</returns> |
43 | | - public static Size Rotate(this Size size) |
44 | | - => new Size(size.Height, size.Width); |
| 30 | + /// <summary> |
| 31 | + /// Get a <see cref="Rectangle"/> with an <see cref="Rectangle.Location"/> of 0,0 and <see cref="Rectangle.Width"/> and <see cref="Rectangle.Height"/> based upon <paramref name="size"/>. |
| 32 | + /// </summary> |
| 33 | + /// <param name="size">The <see cref="Size"/> to base the <see cref="Rectangle"/> on.</param> |
| 34 | + /// <returns>A new <see cref="Rectangle"/>.</returns> |
| 35 | + public static Rectangle AsRectangle(this Size size) |
| 36 | + => new Rectangle(new Value(0, size.Width.Unit), new Value(0, size.Height.Unit), size.Width, size.Height); |
45 | 37 |
|
46 | | - /// <summary> |
47 | | - /// Get the raw values representing this Size in a provided unit |
48 | | - /// </summary> |
49 | | - /// <param name="size">The size to get in raw format</param> |
50 | | - /// <param name="unit">The unit to get the result in.</param> |
51 | | - /// <returns>A tuple representing the raw values.</returns> |
52 | | - public static (double Width, double Height) AsRaw(this Size size, Unit unit) |
53 | | - => (size.Width.AsRaw(unit), size.Height.AsRaw(unit)); |
54 | | - } |
| 38 | + /// <summary> |
| 39 | + /// Get the raw values representing this <see cref="Size"/> in a provided <see cref="Unit"/>. |
| 40 | + /// </summary> |
| 41 | + /// <param name="size">The <see cref="Size"/> to get in raw format.</param> |
| 42 | + /// <param name="unit">The <see cref="Unit"/> to get the result in.</param> |
| 43 | + /// <returns>A tuple representing the raw values.</returns> |
| 44 | + public static (double Width, double Height) AsRaw(this Size size, Unit unit) |
| 45 | + => (size.Width.AsRaw(unit), size.Height.AsRaw(unit)); |
55 | 46 | } |
0 commit comments