Boost logo

Geometry :

Subject: [geometry] union gives an empty multi-polygon
From: Romain Texier (romain.texier_at_[hidden])
Date: 2012-12-27 09:11:56


Hi,

I want to make real time union and clipping of many polygons.
I have tried the clipper library and I would like to try the boost geometry
library.

But I have a problem: The union of two triangles is an empty multi-polygon.
Could you help me ?

typedef boost::geometry::model::d2::point_xy<float> BoostPoint;
typedef boost::geometry::model::polygon<BoostPoint,false> BoostPolygon;
//false because my triangles are counter-clockwise.
typedef boost::geometry::model::multi_polygon< BoostPolygon > BoostPolygons;

void BoostShape::createNewPoly(Triangle2D const & NewTriangle,
BoostPolygons& p_InOutPolygon)
{
model::ring<BoostPoint,false> outerRingTriangle;
outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex0.X,NewTriangle.m_Vertex0.Y));
outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex1.X,NewTriangle.m_Vertex1.Y));
outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex2.X,NewTriangle.m_Vertex2.Y));

BoostPolygon triangleForBoost;
triangleForBoost.outer() = outerRingTriangle;

p_InOutPolygon.clear();
p_InOutPolygon.push_back(triangleForBoost); //that works: polygons of size
1, with a polygon of 3 vertex
}
void BoostShape::AddTriangle (Triangle2D const & NewTriangle,
BoostPolygons& p_InOutPolygon)
{
model::ring<BoostPoint,false> outerRingTriangle;
outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex0.X,NewTriangle.m_Vertex0.Y));
outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex1.X,NewTriangle.m_Vertex1.Y));
outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex2.X,NewTriangle.m_Vertex2.Y));

BoostPolygon triangleForBoost;
triangleForBoost.outer() = outerRingTriangle;

BoostPolygons Result;
boost::geometry::union_(p_InOutPolygon, triangleForBoost, Result); //
Doesn't work. Result is empty
p_InOutPolygon = Result;
}

Regards,
Romain



Geometry list run by mateusz at loskot.net