Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Issue 200 fix intersection #220

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CGAL_patches/CGAL/corefinement_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,15 @@ class Polyhedron_corefinement

if (!intersection.empty())
{
Volume_import_modifier modifier(final_map,intersection.begin(),intersection.end());
Output_polyhedron* new_poly=new Output_polyhedron();
new_poly->delegate(modifier);
*poly_output++=std::make_pair( new_poly,static_cast<int>(Intersection_tag) );
for (const auto& dart : intersection)
{
Volume_import_modifier modifier(final_map, dart);
Output_polyhedron *new_poly = new Output_polyhedron();
new_poly->delegate(modifier);
*poly_output++ = std::make_pair( new_poly
, static_cast<int>(Intersection_tag)
);
}
}

if (!P_minus_Q.empty())
Expand Down
9 changes: 6 additions & 3 deletions src/algorithm/Intersection3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,12 @@ void _intersection_solid_solid( const MarkedPolyhedron& pa, const MarkedPolyhedr
}

// else, we have an intersection
MarkedPolyhedron* res_poly = result[0].first;
output.addPrimitive( *res_poly );
delete res_poly;
for (std::pair< MarkedPolyhedron*, int >& p : result )
{
std::unique_ptr< MarkedPolyhedron > res_poly( p.first );
output.addPrimitive( *res_poly );
p.first = nullptr;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/bench/BenchWKT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE( testReadTriangle )
bench().start( boost::format( "READ WKT TRIANGLE" ) ) ;

for ( int i = 0; i < N; i++ ) {
io::readWkt( "TRIANGLE((0 0,0 1000,1000 1000,1000 0,0 0))" ) ;
io::readWkt( "TRIANGLE((0 0,0 1000,1000 1000,0 0))" ) ;
}

bench().stop();
Expand Down
44 changes: 43 additions & 1 deletion test/regress/standalone/SFCGAL/IntersectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <SFCGAL/io/wkt.h>
#include <SFCGAL/algorithm/intersection.h>
#include <SFCGAL/Geometry.h>
#include <SFCGAL/algorithm/extrude.h>
#include <SFCGAL/algorithm/isValid.h>
#include <SFCGAL/MultiSolid.h>

#include "../../../test_config.h"

Expand Down Expand Up @@ -57,8 +60,47 @@ BOOST_AUTO_TEST_CASE( test_postgis_4157 )
algorithm::intersection3D( *g1, *g2 );
}

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE( test_sfcgal_issue_200 )
{
std::unique_ptr< SFCGAL::Geometry > poly1 = SFCGAL::io::readWkt( "POLYGON(( 0 0"
", 1 0"
", 1 1"
", 0 1"
", 0 0"
"))"
);

std::unique_ptr< SFCGAL::Geometry > solid1 = SFCGAL::algorithm::extrude( *poly1
, 0.0
, 0.0
, 1.0
);

std::unique_ptr< SFCGAL::Geometry > poly2 = SFCGAL::io::readWkt( "POLYGON(( -1 0.2"
", 1.8 0.2"
", 1.8 0.4"
", -0.8 0.4"
", -0.8 0.6"
", 1.8 0.6"
", 1.8 0.8"
", -1 0.8"
", -1 0.2"
"))"
);

std::unique_ptr< SFCGAL::Geometry > solid2 = SFCGAL::algorithm::extrude( *poly2
, 0.0
, 0.0
, 1.0
);

std::unique_ptr< SFCGAL::Geometry > inx = SFCGAL::algorithm::intersection3D( *solid1
, *solid2
);

BOOST_CHECK( algorithm::isValid( *inx ) );
BOOST_CHECK_EQUAL( inx->geometryTypeId(), TYPE_MULTISOLID );
BOOST_CHECK_EQUAL( inx->as<MultiSolid>().numGeometries(), 2 );
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 2 additions & 0 deletions test/unit/SFCGAL/algorithm/IntersectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <SFCGAL/MultiPolygon.h>
#include <SFCGAL/MultiSolid.h>
#include <SFCGAL/detail/transform/AffineTransform3.h>
#include <SFCGAL/algorithm/extrude.h>
#include <SFCGAL/algorithm/isValid.h>

#include "../../../test_config.h"

Expand Down