Skip to content

Commit

Permalink
update .net8
Browse files Browse the repository at this point in the history
  • Loading branch information
tk-yoshimura committed Jan 20, 2024
1 parent 40460f9 commit fec1e0e
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 72 deletions.
7 changes: 1 addition & 6 deletions ShapeFitting.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShapeFittingTest", "ShapeFi
{22613731-5DDC-4EF7-B60B-3F217C6B7035} = {22613731-5DDC-4EF7-B60B-3F217C6B7035}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0211DD41-0938-4BC1-BA21-261315195536}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShapeFittingBenchmark", "ShapeFittingBenchmark\ShapeFittingBenchmark.csproj", "{F038C75C-DA22-48B4-9A07-C825ED0E65B9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShapeFittingBenchmark", "ShapeFittingBenchmark\ShapeFittingBenchmark.csproj", "{F038C75C-DA22-48B4-9A07-C825ED0E65B9}"
ProjectSection(ProjectDependencies) = postProject
{22613731-5DDC-4EF7-B60B-3F217C6B7035} = {22613731-5DDC-4EF7-B60B-3F217C6B7035}
EndProjectSection
Expand Down
8 changes: 4 additions & 4 deletions ShapeFitting/Algebra/AlgebraD2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public static ((double val, Vector vec) l1, (double val, Vector vec) l2) EigenVa

Matrix mat_asymm = new(m1, m3, m3, m2);

return ((l1, EigenVector(mat_asymm, l1, veps)),
(l2, EigenVector(mat_asymm, l2, veps)));
return ((l1, EigenVector(mat_asymm, l1)),
(l2, EigenVector(mat_asymm, l2)));
}

public static (double val, Vector vec)[] EigenValues(Matrix mat, double eps = 1e-8) {
Expand Down Expand Up @@ -221,10 +221,10 @@ public static (double val, Vector vec)[] EigenValues(Matrix mat, double eps = 1e
.Distinct()
).ToArray();

return ls.Select((l) => (l, EigenVector(mat, l, veps))).ToArray();
return ls.Select((l) => (l, EigenVector(mat, l))).ToArray();
}

