0

We're using the library NetTopologySuite to work with geometries/(multi)polygons (in C#).

At some point, we need both the 'union' AND 'intersection' of two geometries (functionally we want the union of the two geometries and determine the duplicate parts of that union).

I know I can get a union using CascadedPolygonUnion.Union(new List<Geometry> { geometry1, geometry2 })) and the intersection using geometry1.Intersection(geometry2).

But since the 'intersection' of the two polygons is basically the 'duplicated' part for a union, isn't there a routine that will determine the intersection AND the union in one function call?

Ex.

var result = GetUnionAndIntersection(geometry1, geometry2)
result.Union;
result.Intersection;

The main reason for the question is the assumption that there might be such a routine because it would perform faster than the two individual routines as the routine share some common knowledge about the duplicate area(s)...

R. Hoek
  • 916
  • 8
  • 27
  • What is the problem with calling 2 methods. The goal of their library was to not hide functionally within a single method but it was to let you choose what you want. And what prevent your from creating a method that does both calculation and return both result ? – Franck Apr 06 '21 at 13:15
  • @Franck because the two operations seem to have some 'overlapping knowledge' regarding the 'duplicate' area, I would expect performance benefit when determining both 'results' in a single operation and therefor suspect there might be such a routine... – R. Hoek Apr 06 '21 at 13:20
  • 2
    Typically Boolean geometries operations do not work the same way. Performance anyhow should not be an issue. Micro optimization is have a heavy diminish return. You are better off optimizing other part of your code first or if it's not performant enough find another library that does it faster. I do tens of thousands of Boolean union/difference/intersect per seconds in a custom 2D/3D CAD engine. – Franck Apr 06 '21 at 14:28
  • @Franck OK, thanks for the insight - for now, I'll leave this question open so others can still give a suggestion (if any). But if you create an answer based on your comment I'll accept it... For now +1 for the comment ;) – R. Hoek Apr 06 '21 at 14:31

0 Answers0