Geri-Borbas/Unity.Library.eppz.Geometry

Polygon subtraction

Opened this issue ยท 5 comments

Great stuff you got here! Just one question, you mention in the description that you can perform subtraction. Is it possible to subtract one polygon from another as shown in the picture below? So far i have only managed to do an XOR.
image

Thanks!

Awesome, thanks for the quick reply!

All i had to do was to change this:
clipper.Execute(ClipType.ctUnion, unionPaths);

Into:
clipper.Execute(ClipType.ctDifference, unionPaths);

So if you wanted a general function for doing all these kinds of operations you could change the function public Polygon UnionPolygon() into public Polygon BooleanOperation(ClipType clipType)

Super simple, thanks again!

Boolean operations are done using Clipper, a great open source freeware library for clipping and offsetting lines and polygons.

So far I only incorporated union, but you can easily extend the library to make extension methods doing different types of clipping operations. See ClipType for the actual Clipper documentation.

In this library, only ClipType.ctUnion is implemented so far. See Polygon.cs#L626.

You can nicely arrange the extensions into an extension class like below.

using System;
using UnityEngine;


namespace EPPZ.Geometry
{


	public static class Polygon_Extensions
	{

                public Polygon IntersectionPolygon(this Polygon _this)
		{ ... }

                public Polygon DifferencePolygon(this Polygon _this)
		{ ... }

                public Polygon XORPolygon(this Polygon _this)
		{ ... }
	}
}

i can't open example scene in unity 2018.3.6.
is there any thing to do before importing?