Skip to content

Commit fce98a6

Browse files
authored
Merge pull request #12 from synercoder/develop
Preparing release rc02
2 parents 585cedd + a8db7be commit fce98a6

File tree

19 files changed

+871
-174
lines changed

19 files changed

+871
-174
lines changed

.github/workflows/dotnet-core.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: .NET Core
22
on:
3+
push:
4+
branches:
5+
- develop
36
pull_request:
47
release:
58
types:

Directory.Build.props

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@
4444
<LangVersion>8.0</LangVersion>
4545
</PropertyGroup>
4646

47+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
48+
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
49+
</PropertyGroup>
50+
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
51+
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
52+
</PropertyGroup>
53+
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
54+
<DefineConstants>$(DefineConstants);SUPPORTS_HASHCODE</DefineConstants>
55+
</PropertyGroup>
56+
4757
</Project>

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
Primitives with types attached (think mm, cm, in, px) that can be used for 2D graphics.
44

5+
## Build status
6+
7+
Develop: ![.NET Core](https://github.com/synercoder/Primitives/workflows/.NET%20Core/badge.svg?branch=develop)
8+
59
## License
610
This project is licensed under MIT license.

src/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Project>
33

44
<PropertyGroup>
5+
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.6</TargetFrameworks>
56
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props</MSBuildAllProjects>
67
<SynercodingProjectCategory>src</SynercodingProjectCategory>
78
</PropertyGroup>

src/Synercoding.Primitives/Extensions/SizeExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static Size Expand(this Size size, Spacing spacing)
3333
/// <param name="size">The size to base the <see cref="Rectangle"/> on</param>
3434
/// <returns>A new <see cref="Rectangle"/></returns>
3535
public static Rectangle AsRectangle(this Size size)
36-
=> new Rectangle(new UnitValue(0, size.Width.Unit), new UnitValue(0, size.Height.Unit), size.Width, size.Height);
36+
=> new Rectangle(new Value(0, size.Width.Unit), new Value(0, size.Height.Unit), size.Width, size.Height);
3737

3838
/// <summary>
3939
/// Get a <see cref="Size"/> where the Width and Height are switched

src/Synercoding.Primitives/PackageDetails.props

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
<Product>Synercoding.Primitives</Product>
1111
<Title>Synercoding.Primitives</Title>
1212
<Description>Primitives with types attached (think mm, cm, in, px) that can be used for 2D graphics.</Description>
13-
<PackageReleaseNotes>Initial alpha release.</PackageReleaseNotes>
13+
<PackageReleaseNotes>- Removed implicit double conversion, to easy to make a mistake with the wrong unit type
14+
- Added equality and inequality operators to all structs
15+
- Added multiple target-frameworks
16+
- Added multiplication operator for Value on other side
17+
- Renamed UnitValue to Value
18+
- Fixed a few nullability warnings</PackageReleaseNotes>
1419
</PropertyGroup>
1520

1621
</Project>

src/Synercoding.Primitives/Point.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ namespace Synercoding.Primitives
1616
/// <param name="unit">The unit type of the coordinates</param>
1717
public Point(double x, double y, Unit unit)
1818
{
19-
X = new UnitValue(x, unit);
20-
Y = new UnitValue(y, unit);
19+
X = new Value(x, unit);
20+
Y = new Value(y, unit);
2121
}
2222

2323
/// <summary>
2424
/// Constructor for a <see cref="Point"/>
2525
/// </summary>
2626
/// <param name="x">The X coordinate</param>
2727
/// <param name="y">The Y coordinate</param>
28-
public Point(UnitValue x, UnitValue y)
28+
public Point(Value x, Value y)
2929
{
3030
X = x;
3131
Y = y;
@@ -36,7 +36,7 @@ public Point(UnitValue x, UnitValue y)
3636
/// </summary>
3737
/// <param name="x">Out parameter for the <see cref="X"/> property</param>
3838
/// <param name="y">Out parameter for the <see cref="Y"/> property</param>
39-
public void Deconstruct(out UnitValue x, out UnitValue y)
39+
public void Deconstruct(out Value x, out Value y)
4040
{
4141
x = X;
4242
y = Y;
@@ -51,12 +51,12 @@ public static Point Origin
5151
/// <summary>
5252
/// The X coordinate
5353
/// </summary>
54-
public UnitValue X { get; }
54+
public Value X { get; }
5555

5656
/// <summary>
5757
/// The Y coordinate
5858
/// </summary>
59-
public UnitValue Y { get; }
59+
public Value Y { get; }
6060

6161
/// <inheritdoc />
6262
public Point ConvertTo(Unit unit)
@@ -71,10 +71,8 @@ public override int GetHashCode()
7171
=> HashCode.Combine(X, Y);
7272

7373
/// <inheritdoc />
74-
public override bool Equals(object obj)
75-
{
76-
return obj is Point unit && Equals(unit);
77-
}
74+
public override bool Equals(object? obj)
75+
=> obj is Point unit && Equals(unit);
7876

7977
/// <inheritdoc />
8078
public bool Equals(Point other)
@@ -89,5 +87,23 @@ public bool Equals(Point other)
8987
/// <inheritdoc />
9088
public override string ToString()
9189
=> $"X: {X}, Y: {Y}";
90+
91+
/// <summary>
92+
/// Returns a value that indicates whether two specified <see cref="Point"/> values are equal.
93+
/// </summary>
94+
/// <param name="left">The first value to compare.</param>
95+
/// <param name="right">The second value to compare.</param>
96+
/// <returns>true if left and right are equal; otherwise, false.</returns>
97+
public static bool operator ==(Point left, Point right)
98+
=> left.Equals(right);
99+
100+
/// <summary>
101+
/// Returns a value that indicates whether two specified <see cref="Point"/> values are not equal.
102+
/// </summary>
103+
/// <param name="left">The first value to compare.</param>
104+
/// <param name="right">The second value to compare.</param>
105+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
106+
public static bool operator !=(Point left, Point right)
107+
=> !( left == right );
92108
}
93109
}

src/Synercoding.Primitives/Rectangle.cs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace Synercoding.Primitives
1818
/// <param name="unit">The unit type of the coordinates</param>
1919
public Rectangle(double llx, double lly, double urx, double ury, Unit unit)
2020
{
21-
LLX = new UnitValue(llx, unit);
22-
LLY = new UnitValue(lly, unit);
23-
URX = new UnitValue(urx, unit);
24-
URY = new UnitValue(ury, unit);
21+
LLX = new Value(llx, unit);
22+
LLY = new Value(lly, unit);
23+
URX = new Value(urx, unit);
24+
URY = new Value(ury, unit);
2525
}
2626

2727
/// <summary>
@@ -31,7 +31,7 @@ public Rectangle(double llx, double lly, double urx, double ury, Unit unit)
3131
/// <param name="lly">The lower left y coordinate</param>
3232
/// <param name="urx">The upper right x coordinate</param>
3333
/// <param name="ury">The upper right y coordinate</param>
34-
public Rectangle(UnitValue llx, UnitValue lly, UnitValue urx, UnitValue ury)
34+
public Rectangle(Value llx, Value lly, Value urx, Value ury)
3535
{
3636
LLX = llx;
3737
LLY = lly;
@@ -70,7 +70,7 @@ public void Deconstruct(out Point location, out Size size)
7070
/// <param name="lly">The out parameter for the lower left y coordinate</param>
7171
/// <param name="urx">The out parameter for the upper right x coordinate</param>
7272
/// <param name="ury">The out parameter for the upper right y coordinate</param>
73-
public void Deconstruct(out UnitValue llx, out UnitValue lly, out UnitValue urx, out UnitValue ury)
73+
public void Deconstruct(out Value llx, out Value lly, out Value urx, out Value ury)
7474
{
7575
llx = LLX;
7676
lly = LLY;
@@ -87,33 +87,33 @@ public static Rectangle Zero
8787
/// <summary>
8888
/// The lower left x coordinate
8989
/// </summary>
90-
public UnitValue LLX { get; }
90+
public Value LLX { get; }
9191

9292
/// <summary>
9393
/// The lower left y coordinate
9494
/// </summary>
95-
public UnitValue LLY { get; }
95+
public Value LLY { get; }
9696

9797
/// <summary>
9898
/// The upper right x coordinate
9999
/// </summary>
100-
public UnitValue URX { get; }
100+
public Value URX { get; }
101101

102102
/// <summary>
103103
/// The upper right y coordinate
104104
/// </summary>
105-
public UnitValue URY { get; }
105+
public Value URY { get; }
106106

107107
/// <summary>
108108
/// The width of this <see cref="Rectangle"/>
109109
/// </summary>
110-
public UnitValue Width
110+
public Value Width
111111
=> URX - LLX;
112112

113113
/// <summary>
114114
/// The height of this <see cref="Rectangle"/>
115115
/// </summary>
116-
public UnitValue Height
116+
public Value Height
117117
=> URY - LLY;
118118

119119
/// <summary>
@@ -143,10 +143,8 @@ public override int GetHashCode()
143143
=> HashCode.Combine(LLX, LLY, URX, URY);
144144

145145
/// <inheritdoc/>
146-
public override bool Equals(object obj)
147-
{
148-
return obj is Rectangle unit && Equals(unit);
149-
}
146+
public override bool Equals(object? obj)
147+
=> obj is Rectangle unit && Equals(unit);
150148

151149
/// <inheritdoc/>
152150
public bool Equals(Rectangle other)
@@ -163,5 +161,23 @@ public bool Equals(Rectangle other)
163161
/// <inheritdoc/>
164162
public override string ToString()
165163
=> $"LLX {LLX}, LLY {LLY}, URX {URX}, URY {URY}";
164+
165+
/// <summary>
166+
/// Returns a value that indicates whether two specified <see cref="Rectangle"/> values are equal.
167+
/// </summary>
168+
/// <param name="left">The first value to compare.</param>
169+
/// <param name="right">The second value to compare.</param>
170+
/// <returns>true if left and right are equal; otherwise, false.</returns>
171+
public static bool operator ==(Rectangle left, Rectangle right)
172+
=> left.Equals(right);
173+
174+
/// <summary>
175+
/// Returns a value that indicates whether two specified <see cref="Rectangle"/> values are not equal.
176+
/// </summary>
177+
/// <param name="left">The first value to compare.</param>
178+
/// <param name="right">The second value to compare.</param>
179+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
180+
public static bool operator !=(Rectangle left, Rectangle right)
181+
=> !( left == right );
166182
}
167183
}

src/Synercoding.Primitives/Size.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ namespace Synercoding.Primitives
1616
/// <param name="unit">The unit of the <see cref="Size"/></param>
1717
public Size(double width, double height, Unit unit)
1818
{
19-
Width = new UnitValue(width, unit);
20-
Height = new UnitValue(height, unit);
19+
Width = new Value(width, unit);
20+
Height = new Value(height, unit);
2121
}
2222

2323
/// <summary>
2424
/// Constructor for a <see cref="Size"/>
2525
/// </summary>
2626
/// <param name="width">The width parameter</param>
2727
/// <param name="height">The height parameter</param>
28-
public Size(UnitValue width, UnitValue height)
28+
public Size(Value width, Value height)
2929
{
3030
Width = width;
3131
Height = height;
@@ -36,7 +36,7 @@ public Size(UnitValue width, UnitValue height)
3636
/// </summary>
3737
/// <param name="width">Out parameter for the <see cref="Width"/> property</param>
3838
/// <param name="height">Out parameter for the <see cref="Height"/> property</param>
39-
public void Deconstruct(out UnitValue width, out UnitValue height)
39+
public void Deconstruct(out Value width, out Value height)
4040
{
4141
width = Width;
4242
height = Height;
@@ -51,12 +51,12 @@ public static Size Empty
5151
/// <summary>
5252
/// The width property
5353
/// </summary>
54-
public UnitValue Width { get; }
54+
public Value Width { get; }
5555

5656
/// <summary>
5757
/// The height property
5858
/// </summary>
59-
public UnitValue Height { get; }
59+
public Value Height { get; }
6060

6161
/// <summary>
6262
/// Get the <see cref="Primitives.Orientation"/> of the size
@@ -73,8 +73,8 @@ public Orientation Orientation
7373
public Size ConvertTo(Unit unit)
7474
{
7575
return new Size(
76-
width: Width.ConvertTo(unit),
77-
height: Height.ConvertTo(unit),
76+
width: Width.ConvertTo(unit).Raw,
77+
height: Height.ConvertTo(unit).Raw,
7878
unit);
7979
}
8080

@@ -83,10 +83,8 @@ public override int GetHashCode()
8383
=> HashCode.Combine(Width, Height);
8484

8585
/// <inheritdoc/>
86-
public override bool Equals(object obj)
87-
{
88-
return obj is Size unit && Equals(unit);
89-
}
86+
public override bool Equals(object? obj)
87+
=> obj is Size unit && Equals(unit);
9088

9189
/// <inheritdoc/>
9290
public bool Equals(Size other)
@@ -101,5 +99,23 @@ public bool Equals(Size other)
10199
/// <inheritdoc/>
102100
public override string ToString()
103101
=> $"W: {Width}, H: {Height}";
102+
103+
/// <summary>
104+
/// Returns a value that indicates whether two specified <see cref="Size"/> values are equal.
105+
/// </summary>
106+
/// <param name="left">The first value to compare.</param>
107+
/// <param name="right">The second value to compare.</param>
108+
/// <returns>true if left and right are equal; otherwise, false.</returns>
109+
public static bool operator ==(Size left, Size right)
110+
=> left.Equals(right);
111+
112+
/// <summary>
113+
/// Returns a value that indicates whether two specified <see cref="Size"/> values are not equal.
114+
/// </summary>
115+
/// <param name="left">The first value to compare.</param>
116+
/// <param name="right">The second value to compare.</param>
117+
/// <returns>true if left and right are not equal; otherwise, false.</returns>
118+
public static bool operator !=(Size left, Size right)
119+
=> !( left == right );
104120
}
105121
}

0 commit comments

Comments
 (0)