Skip to content

Commit

Permalink
Complete examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lycantropos committed Jul 19, 2023
1 parent 35732ce commit fbf6b13
Showing 1 changed file with 230 additions and 0 deletions.
230 changes: 230 additions & 0 deletions src/GonExamples/PolygonsWithHolesBinaryOperations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
using System.Diagnostics;

using Point = Gon.Point<double>;
using Contour = Gon.Contour<double>;
using Polygon = Gon.Polygon<double>;

namespace GonExamples
{
public static class PolygonsWithHolesBinaryOperations
{
public static Polygon FirstOperand = new Polygon(
new Contour(
new[] { new Point(1, 1), new Point(5, 1), new Point(5, 5), new Point(1, 5) }
),
new[]
{
new Contour(
new[] { new Point(2, 2), new Point(2, 4), new Point(4, 4), new Point(4, 2) }
)
}
);
public static Polygon SecondOperand = new Polygon(
new Contour(
new[] { new Point(0, 3), new Point(3, 0), new Point(6, 3), new Point(3, 6) }
),
new[]
{
new Contour(
new[] { new Point(2, 3), new Point(3, 4), new Point(4, 3), new Point(3, 2) }
)
}
);

public static void RunExamples()
{
RunDifferenceExample();
RunIntersectionExample();
RunSymmetricDifferenceExample();
RunUnionExample();
}

private static void RunDifferenceExample()
{
var difference = FirstOperand - SecondOperand;
Debug.Assert(difference.Length == 4);
Debug.Assert(
difference[0]
== new Polygon(
new Contour(new[] { new Point(1, 1), new Point(2, 1), new Point(1, 2) })
)
);
Debug.Assert(
difference[1]
== new Polygon(
new Contour(new[] { new Point(1, 4), new Point(2, 5), new Point(1, 5) })
)
);
Debug.Assert(
difference[2]
== new Polygon(
new Contour(new[] { new Point(4, 1), new Point(5, 1), new Point(5, 2) })
)
);
Debug.Assert(
difference[3]
== new Polygon(
new Contour(new[] { new Point(4, 5), new Point(5, 4), new Point(5, 5) })
)
);
}

private static void RunIntersectionExample()
{
var intersection = FirstOperand & SecondOperand;
Debug.Assert(intersection.Length == 1);
Debug.Assert(
intersection[0]
== new Polygon(
new Contour(
new[]
{
new Point(1, 2),
new Point(2, 1),
new Point(4, 1),
new Point(5, 2),
new Point(5, 4),
new Point(4, 5),
new Point(2, 5),
new Point(1, 4)
}
),
new[]
{
new Contour(
new[]
{
new Point(2, 2),
new Point(2, 4),
new Point(4, 4),
new Point(4, 2)
}
)
}
)
);
}

private static void RunSymmetricDifferenceExample()
{
var symmetricDifference = FirstOperand ^ SecondOperand;
Debug.Assert(symmetricDifference.Length == 12);
Debug.Assert(
symmetricDifference[0]
== new Polygon(
new Contour(new[] { new Point(0, 3), new Point(1, 2), new Point(1, 4) })
)
);
Debug.Assert(
symmetricDifference[1]
== new Polygon(
new Contour(new[] { new Point(1, 1), new Point(2, 1), new Point(1, 2) })
)
);
Debug.Assert(
symmetricDifference[2]
== new Polygon(
new Contour(new[] { new Point(1, 4), new Point(2, 5), new Point(1, 5) })
)
);
Debug.Assert(
symmetricDifference[3]
== new Polygon(
new Contour(new[] { new Point(2, 1), new Point(3, 0), new Point(4, 1) })
)
);
Debug.Assert(
symmetricDifference[4]
== new Polygon(
new Contour(new[] { new Point(2, 2), new Point(3, 2), new Point(2, 3) })
)
);
Debug.Assert(
symmetricDifference[5]
== new Polygon(
new Contour(new[] { new Point(2, 3), new Point(3, 4), new Point(2, 4) })
)
);
Debug.Assert(
symmetricDifference[6]
== new Polygon(
new Contour(new[] { new Point(2, 5), new Point(4, 5), new Point(3, 6) })
)
);
Debug.Assert(
symmetricDifference[7]
== new Polygon(
new Contour(new[] { new Point(3, 2), new Point(4, 2), new Point(4, 3) })
)
);
Debug.Assert(
symmetricDifference[8]
== new Polygon(
new Contour(new[] { new Point(3, 4), new Point(4, 3), new Point(4, 4) })
)
);
Debug.Assert(
symmetricDifference[9]
== new Polygon(
new Contour(new[] { new Point(4, 1), new Point(5, 1), new Point(5, 2) })
)
);
Debug.Assert(
symmetricDifference[10]
== new Polygon(
new Contour(new[] { new Point(4, 5), new Point(5, 4), new Point(5, 5) })
)
);
Debug.Assert(
symmetricDifference[11]
== new Polygon(
new Contour(new[] { new Point(5, 2), new Point(6, 3), new Point(5, 4) })
)
);
}

private static void RunUnionExample()
{
var union = FirstOperand | SecondOperand;
Debug.Assert(union.Length == 1);
Debug.Assert(
union[0]
== new Polygon(
new Contour(
new[]
{
new Point(0, 3),
new Point(1, 2),
new Point(1, 1),
new Point(2, 1),
new Point(3, 0),
new Point(4, 1),
new Point(5, 1),
new Point(5, 2),
new Point(6, 3),
new Point(5, 4),
new Point(5, 5),
new Point(4, 5),
new Point(3, 6),
new Point(2, 5),
new Point(1, 5),
new Point(1, 4)
}
),
new[]
{
new Contour(
new[]
{
new Point(2, 3),
new Point(3, 4),
new Point(4, 3),
new Point(3, 2)
}
)
}
)
);
}
}
}

0 comments on commit fbf6b13

Please sign in to comment.