-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use special designed Point + Size structs
- Loading branch information
Showing
27 changed files
with
279 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
namespace murrty.structs; | ||
using System.Runtime.InteropServices; | ||
[StructLayout(LayoutKind.Sequential)] | ||
public struct Point { | ||
/// <summary> | ||
/// Represents an invalid Point value. | ||
/// </summary> | ||
public static readonly Point Invalid = new(-32_000, -32_000); | ||
/// <summary> | ||
/// The X-coordinate of the Point. | ||
/// </summary> | ||
public int X { | ||
get; set; | ||
} | ||
|
||
/// <summary> | ||
/// The Y-coordinate of the Point. | ||
/// </summary> | ||
public int Y { | ||
get; set; | ||
} | ||
|
||
/// <summary> | ||
/// Whether the <see cref="Point"/> can be considered a valid <see cref="Point"/> compared to <see cref="Invalid"/>. | ||
/// </summary> | ||
public bool Valid => this.X != Invalid.X && this.Y != Invalid.Y; | ||
|
||
public Point() { | ||
X = 0; | ||
Y = 0; | ||
} | ||
|
||
public Point(int X, int Y) { | ||
this.X = X; | ||
this.Y = Y; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object obj) => obj is Point point && this.X == point.X && this.Y == point.Y; | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() { | ||
int hashCode = 1861411795; | ||
hashCode = hashCode * -1521134295 + this.X.GetHashCode(); | ||
hashCode = hashCode * -1521134295 + this.Y.GetHashCode(); | ||
return hashCode; | ||
} | ||
|
||
public static bool operator ==(Point a, Point b) => a.X == b.X && a.Y == b.Y; | ||
|
||
public static bool operator !=(Point a, Point b) => a.X != b.X || a.Y != b.Y; | ||
|
||
/// <summary> | ||
/// Implicitly converts this Point structure to a System.Drawing.Point structure. | ||
/// </summary> | ||
/// <param name="p"></param> | ||
public static implicit operator System.Drawing.Point(Point p) => new(p.X, p.Y); | ||
|
||
/// <summary> | ||
/// Implicity converts a System.Drawing.Point structure to this Point structure. | ||
/// </summary> | ||
/// <param name="p"></param> | ||
public static implicit operator Point(System.Drawing.Point p) => new(p.X, p.Y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
namespace murrty.structs; | ||
using System.Runtime.InteropServices; | ||
[StructLayout(LayoutKind.Sequential)] | ||
public struct Size { | ||
/// <summary> | ||
/// Represents an empty Size value. | ||
/// </summary> | ||
public static readonly Size Empty = new(0, 0); | ||
/// <summary> | ||
/// The width of the Size. | ||
/// </summary> | ||
public int Width { | ||
get; set; | ||
} | ||
/// <summary> | ||
/// The height of the Size. | ||
/// </summary> | ||
public int Height { | ||
get; set; | ||
} | ||
/// <summary> | ||
/// Whether the <see cref="Size"/> can be considered a valid <see cref="Size"/> compared to <see cref="Empty"/>. | ||
/// </summary> | ||
public bool Valid => this.Width > Empty.Width && this.Height > Empty.Height; | ||
|
||
public Size() { | ||
this = Empty; | ||
} | ||
|
||
public Size(int Width, int Height) { | ||
this.Width = Width; | ||
this.Height = Height; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object obj) => obj is Size size && this.Width == size.Width && this.Height == size.Height; | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() { | ||
int hashCode = 859600377; | ||
hashCode = hashCode * -1521134295 + this.Width.GetHashCode(); | ||
hashCode = hashCode * -1521134295 + this.Height.GetHashCode(); | ||
return hashCode; | ||
} | ||
|
||
/// <summary> | ||
/// Equals-to operator. | ||
/// </summary> | ||
/// <param name="a"></param> | ||
/// <param name="b"></param> | ||
/// <returns></returns> | ||
public static bool operator ==(Size a, Size b) => a.Width == b.Width && a.Height == b.Height; | ||
/// <summary> | ||
/// Not equals-to operator. | ||
/// </summary> | ||
/// <param name="a"></param> | ||
/// <param name="b"></param> | ||
/// <returns></returns> | ||
public static bool operator !=(Size a, Size b) => a.Width != b.Width || a.Height != b.Height; | ||
|
||
/// <summary> | ||
/// Implicitly converts this Point structure to a System.Drawing.Point structure. | ||
/// </summary> | ||
/// <param name="p"></param> | ||
public static implicit operator System.Drawing.Size(Size s) => new(s.Width, s.Height); | ||
|
||
/// <summary> | ||
/// Implicity converts a System.Drawing.Point structure to this Point structure. | ||
/// </summary> | ||
/// <param name="p"></param> | ||
public static implicit operator Size(System.Drawing.Size s) => new(s.Width, s.Height); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.