Skip to content

Commit c88583e

Browse files
Added Distance<T> implementation, and unit tests.
1 parent 54d322f commit c88583e

27 files changed

+1695
-37
lines changed

OnixLabs.Units.UnitTests/DistanceTests.cs

Lines changed: 665 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
<IsPackable>false</IsPackable>
8-
</PropertyGroup>
9-
102
<ItemGroup>
11-
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
13-
<PackageReference Include="xunit" Version="2.9.2"/>
14-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>
3+
<ProjectReference Include="..\OnixLabs.Numerics\OnixLabs.Numerics.csproj"/>
4+
<ProjectReference Include="..\OnixLabs.Units\OnixLabs.Units.csproj"/>
155
</ItemGroup>
16-
17-
<ItemGroup>
18-
<Using Include="Xunit"/>
19-
</ItemGroup>
20-
21-
<ItemGroup>
22-
<ProjectReference Include="..\OnixLabs.Numerics\OnixLabs.Numerics.csproj" />
23-
<ProjectReference Include="..\OnixLabs.Units\OnixLabs.Units.csproj" />
24-
</ItemGroup>
25-
266
</Project>

OnixLabs.Units/DataSize.Arithmetic.Addition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace OnixLabs.Units;
1616

17+
// ReSharper disable MemberCanBePrivate.Global
1718
public readonly partial struct DataSize<T>
1819
{
1920
/// <summary>

OnixLabs.Units/DataSize.Arithmetic.Division.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace OnixLabs.Units;
1616

17+
// ReSharper disable MemberCanBePrivate.Global
1718
public readonly partial struct DataSize<T>
1819
{
1920
/// <summary>

OnixLabs.Units/DataSize.Arithmetic.Multiplication.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace OnixLabs.Units;
1616

17+
// ReSharper disable MemberCanBePrivate.Global
1718
public readonly partial struct DataSize<T>
1819
{
1920
/// <summary>

OnixLabs.Units/DataSize.Arithmetic.Subtraction.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace OnixLabs.Units;
1616

17+
// ReSharper disable MemberCanBePrivate.Global
1718
public readonly partial struct DataSize<T>
1819
{
1920
/// <summary>

OnixLabs.Units/DataSize.To.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ public readonly partial struct DataSize<T>
2222
/// <summary>
2323
/// Formats the value of the current instance using the default format.
2424
/// </summary>
25-
/// <returns>The value of the current instance in the default format.</returns>
25+
/// <returns>Returns the value of the current instance in the default format.</returns>
2626
public override string ToString() => ToString(BitsSpecifier);
2727

2828
/// <summary>
2929
/// Formats the value of the current instance using the specified format.
3030
/// </summary>
3131
/// <param name="format">The format to use, or null to use the default format.</param>
3232
/// <param name="formatProvider">The provider to use to format the value.</param>
33-
/// <returns>The value of the current instance in the specified format.</returns>
33+
/// <returns>Returns the value of the current instance in the specified format.</returns>
3434
public string ToString(string? format, IFormatProvider? formatProvider = null) => ToString(format.AsSpan(), formatProvider);
3535

3636
/// <summary>
3737
/// Formats the value of the current instance using the specified format.
3838
/// </summary>
3939
/// <param name="format">The format to use, or null to use the default format.</param>
4040
/// <param name="formatProvider">The provider to use to format the value.</param>
41-
/// <returns>The value of the current instance in the specified format.</returns>
41+
/// <returns>Returns the value of the current instance in the specified format.</returns>
4242
public string ToString(ReadOnlySpan<char> format, IFormatProvider? formatProvider = null)
4343
{
4444
(string specifier, int scale) = format.GetSpecifierAndScale(defaultSpecifier: BitsSpecifier);

OnixLabs.Units/DataSize.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace OnixLabs.Units;
2222
/// Represents a unit of data size.
2323
/// </summary>
2424
/// <typeparam name="T">The underlying floating point value.</typeparam>
25+
// ReSharper disable MemberCanBePrivate.Global
2526
public readonly partial struct DataSize<T> :
2627
IValueEquatable<DataSize<T>>,
2728
IValueComparable<DataSize<T>>,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020-2025 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace OnixLabs.Units;
16+
17+
// ReSharper disable MemberCanBePrivate.Global
18+
public readonly partial struct Distance<T>
19+
{
20+
/// <summary>
21+
/// Computes the sum of the specified <see cref="Distance{T}"/> values.
22+
/// </summary>
23+
/// <param name="left">The left-hand value to add to.</param>
24+
/// <param name="right">The right-hand value to add.</param>
25+
/// <returns>Returns the sum of the specified <see cref="Distance{T}"/> values.</returns>
26+
public static Distance<T> Add(Distance<T> left, Distance<T> right) => new(left.QuectoMeters + right.QuectoMeters);
27+
28+
/// <summary>
29+
/// Computes the sum of the specified <see cref="Distance{T}"/> values.
30+
/// </summary>
31+
/// <param name="left">The left-hand value to add to.</param>
32+
/// <param name="right">The right-hand value to add.</param>
33+
/// <returns>Returns the sum of the specified <see cref="Distance{T}"/> values.</returns>
34+
public static Distance<T> operator +(Distance<T> left, Distance<T> right) => Add(left, right);
35+
36+
/// <summary>
37+
/// Computes the sum of the current <see cref="Distance{T}"/> value and the specified other <see cref="Distance{T}"/> value.
38+
/// </summary>
39+
/// <param name="other">The value to add to the current <see cref="Distance{T}"/> value.</param>
40+
/// <returns>Returns the sum of the current <see cref="Distance{T}"/> value and the specified other <see cref="Distance{T}"/> value.</returns>
41+
public Distance<T> Add(Distance<T> other) => Add(this, other);
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2020-2025 ONIXLabs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace OnixLabs.Units;
16+
17+
// ReSharper disable MemberCanBePrivate.Global
18+
public readonly partial struct Distance<T>
19+
{
20+
/// <summary>
21+
/// Computes the quotient of the specified <see cref="Distance{T}"/> values.
22+
/// </summary>
23+
/// <param name="left">The left-hand value to divide.</param>
24+
/// <param name="right">The right-hand value to divide by.</param>
25+
/// <returns>Returns the quotient of the specified <see cref="Distance{T}"/> values.</returns>
26+
public static Distance<T> Divide(Distance<T> left, Distance<T> right) => new(left.QuectoMeters / right.QuectoMeters);
27+
28+
/// <summary>
29+
/// Computes the quotient of the specified <see cref="Distance{T}"/> values.
30+
/// </summary>
31+
/// <param name="left">The left-hand value to divide.</param>
32+
/// <param name="right">The right-hand value to divide by.</param>
33+
/// <returns>Returns the quotient of the specified <see cref="Distance{T}"/> values.</returns>
34+
public static Distance<T> operator /(Distance<T> left, Distance<T> right) => Divide(left, right);
35+
36+
/// <summary>
37+
/// Computes the quotient of the current <see cref="Distance{T}"/> value, divided by the specified other <see cref="Distance{T}"/> value.
38+
/// </summary>
39+
/// <param name="other">The value to divide the current <see cref="Distance{T}"/> value by.</param>
40+
/// <returns>Returns the quotient of the current <see cref="Distance{T}"/> value, divided by the specified other <see cref="Distance{T}"/> value.</returns>
41+
public Distance<T> Divide(Distance<T> other) => Divide(this, other);
42+
}

0 commit comments

Comments
 (0)