Skip to content

lycantropos/Gon.cs

Repository files navigation

Gon.cs

Installation

Install the latest .NET SDK.

User

Download and install the latest stable version from NuGet repository

dotnet add package Gon

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/Gon.cs

Install

dotnet add reference Gon.cs/src/Gon/Gon.csproj

Usage

using System.Diagnostics;

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

namespace GonExamples
{
    public static class Basic
    {
        public static void RunExamples()
        {
            // construction
            var squareBorder = new Contour(
                new[] { new Point(0, 0), new Point(4, 0), new Point(4, 4), new Point(0, 4) }
            );
            var square = new Polygon(squareBorder);

            // accessing various properties
            Debug.Assert(square.Border == squareBorder);
            Debug.Assert(square.Border.Vertices.Length == 4);
            Debug.Assert(square.Holes.Length == 0);

            // equality checks
            Debug.Assert(square == new Polygon(squareBorder));

            // point-in-polygon checks
            Debug.Assert(square.Contains(new Point(2, 2)));
            Debug.Assert(square.Contains(new Point(4, 4)));
            Debug.Assert(!square.Contains(new Point(6, 6)));

            // point location queries
            Debug.Assert(square.Locate(new Point(2, 2)) == Location.Interior);
            Debug.Assert(square.Locate(new Point(4, 4)) == Location.Boundary);
            Debug.Assert(square.Locate(new Point(6, 6)) == Location.Exterior);

            // set intersection
            Polygon[] intersection = square & square;
            Debug.Assert(intersection.Length == 1);
            Debug.Assert(intersection[0] == square);

            // set union
            Polygon[] union = square | square;
            Debug.Assert(union.Length == 1);
            Debug.Assert(union[0] == square);

            // set difference
            Polygon[] difference = square - square;
            Debug.Assert(difference.Length == 0);

            // set symmetric difference
            Polygon[] symmetricDifference = square ^ square;
            Debug.Assert(symmetricDifference.Length == 0);
        }
    }
}

More examples can be found at src/GonExamples directory.

Development

Bumping version

Preparation

Install bump2version.

Pre-release

Choose which version number category to bump following semver specification.

Test bumping version

bump2version --dry-run --verbose $CATEGORY

where $CATEGORY is the target version number category name, possible values are patch/minor/major.

Bump version

bump2version --verbose $CATEGORY

This will set version to major.minor.patch-alpha.

Release

Test bumping version

bump2version --dry-run --verbose release

Bump version

bump2version --verbose release

This will set version to major.minor.patch.

Running tests

In what follows python is an alias for python3.8 or any later version (python3.9 and so on).

Install dependencies

python -m pip install -r requirements-tests.txt

Run tests

pytest