diff --git a/Distribution/xDGA Sample.xlsx b/Distribution/xDGA Sample.xlsx index b89b022..b750554 100644 Binary files a/Distribution/xDGA Sample.xlsx and b/Distribution/xDGA Sample.xlsx differ diff --git a/Distribution/xDGA.ADDIN.xll b/Distribution/xDGA.ADDIN.xll index 6d03d39..e42033c 100644 Binary files a/Distribution/xDGA.ADDIN.xll and b/Distribution/xDGA.ADDIN.xll differ diff --git a/Distribution/xDGA.ADDIN64.xll b/Distribution/xDGA.ADDIN64.xll index 892620a..3572c3f 100644 Binary files a/Distribution/xDGA.ADDIN64.xll and b/Distribution/xDGA.ADDIN64.xll differ diff --git a/Distribution/xDGA32.zip b/Distribution/xDGA32.zip new file mode 100644 index 0000000..5cea22e Binary files /dev/null and b/Distribution/xDGA32.zip differ diff --git a/Distribution/xDGA64.zip b/Distribution/xDGA64.zip new file mode 100644 index 0000000..d117ac2 Binary files /dev/null and b/Distribution/xDGA64.zip differ diff --git a/VERSIONS.md b/VERSIONS.md index 24515b4..582e3a2 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -1,5 +1,12 @@ # xDGA +## Version 0.6 +### October 2017 + +#### xDGA.CORE +* Corrected Duval Pentagons areas. Thanks to Nick and Ania from work who + pointed out the issue and suggested a solution. + ## Version 0.5 ### August 2017 diff --git a/xDGA.CORE/Algorithms/DuvalPentagons/AbstractDuvalPentagonRule.cs b/xDGA.CORE/Algorithms/DuvalPentagons/AbstractDuvalPentagonRule.cs index a018576..e339ec9 100644 --- a/xDGA.CORE/Algorithms/DuvalPentagons/AbstractDuvalPentagonRule.cs +++ b/xDGA.CORE/Algorithms/DuvalPentagons/AbstractDuvalPentagonRule.cs @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -using System; using System.Collections.Generic; using System.Linq; using xDGA.CORE.Interfaces; diff --git a/xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonOneRule.cs b/xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonOneRule.cs index d5950e2..d2d97ff 100644 --- a/xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonOneRule.cs +++ b/xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonOneRule.cs @@ -44,7 +44,7 @@ public DuvalPentagonOneRule() : base("Duval Pentagon 1", Gas.Hydrogen, Gas.Ethan Coordinates = { new CartesianCoordinate(0.0, 40.0), - new CartesianCoordinate(38.0, 12.0), + new CartesianCoordinate(38.0, 12.4), new CartesianCoordinate(32.0, -6.0), new CartesianCoordinate(4.0, 16.0), new CartesianCoordinate(0.0, 1.5) @@ -67,9 +67,10 @@ public DuvalPentagonOneRule() : base("Duval Pentagon 1", Gas.Hydrogen, Gas.Ethan Coordinates = { new CartesianCoordinate(24.0, -30.0), - new CartesianCoordinate(1.0, -32.0), + new CartesianCoordinate(1.0, -32.4), + new CartesianCoordinate(-23.3, -32.4), new CartesianCoordinate(-6.0, -4.0), - new CartesianCoordinate(-1.0, -2.0) + new CartesianCoordinate(-1.0, -2.0) } }); @@ -77,8 +78,8 @@ public DuvalPentagonOneRule() : base("Duval Pentagon 1", Gas.Hydrogen, Gas.Ethan { Coordinates = { - new CartesianCoordinate(1.0, -32.0), - new CartesianCoordinate(-22.5, -32.0), + new CartesianCoordinate(1.0, -32.4), + new CartesianCoordinate(-22.5, -32.4), new CartesianCoordinate(-6.0, -4.0) } }); @@ -89,9 +90,10 @@ public DuvalPentagonOneRule() : base("Duval Pentagon 1", Gas.Hydrogen, Gas.Ethan { new CartesianCoordinate(0.0, 1.5), new CartesianCoordinate(-35.0, 3.0), - new CartesianCoordinate(-22.5, -32.0), + new CartesianCoordinate(-22.5, -32.4), new CartesianCoordinate(-6.0, -4.0), - new CartesianCoordinate(-1.0, -2.0) + new CartesianCoordinate(-1.0, -2.0), + new CartesianCoordinate(-23.3, -32.4) } }); @@ -105,7 +107,8 @@ public DuvalPentagonOneRule() : base("Duval Pentagon 1", Gas.Hydrogen, Gas.Ethan new CartesianCoordinate(-1.0, 24.5), new CartesianCoordinate(-1.0, 33.0), new CartesianCoordinate(0.0, 33.0), - new CartesianCoordinate(0.0, 40.0) + new CartesianCoordinate(0.0, 40.0), + new CartesianCoordinate(-38.0, -12.4) } }); } diff --git a/xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonTwoRule.cs b/xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonTwoRule.cs index d549d2b..13f9e39 100644 --- a/xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonTwoRule.cs +++ b/xDGA.CORE/Algorithms/DuvalPentagons/DuvalPentagonTwoRule.cs @@ -44,7 +44,7 @@ public DuvalPentagonTwoRule() : base("Duval Pentagon 2", Gas.Hydrogen, Gas.Ethan Coordinates = { new CartesianCoordinate(0.0, 40.0), - new CartesianCoordinate(38.0, 12.0), + new CartesianCoordinate(38.0, 12.4), new CartesianCoordinate(32.0, -6.0), new CartesianCoordinate(4.0, 16.0), new CartesianCoordinate(0.0, 1.5) @@ -72,7 +72,8 @@ public DuvalPentagonTwoRule() : base("Duval Pentagon 2", Gas.Hydrogen, Gas.Ethan new CartesianCoordinate(-1.0, 24.5), new CartesianCoordinate(-1.0, 33.0), new CartesianCoordinate(0.0, 33.0), - new CartesianCoordinate(0.0, 40.0) + new CartesianCoordinate(0.0, 40.0), + new CartesianCoordinate(-38.0, -12.4) } }); @@ -82,7 +83,9 @@ public DuvalPentagonTwoRule() : base("Duval Pentagon 2", Gas.Hydrogen, Gas.Ethan { new CartesianCoordinate(24.0, -30.0), new CartesianCoordinate(-3.5, -3.0), - new CartesianCoordinate(2.5, -32.0) + new CartesianCoordinate(-1.0, -2.0), + new CartesianCoordinate(2.5, -32.4), + new CartesianCoordinate(23.3, -32.4) } }); @@ -90,10 +93,10 @@ public DuvalPentagonTwoRule() : base("Duval Pentagon 2", Gas.Hydrogen, Gas.Ethan { Coordinates = { - new CartesianCoordinate(2.5, -32.0), + new CartesianCoordinate(2.5, -32.4), new CartesianCoordinate(-3.5, -3.0), new CartesianCoordinate(-11.0, -8.0), - new CartesianCoordinate(-21.5, -32.0) + new CartesianCoordinate(-21.5, -32.4) } }); @@ -101,12 +104,13 @@ public DuvalPentagonTwoRule() : base("Duval Pentagon 2", Gas.Hydrogen, Gas.Ethan { Coordinates = { - new CartesianCoordinate(-21.5, -32.0), + new CartesianCoordinate(-21.5, -32.4), new CartesianCoordinate(-11.0, -8.0), new CartesianCoordinate(-3.5, -3.0), new CartesianCoordinate(-1.0, -2.0), new CartesianCoordinate(0.0, 1.5), - new CartesianCoordinate(-35.0, 3.0) + new CartesianCoordinate(-35.0, 3.0), + new CartesianCoordinate(-23.3, -32.4) } }); } diff --git a/xDGA.CORE/Models/Area.cs b/xDGA.CORE/Models/Area.cs index 0306f47..aa35b8c 100644 --- a/xDGA.CORE/Models/Area.cs +++ b/xDGA.CORE/Models/Area.cs @@ -21,6 +21,7 @@ // SOFTWARE. using System; +using System.Linq; using System.Collections.Generic; namespace xDGA.CORE.Models @@ -110,25 +111,79 @@ public CartesianCoordinate GetCoordinate(double x, double y) return Coordinates.Find(c => { return c.X == x && c.Y == y; }); } + /// + /// Ensure coordinates are sorted in a counter-clockwise position + /// + private void SortCoordinates() + { + var angles = new Dictionary(); + + if (Coordinates.Count > 0) + { + foreach (var coordinate in Coordinates) + { + angles.Add(coordinate.ToVector().Angle,coordinate); + } + + angles.Values.ToList(); + + var list = angles.Keys.ToList(); + list.Sort(); + + Coordinates.Clear(); + + foreach (var angle in list) + { + Coordinates.Add(angles[angle]); + } + } + } + + /// + /// Determines whether a point is inside this polygonal area. + /// If the point is at an edge or a vertex it is considered to be + /// inside the area. It uses the algorithm documented by Paul Bourke. + /// + /// + /// The that will be checked. + /// public bool CheckIfCoordinateIsInArea(CartesianCoordinate coordinate) { var isInside = false; - var x = coordinate.X; - var y = coordinate.Y; + int counter = 0; + int i = 1; + int n = Coordinates.Count; + double xinters; + CartesianCoordinate p1, p2; - var polySides = Coordinates.Count; - var j = polySides - 1; + p1 = Coordinates[0]; - for (int i = 0; i < polySides; i++) + foreach (var point in Coordinates) { - if ((((Coordinates[i].Y < y && Coordinates[j].Y >= y) || (Coordinates[j].Y < y && Coordinates[i].Y >= y)) && (Coordinates[i].X <= x || Coordinates[j].X <= x))) + p2 = Coordinates[i % n]; + + if (coordinate.Y > Math.Min(p1.Y,p2.Y)) { - isInside = isInside ^ ((Coordinates[i].X + (y - Coordinates[i].Y) / (Coordinates[j].Y - Coordinates[i].Y) * (Coordinates[j].X - Coordinates[i].X)) < x); + if(coordinate.Y <= Math.Max(p1.Y,p2.Y)) + { + if(coordinate.X <= Math.Max(p1.X,p2.X)) + { + if(p1.Y != p2.Y) + { + xinters = (coordinate.Y - p1.Y) * (p2.X - p1.X) / (p2.Y - p1.Y) + p1.X; + if (p1.X == p2.X || coordinate.X <= xinters) counter++; + } + } + } } - j = i; + p1 = p2; + + i++; } + if (counter % 2 != 0) isInside = true; + return isInside; } } diff --git a/xDGA.CORE/xDGA.CORE.csproj b/xDGA.CORE/xDGA.CORE.csproj index c27c024..0809f3c 100644 --- a/xDGA.CORE/xDGA.CORE.csproj +++ b/xDGA.CORE/xDGA.CORE.csproj @@ -20,6 +20,7 @@ DEBUG;TRACE prompt 4 + bin\Debug\xDGA.CORE.xml pdbonly