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

Commit b632e6c

Browse files
authored
Merge pull request #157 from sloriot/CGAL_gmpxx_compatibility
Compatibility with gmpxx
2 parents 5499795 + e2d656b commit b632e6c

19 files changed

Lines changed: 228 additions & 163 deletions

File tree

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
language: cpp
1+
language: cpp
2+
dist: trusty
3+
sudo: required
24

35
# os:
46
# - linux
@@ -9,14 +11,14 @@ compiler:
911
- clang
1012

1113
env:
12-
- CGAL_VERSION=4.3
13-
- CGAL_VERSION=4.7
14+
- CGAL_VERSION=4.10.2
15+
- CGAL_VERSION=4.11.1
1416

1517
before_install:
1618
- ./travis/${TRAVIS_OS_NAME}/before_install.sh $CGAL_VERSION
1719

1820
before_script:
19-
- cmake -DSFCGAL_BUILD_TESTS=ON
21+
- CGAL_DIR=/usr/local/lib/CGAL cmake -DSFCGAL_BUILD_TESTS=ON
2022

2123
script:
2224
- make

cmake/Modules/FindCGAL.cmake

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/Coordinate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ class RoundVisitor : public boost::static_visitor<> {
267267

268268
Kernel::FT _roundFT( const Kernel::FT& v ) const {
269269
#ifdef CGAL_USE_GMPXX
270-
return Kernel::FT( ::mpq_class(
271-
SFCGAL::round( v.exact() * _scaleFactor ),
272-
_scaleFactor
273-
) ) ;
270+
::mpq_class q( SFCGAL::round( v.exact() * _scaleFactor ),
271+
_scaleFactor) ;
272+
q.canonicalize();
273+
return Kernel::FT(q);
274274
#else
275275
return Kernel::FT( CGAL::Gmpq(
276276
SFCGAL::round( v.exact() * _scaleFactor ),

src/detail/io/Serialization.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,53 @@ void load( boost::archive::binary_iarchive& ar, CGAL::Gmpz& z, const unsigned in
169169
}
170170
}
171171

172+
#ifdef CGAL_USE_GMPXX
173+
void save( boost::archive::text_oarchive& ar, const mpz_class& z, const unsigned int /*version*/ )
174+
{
175+
std::ostringstream ostr;
176+
ostr << z;
177+
std::string str = ostr.str();
178+
ar << str;
179+
}
180+
181+
// specialization for binary archives
182+
void save ( boost::archive::binary_oarchive& ar, const mpz_class& z, const unsigned int/* version*/ )
183+
{
184+
mpz_srcptr mpz = z.get_mpz_t();
185+
int32_t size = mpz->_mp_size;
186+
ar& size;
187+
uint32_t rsize = size >= 0 ? size : -size;
188+
189+
for ( uint32_t i = 0; i < rsize; ++i ) {
190+
ar& mpz->_mp_d[i];
191+
}
192+
}
193+
194+
195+
void load( boost::archive::text_iarchive& ar, mpz_class& z, const unsigned int /*version*/ )
196+
{
197+
std::string line;
198+
ar >> line;
199+
std::istringstream istr( line );
200+
istr >> z;
201+
}
202+
203+
void load( boost::archive::binary_iarchive& ar, mpz_class& z, const unsigned int /*version*/ )
204+
{
205+
int32_t size;
206+
uint32_t rsize;
207+
mpz_ptr mpz = z.get_mpz_t();
208+
ar& size;
209+
rsize = size >= 0 ? size : -size;
210+
mpz->_mp_size = size;
211+
_mpz_realloc( mpz, rsize );
212+
uint32_t i;
213+
214+
for ( i = 0; i < rsize; ++i ) {
215+
ar& mpz->_mp_d[i];
216+
}
217+
}
218+
#endif
219+
172220
}
173221
}

src/detail/io/Serialization.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include <boost/archive/binary_iarchive.hpp>
3535
#include <boost/archive/text_oarchive.hpp>
3636
#include <boost/archive/text_iarchive.hpp>
37+
#ifdef CGAL_USE_GMPXX
38+
#include <CGAL/mpz_class.h>
39+
#include <CGAL/mpq_class.h>
40+
#endif
3741

3842
namespace SFCGAL {
3943

@@ -132,6 +136,63 @@ void serialize( Archive& ar, CGAL::Gmpq& q, const unsigned int version )
132136
split_free( ar, q, version );
133137
}
134138

139+
#ifdef CGAL_USE_GMPXX
140+
/**
141+
* Serialization of mpz_class for text archives
142+
*/
143+
SFCGAL_API void save( boost::archive::text_oarchive& ar, const mpz_class& z, const unsigned int version );
144+
145+
/**
146+
* Serialization of mpz_class for binary archives
147+
*/
148+
SFCGAL_API void save ( boost::archive::binary_oarchive& ar, const mpz_class& z, const unsigned int version );
149+
150+
/**
151+
* Unserialization of mpz_class for text archives
152+
*/
153+
SFCGAL_API void load( boost::archive::text_iarchive& ar, mpz_class& z, const unsigned int version );
154+
155+
/**
156+
* Unserialization of mpz_class for binary archives
157+
*/
158+
SFCGAL_API void load( boost::archive::binary_iarchive& ar, mpz_class& z, const unsigned int version );
159+
160+
template<class Archive>
161+
void serialize( Archive& ar, mpz_class& z, const unsigned int version )
162+
{
163+
split_free( ar, z, version );
164+
}
165+
166+
/**
167+
* Serializer of mpq_class
168+
*/
169+
template<class Archive>
170+
void save( Archive& ar, const mpq_class& q, const unsigned int /*version*/ )
171+
{
172+
mpz_class n = q.get_num();
173+
mpz_class d = q.get_den();
174+
ar& n;
175+
ar& d;
176+
}
177+
178+
/**
179+
* Unserializer of mpq_class
180+
*/
181+
template<class Archive>
182+
void load( Archive& ar, mpq_class& q, const unsigned int /*version*/ )
183+
{
184+
mpz_class n;
185+
mpz_class d;
186+
ar& n;
187+
ar& d;
188+
q = mpq_class( n, d );
189+
}
190+
template<class Archive>
191+
void serialize( Archive& ar, mpq_class& q, const unsigned int version )
192+
{
193+
split_free( ar, q, version );
194+
}
195+
#endif
135196

136197
/**
137198
* Serializer of Kernel::FT

src/detail/io/WktReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ bool WktReader::readPointCoordinate( Point& p )
647647
}
648648

649649
p = Point( coordinates[0], coordinates[1], coordinates[2] );
650-
p.setM( coordinates[3].to_double() );
650+
p.setM( CGAL::to_double(coordinates[3]) );
651651
}
652652
else if ( _isMeasured && ! _is3D ) {
653653
// XYM
@@ -656,7 +656,7 @@ bool WktReader::readPointCoordinate( Point& p )
656656
}
657657

658658
p = Point( coordinates[0], coordinates[1] );
659-
p.setM( coordinates[2].to_double() );
659+
p.setM( CGAL::to_double(coordinates[2]) );
660660
}
661661
else if ( coordinates.size() == 3 ) {
662662
// XYZ

src/detail/io/WktWriter.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ namespace SFCGAL {
4040
namespace detail {
4141
namespace io {
4242

43+
namespace impl {
44+
std::ostream& writeFT(std::ostream& s, const CGAL::Gmpq& ft)
45+
{
46+
s << ft;
47+
return s;
48+
}
49+
50+
#ifdef CGAL_USE_GMPXX
51+
std::ostream& writeFT(std::ostream& s, const mpq_class& ft)
52+
{
53+
s << ft.get_num() << "/" << ft.get_den();
54+
return s;
55+
}
56+
#endif
57+
} //end of impl namespace
58+
4359
///
4460
///
4561
///
@@ -135,10 +151,12 @@ void WktWriter::writeCoordinateType( const Geometry& g )
135151
void WktWriter::writeCoordinate( const Point& g )
136152
{
137153
if ( _exactWrite ) {
138-
_s << CGAL::exact( g.x() ) << " " << CGAL::exact( g.y() );
154+
impl::writeFT(_s, CGAL::exact( g.x() )) << " ";
155+
impl::writeFT(_s, CGAL::exact( g.y() ));
139156

140157
if ( g.is3D() ) {
141-
_s << " " << CGAL::exact( g.z() );
158+
_s << " ";
159+
impl::writeFT(_s, CGAL::exact( g.z() ));
142160
}
143161
}
144162
else {

src/detail/tools/InputStreamReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class BasicInputStreamReader {
150150
skipWhiteSpaces();
151151
}
152152

153-
if ( _s >> value ) {
153+
if( _s >> CGAL::iformat(value) ) {
154154
commit();
155155
return true ;
156156
}

src/numeric.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,48 @@ CGAL::Gmpz round( const CGAL::Gmpq& v )
5858
}
5959
}
6060

61+
#ifdef CGAL_USE_GMPXX
62+
///
63+
///
64+
///
65+
mpz_class floor( const mpq_class& v )
66+
{
67+
return v.get_num() / v.get_den() ;
68+
}
69+
70+
///
71+
///
72+
///
73+
mpz_class ceil( const mpq_class& v )
74+
{
75+
mpz_class result( 0 ) ;
76+
mpz_cdiv_q( result.get_mpz_t(), v.get_num().get_mpz_t(), v.get_den().get_mpz_t() ) ;
77+
return result ;
78+
}
79+
80+
///
81+
///
82+
///
83+
mpz_class round( const mpq_class& v )
84+
{
85+
if ( v < 0 ) {
86+
//ceil( v - 0.5 ) ;
87+
mpq_class tmp = v - mpq_class( 1,2 );
88+
return ceil( tmp );
89+
}
90+
else if ( v == 0 ) {
91+
return 0 ;
92+
}
93+
else {
94+
//floor( v + 0.5 ) ;
95+
mpq_class tmp = v + mpq_class( 1,2 );
96+
return floor( tmp );
97+
}
98+
}
99+
#endif
100+
101+
102+
61103
}//SFCGAL
62104

63105

test/garden/CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ add_executable( ${REGRESS_NAME} ${SFCGAL_REGRESS_GARDEN_TEST_SOURCES} )
66

77
target_link_libraries( ${REGRESS_NAME}
88
SFCGAL
9-
${Boost_LIBRARIES}
10-
${CGAL_LIBRARIES}
9+
CGAL::CGAL
10+
CGAL::CGAL_Core
1111
)
12-
if( ${SFCGAL_WITH_MPFR} )
13-
target_link_libraries( ${REGRESS_NAME} ${MPFR_LIBRARIES} )
14-
endif( ${SFCGAL_WITH_MPFR} )
12+
target_link_libraries( ${REGRESS_NAME} ${CGAL_3RD_PARTY_LIBRARIES} )
1513

1614
set_target_properties( ${REGRESS_NAME} PROPERTIES DEBUG_POSTFIX "d" )
1715
install( TARGETS ${REGRESS_NAME} DESTINATION bin )

0 commit comments

Comments
 (0)