Skip to content

Commit

Permalink
Merge pull request #37 from MagmaWorks/task/perimeter-closed-polygon
Browse files Browse the repository at this point in the history
Perimeter always closed polygon(s)
  • Loading branch information
kpne authored Oct 23, 2024
2 parents 99bf98a + a72f89a commit f8d4d01
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Countries/CountryTests/CountryTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.30">
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
14 changes: 10 additions & 4 deletions Loads/LoadTests/LoadTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Materials/MaterialTests/MaterialTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="OasysUnits.Serialization.JsonNet" Version="1.1.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.30">
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MagmaWorks.Geometry" Version="0.0.5" />
<PackageReference Include="MagmaWorks.Geometry" Version="0.0.7" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
39 changes: 37 additions & 2 deletions Profiles/Perimeter/Perimeter.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using MagmaWorks.Geometry;
using OasysUnits;

namespace MagmaWorks.Taxonomy.Profiles
{
public class Perimeter : IPerimeter
{
public ILocalPolygon2d OuterEdge { get; set; }
public IList<ILocalPolygon2d> VoidEdges { get; set; }
public ILocalPolygon2d OuterEdge
{
get { return _outerEdge; }
set
{
_outerEdge = EnsureClosedPolygon(value);
}
}

public IList<ILocalPolygon2d> VoidEdges
{
get { return _voidEdges; }
set
{
if (value != null)
{
_voidEdges = value.Select(edge => EnsureClosedPolygon(edge)).ToList();
}
}
}

private ILocalPolygon2d _outerEdge;
private IList<ILocalPolygon2d> _voidEdges;

private Perimeter() { }

Expand Down Expand Up @@ -50,5 +73,17 @@ public static (IPerimeter, IPerimeter) CreatePerimeters<T>(T profile)
{
return PerimeterFactory.PerimeterFactory.CreateBackToBackPerimeters(profile);
}

private static ILocalPolygon2d EnsureClosedPolygon(ILocalPolygon2d polygon)
{
if (polygon.IsClosed)
{
return polygon;
}

var closed = new LocalPolygon2d(polygon.Points);
closed.Points.Add(closed.Points[0]);
return closed;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ internal static List<ILocalPoint2d> CreateCirclePoints(Length diameter, int divi
for (int i = divisions + 1; i-- > 0;)
{
pts.Add(new LocalPoint2d(
factorU * radius * Math.Cos(radian * i),
factorV * radius * Math.Sin(radian * i))
factorU * radius * Math.Round(Math.Cos(radian * i), 15),
factorV * radius * Math.Round(Math.Sin(radian * i), 15))
);
}

Expand Down
16 changes: 8 additions & 8 deletions Profiles/ProfileTests/PerimeterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void CreateProfileTest()

// Assert
Assert.Single(profile.VoidEdges);
Assert.Equal(4, profile.OuterEdge.Points.Count);
Assert.Equal(4, profile.VoidEdges[0].Points.Count);
Assert.Equal(5, profile.OuterEdge.Points.Count);
Assert.Equal(5, profile.VoidEdges[0].Points.Count);
}

[Fact]
Expand Down Expand Up @@ -64,8 +64,8 @@ public void InterfaceSurvivesRoundtripDeserializationTest()

// Assert
Assert.Single(prflDeserialized.VoidEdges);
Assert.Equal(4, prflDeserialized.OuterEdge.Points.Count);
Assert.Equal(4, prflDeserialized.VoidEdges[0].Points.Count);
Assert.Equal(5, prflDeserialized.OuterEdge.Points.Count);
Assert.Equal(5, prflDeserialized.VoidEdges[0].Points.Count);
Assert.Equivalent(prfl, prflDeserialized);
}

Expand Down Expand Up @@ -96,8 +96,8 @@ public void ConcreteImplementationSurvivesRoundtripDeserializationTest()

// Assert
Assert.Single(prflDeserialized.VoidEdges);
Assert.Equal(4, prflDeserialized.OuterEdge.Points.Count);
Assert.Equal(4, prflDeserialized.VoidEdges[0].Points.Count);
Assert.Equal(5, prflDeserialized.OuterEdge.Points.Count);
Assert.Equal(5, prflDeserialized.VoidEdges[0].Points.Count);
Assert.Equivalent(prfl, prflDeserialized);
}

Expand Down Expand Up @@ -127,8 +127,8 @@ public void GetPerimeterTest()

// Assert
Assert.Single(perimeter.VoidEdges);
Assert.Equal(4, perimeter.OuterEdge.Points.Count);
Assert.Equal(4, perimeter.VoidEdges[0].Points.Count);
Assert.Equal(5, perimeter.OuterEdge.Points.Count);
Assert.Equal(5, perimeter.VoidEdges[0].Points.Count);
Assert.Equivalent(prfl, perimeter);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Profiles/ProfileTests/ProfileTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="OasysUnits.Serialization.JsonNet" Version="1.1.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.30">
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Profiles/ProfileTests/Utility/TestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal static void TestLengthsAreEqual(Length expected, Length actual)
Assert.Equal(expected.Unit, actual.Unit);
}

internal static void TestListsOfDoublesAreEqual(List<double> expected, List<double> actual, int precision = 12)
internal static void TestListsOfDoublesAreEqual(List<double> expected, List<double> actual, int precision = 10)
{
Assert.Equal(expected.Count, actual.Count);
for (int i = 0; i < expected.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion Sections/ISections/MagmaWorks.Taxonomy.ISections.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MagmaWorks.IGeometry" Version="0.0.5" />
<PackageReference Include="MagmaWorks.IGeometry" Version="0.0.7" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 3 additions & 3 deletions Sections/SectionTests/SectionTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MagmaWorks.Geometry" Version="0.0.5" />
<PackageReference Include="MagmaWorks.Geometry" Version="0.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.30">
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Sections/Sections/MagmaWorks.Taxonomy.Sections.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MagmaWorks.IGeometry" Version="0.0.5" />
<PackageReference Include="MagmaWorks.IGeometry" Version="0.0.7" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions Stages/StageTests/StageTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.30">
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions Standards/StandardTests/StandardTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="OasysUnits.Serialization.JsonNet" Version="1.1.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.30">
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit f8d4d01

Please sign in to comment.