private static Vector EigenVector(Matrix mat, double l, double eps) {
private static Vector EigenVector(Matrix mat, double l) {

static Vector normalize(Vector v) {
(double x, double y) = v;
Expand Down
10 changes: 5 additions & 5 deletions ShapeFitting/Algebra/AlgebraD3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ static Vector normalize(Vector v) {
m11 -= l; m22 -= l; m33 -= l;

double rx, ry, rz;
double[][] e = { new double[]{ m11, m12, m13 },
new double[]{ m21, m22, m23 },
new double[]{ m31, m32, m33 } };
double[][] e = [ [m11, m12, m13],
[m21, m22, m23],
[m31, m32, m33] ];

(int i0, int i1, int i2) = Order.AbsArgSort(e[0][0], e[1][0], e[2][0]);
e = new double[][] { e[i0], e[i1], e[i2] };
e = [e[i0], e[i1], e[i2]];

if (Math.Abs(e[2][0]) > eps) {
double r02 = e[0][0] / e[2][0], r12 = e[1][0] / e[2][0];
Expand All @@ -328,7 +328,7 @@ static Vector normalize(Vector v) {
}

if (Math.Abs(e[0][1]) > Math.Abs(e[1][1])) {
e = new double[][] { e[1], e[0], e[2] };
e = [e[1], e[0], e[2]];
}

if (Math.Abs(e[1][1]) > eps) {
Expand Down
16 changes: 8 additions & 8 deletions ShapeFitting/Geometry/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Circle(double cx, double cy, double r) {
this.Radius = r;
}

public bool IsValid => Center.IsValid && double.IsFinite(Radius) && Radius >= 0;
public readonly bool IsValid => Center.IsValid && double.IsFinite(Radius) && Radius >= 0;

public static Circle Invalid => new(Vector.Invalid, double.NaN);

Expand Down Expand Up @@ -52,11 +52,11 @@ public static Circle FromPoints(Vector a, Vector b, Vector c) {
return new Circle(center, radius);
}

public Vector Point(double theta) {
public readonly Vector Point(double theta) {
return Center + new Vector(Math.Cos(theta) * Radius, Math.Sin(theta) * Radius);
}

public Vector[] Points(IReadOnlyList<double> thetas) {
public readonly Vector[] Points(IReadOnlyList<double> thetas) {
Vector[] vs = new Vector[thetas.Count];

for (int i = 0; i < thetas.Count; i++) {
Expand All @@ -67,7 +67,7 @@ public Vector[] Points(IReadOnlyList<double> thetas) {
return vs;
}

public override bool Equals(object obj) {
public override readonly bool Equals(object obj) {
return obj is Circle circle && (circle == this);
}

Expand Down Expand Up @@ -99,9 +99,9 @@ public static explicit operator Ellipse(Circle circle) {
return new Ellipse(circle.Center, (circle.Radius, circle.Radius), 0);
}

public void Deconstruct(out double cx, out double cy, out double r) => (cx, cy, r) = (Center.X, Center.Y, Radius);
public readonly void Deconstruct(out double cx, out double cy, out double r) => (cx, cy, r) = (Center.X, Center.Y, Radius);

public void Deconstruct(out Vector c, out double r) => (c, r) = (Center, Radius);
public readonly void Deconstruct(out Vector c, out double r) => (c, r) = (Center, Radius);

public static double[] Distance(IReadOnlyList<Vector> vs, double a, double b, double c) {
double[] dists = new double[vs.Count];
Expand All @@ -118,11 +118,11 @@ public static double[] Distance(IReadOnlyList<Vector> vs, double a, double b, do
return dists;
}

public override int GetHashCode() {
public override readonly int GetHashCode() {
return Center.GetHashCode() ^ Radius.GetHashCode();
}

public override string ToString() {
public override readonly string ToString() {
if (!IsValid) {
return nameof(Invalid);
}
Expand Down
14 changes: 7 additions & 7 deletions ShapeFitting/Geometry/Ellipse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Ellipse(Vector center, (double major, double minor) axis, double angle) {
this.Angle = angle;
}

public bool IsValid => Center.IsValid
public readonly bool IsValid => Center.IsValid
&& double.IsFinite(Axis.major) && double.IsFinite(Axis.minor)
&& double.IsFinite(Angle);

Expand Down Expand Up @@ -51,14 +51,14 @@ public static Ellipse FromImplicit(double a, double b, double c, double d, doubl
return new Ellipse(new Vector(cx, cy), (major_axis, minor_axis), angle);
}

public Vector Point(double theta) {
public readonly Vector Point(double theta) {
double cs = Math.Cos(Angle), sn = Math.Sin(Angle);
double a = Math.Cos(theta) * Axis.major, b = Math.Sin(theta) * Axis.minor;

return Center + new Vector(cs * a - sn * b, sn * a + cs * b);
}

public Vector[] Points(IReadOnlyList<double> thetas) {
public readonly Vector[] Points(IReadOnlyList<double> thetas) {
Vector[] vs = new Vector[thetas.Count];

double cs = Math.Cos(Angle), sn = Math.Sin(Angle);
Expand All @@ -74,7 +74,7 @@ public Vector[] Points(IReadOnlyList<double> thetas) {
return vs;
}

public override bool Equals(object obj) {
public override readonly bool Equals(object obj) {
return obj is Ellipse ellipse && (ellipse == this);
}

Expand Down Expand Up @@ -102,10 +102,10 @@ public static implicit operator (Vector center, (double major, double minor) axi
return (ellipse.Center, ellipse.Axis, ellipse.Angle);
}

public void Deconstruct(out double cx, out double cy, out double rx, out double ry, out double angle)
public readonly void Deconstruct(out double cx, out double cy, out double rx, out double ry, out double angle)
=> (cx, cy, rx, ry, angle) = (Center.X, Center.Y, Axis.major, Axis.minor, Angle);

public void Deconstruct(out Vector center, out (double major, double minor) axis, out double angle)
public readonly void Deconstruct(out Vector center, out (double major, double minor) axis, out double angle)
=> (center, axis, angle) = (Center, Axis, Angle);

public static double[] Distance(IReadOnlyList<Vector> vs, double a, double b, double c, double d, double e, double f) {
Expand All @@ -123,7 +123,7 @@ public static double[] Distance(IReadOnlyList<Vector> vs, double a, double b, do
return dists;
}

public override int GetHashCode() {
public override readonly int GetHashCode() {
return Center.GetHashCode() ^ Axis.GetHashCode() ^ Angle.GetHashCode();
}

Expand Down
24 changes: 12 additions & 12 deletions ShapeFitting/Geometry/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public struct Line {
public double B { set; get; }
public double C { set; get; }

public double Theta => Math.Atan2(A, B);
public double Phi => C;
public readonly double Theta => Math.Atan2(A, B);
public readonly double Phi => C;

public Line(double a, double b, double c) {
this.A = a;
Expand All @@ -28,15 +28,15 @@ public Line(double theta, double phi) {
this.C = phi;
}

public bool IsValid => double.IsFinite(A) && double.IsFinite(B) && double.IsFinite(C);
public readonly bool IsValid => double.IsFinite(A) && double.IsFinite(B) && double.IsFinite(C);

public static Line Invalid => new(double.NaN, double.NaN, double.NaN);

/// <summary>y = f(x)</summary>
public double Fx(double x) => -(A * x + C) / B;
public readonly double Fx(double x) => -(A * x + C) / B;

/// <summary>y = f(x)</summary>
public double[] Fx(double[] xs) {
public readonly double[] Fx(double[] xs) {
double[] ys = new double[xs.Length];
for (int i = 0; i < xs.Length; i++) {
ys[i] = -(A * xs[i] + C) / B;
Expand All @@ -46,10 +46,10 @@ public double[] Fx(double[] xs) {
}

/// <summary>x = f(y)</summary>
public double Fy(double y) => -(B * y + C) / A;
public readonly double Fy(double y) => -(B * y + C) / A;

/// <summary>x = f(y)</summary>
public double[] Fy(double[] ys) {
public readonly double[] Fy(double[] ys) {
double[] xs = new double[ys.Length];
for (int i = 0; i < ys.Length; i++) {
xs[i] = -(B * ys[i] + C) / A;
Expand Down Expand Up @@ -81,7 +81,7 @@ public static Line FromPoints(Vector a, Vector b) {
}
}

public override bool Equals(object obj) {
public override readonly bool Equals(object obj) {
return obj is Line line && (line == this);
}

Expand Down Expand Up @@ -109,9 +109,9 @@ public static implicit operator (double theta, double phi)(Line line) {
return (line.Theta, line.Phi);
}

public void Deconstruct(out double a, out double b, out double c) => (a, b, c) = (A, B, C);
public readonly void Deconstruct(out double a, out double b, out double c) => (a, b, c) = (A, B, C);

public void Deconstruct(out double theta, out double phi) => (theta, phi) = (Theta, Phi);
public readonly void Deconstruct(out double theta, out double phi) => (theta, phi) = (Theta, Phi);

public static Line[] Concat(IReadOnlyList<double> a_list, IReadOnlyList<double> b_list, IReadOnlyList<double> c_list) {
if (a_list.Count != b_list.Count || a_list.Count != c_list.Count) {
Expand Down Expand Up @@ -159,11 +159,11 @@ public static double[] Distance(IReadOnlyList<Vector> vs, double a, double b, do
return dists;
}

public override int GetHashCode() {
public override readonly int GetHashCode() {
return A.GetHashCode() ^ B.GetHashCode() ^ C.GetHashCode();
}

public override string ToString() {
public override readonly string ToString() {
if (!IsValid) {
return nameof(Invalid);
}
Expand Down
10 changes: 5 additions & 5 deletions ShapeFitting/Geometry/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Vector(double x, double y) {
this.Y = y;
}

public bool IsValid => double.IsFinite(X) && double.IsFinite(Y);
public readonly bool IsValid => double.IsFinite(X) && double.IsFinite(Y);

public static Vector Invalid => new(double.NaN, double.NaN);

Expand All @@ -37,10 +37,10 @@ public Vector(double x, double y) {
return v * (1d / r);
}

public double SquareNorm => X * X + Y * Y;
public readonly double SquareNorm => X * X + Y * Y;
public double Norm => Math.Sqrt(SquareNorm);

public override bool Equals(object obj) {
public override readonly bool Equals(object obj) {
return obj is Vector vector && (vector == this);
}

Expand All @@ -56,7 +56,7 @@ public static implicit operator Vector((double x, double y) v) {
return new Vector(v.x, v.y);
}

public void Deconstruct(out double x, out double y) => (x, y) = (X, Y);
public readonly void Deconstruct(out double x, out double y) => (x, y) = (X, Y);

public static Vector[] Concat(IReadOnlyList<double> xs, IReadOnlyList<double> ys) {
if (xs.Count != ys.Count) {
Expand All @@ -74,7 +74,7 @@ public static Vector[] Concat(IReadOnlyList<double> xs, IReadOnlyList<double> ys
return vs;
}

public override int GetHashCode() {
public override readonly int GetHashCode() {
return X.GetHashCode() ^ Y.GetHashCode();
}

Expand Down
4 changes: 2 additions & 2 deletions ShapeFitting/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShapeFitting")]
[assembly: AssemblyCopyright("Copyright © T.Yoshimura 2021-2022")]
[assembly: AssemblyCopyright("Copyright © T.Yoshimura 2021-2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: ComVisible(false)]

[assembly: Guid("72817856-824A-41A6-9962-FC8D0F514546")]

[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyVersion("1.2.0")]

[assembly: InternalsVisibleTo("ShapeFittingTest")]
6 changes: 3 additions & 3 deletions ShapeFitting/ShapeFitting.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Deterministic>false</Deterministic>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
<DocumentationFile>bin\Debug\net6.0\ShapeFitting.xml</DocumentationFile>
<DocumentationFile>bin\Debug\net8.0\ShapeFitting.xml</DocumentationFile>
<Optimize>False</Optimize>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DocumentationFile>bin\Release\net6.0\ShapeFitting.xml</DocumentationFile>
<DocumentationFile>bin\Release\net8.0\ShapeFitting.xml</DocumentationFile>
</PropertyGroup>

</Project>
12 changes: 4 additions & 8 deletions ShapeFitting/Utils/ExceptionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ private enum Lang { Default, JP }

static ExceptionMessage() {
string culture_name = CultureInfo.CurrentCulture.Name;
switch (culture_name) {
case "ja-JP":
lang = Lang.JP;
break;
default:
lang = Lang.Default;
break;
}
lang = culture_name switch {
"ja-JP" => Lang.JP,
_ => Lang.Default,
};
}

public static string MismatchLength =>
Expand Down
15 changes: 9 additions & 6 deletions ShapeFittingBenchmark/ShapeFittingBenchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Reference Include="ShapeFitting">
<HintPath>..\ShapeFitting\bin\Release\net6.0\ShapeFitting.dll</HintPath>
<HintPath>..\ShapeFitting\bin\Release\net8.0\ShapeFitting.dll</HintPath>
</Reference>
</ItemGroup>

Expand Down
Loading

0 comments on commit fec1e0e

Please sign in to comment.