fixes from review

This commit is contained in:
bdm-oslandia 2025-07-22 09:58:15 +02:00 committed by Nyall Dawson
parent 0933b2a16e
commit 7145474c97
5 changed files with 24 additions and 81 deletions

View File

@ -1,8 +1,8 @@
/***************************************************************************
qgssfcgalengine.cpp
----------------
begin : September 2024
copyright : (C) 2024 by Benoit De Mezzo
begin : May 2025
copyright : (C) 2025 by Oslandia
email : benoit dot de dot mezzo at oslandia dot com
***************************************************************************/
@ -20,10 +20,8 @@
#include "qgssfcgalengine.h"
#include "qgsgeometry.h"
#include "qgspolygon.h"
#include "qgsgeometryfactory.h"
#include "qgssfcgalgeometry.h"
#include <thread>
// ===================================
// sfcgal namespace
@ -619,7 +617,10 @@ sfcgal::shared_geom QgsSfcgalEngine::translate( const sfcgal::geometry *geom, co
CHECK_NOT_NULL( geom, nullptr );
sfcgal::geometry *result;
result = sfcgal_geometry_translate_3d( geom, translation.x(), translation.y(), translation.z() );
if ( sfcgal_geometry_is_3d( geom ) )
result = sfcgal_geometry_translate_3d( geom, translation.x(), translation.y(), translation.z() );
else
result = sfcgal_geometry_translate_2d( geom, translation.x(), translation.y() );
CHECK_SUCCESS( errorMsg, nullptr );
return sfcgal::make_shared_geom( result );

View File

@ -21,7 +21,6 @@
#define SIP_NO_FILE
#include <functional>
#include <SFCGAL/capi/sfcgal_c.h>
#include "qgspoint.h"
@ -61,7 +60,7 @@ class QgsSfcgalGeometry;
/**
* Contains SFCGAL related utilities and functions.
* \note not available in Python bindings.
* \since QGIS 3.46
* \since QGIS 4.0
*/
namespace sfcgal
{
@ -102,7 +101,7 @@ namespace sfcgal
*
* Messages are held in a stacktrace in order to improve context understanding.
* \ingroup core
* \since QGIS 3.46
* \since QGIS 4.0
*/
class CORE_EXPORT ErrorHandler
{
@ -154,7 +153,7 @@ namespace sfcgal
* \ingroup core
* \brief Does vector analysis using the SFCGAL library and handles import, export, exception handling
* \note not available in Python bindings
* \since QGIS 3.46
* \since QGIS 4.0
*/
class CORE_EXPORT QgsSfcgalEngine
{

View File

@ -1,8 +1,8 @@
/***************************************************************************
qgssfcgalGeometry.cpp
----------------
begin : September 2024
copyright : (C) 2024 by Benoit De Mezzo
begin : May 2025
copyright : (C) 2025 by Oslandia
email : benoit dot de dot mezzo at oslandia dot com
***************************************************************************/
@ -140,12 +140,12 @@ QString QgsSfcgalGeometry::asWkt( int precision, QString *errorMsg ) const
return out;
}
QgsAbstractGeometry *QgsSfcgalGeometry::asQgisGeometry( QString *errorMsg ) const
std::unique_ptr<QgsAbstractGeometry> QgsSfcgalGeometry::asQgisGeometry( QString *errorMsg ) const
{
sfcgal::errorHandler()->clearText( errorMsg );
std::unique_ptr<QgsAbstractGeometry> out = QgsSfcgalEngine::toAbstractGeometry( mSfcgalGeom.get(), errorMsg );
CHECK_SUCCESS( errorMsg, nullptr );
return out.release();
return out;
}
std::unique_ptr<QgsSfcgalGeometry> QgsSfcgalGeometry::boundary( QString *errorMsg ) const

View File

@ -48,7 +48,7 @@
* \ingroup core
* \class QgsSfcgalGeometry
* \brief SfcgalGeometry geometry type.
* \since QGIS 3.46
* \since QGIS 4.0
*/
class CORE_EXPORT QgsSfcgalGeometry
{
@ -84,7 +84,7 @@ class CORE_EXPORT QgsSfcgalGeometry
* Returns the geometry converted to a QGIS geometry object.
* This method is slow to call, as it always involves re-conversion of the underlying SFCGAL geometry object.
*/
QgsAbstractGeometry *asQgisGeometry( QString *errorMsg = nullptr ) const;
std::unique_ptr<QgsAbstractGeometry> asQgisGeometry( QString *errorMsg = nullptr ) const;
/**
* Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
@ -434,63 +434,6 @@ class CORE_EXPORT QgsSfcgalGeometry
*/
std::unique_ptr<QgsSfcgalGeometry> extrude( const QgsVector3D &extrusion, QString *errorMsg = nullptr ) const;
#ifndef SIP_RUN
/**
* Cast the \a geom to the exact underlying QGIS geometry.
* Should be used, for example, by qgsgeometry_cast<QgsPoint *>( geometry ) or by qgsgeometry_cast<QgsPolygon *>( geometry ).
*
* \note Not available in Python. Objects will be automatically be converted to the appropriate target type.
*/
inline static const QgsAbstractGeometry *cast( const QgsSfcgalGeometry *geom )
{
if ( geom )
{
QString errorMsg;
const QgsAbstractGeometry *qgsGeom = geom->asQgisGeometry( &errorMsg );
CHECK_SUCCESS_LOG( &errorMsg, nullptr );
const Qgis::WkbType type = QgsWkbTypes::flatType( geom->wkbType() );
switch ( type )
{
case Qgis::WkbType::Point:
return QgsPoint::cast( qgsGeom );
case Qgis::WkbType::LineString:
return QgsLineString::cast( qgsGeom );
case Qgis::WkbType::CircularString:
return QgsCircularString::cast( qgsGeom );
case Qgis::WkbType::CompoundCurve:
return QgsCompoundCurve::cast( qgsGeom );
case Qgis::WkbType::Polygon:
return QgsPolygon::cast( qgsGeom );
case Qgis::WkbType::CurvePolygon:
return QgsCurvePolygon::cast( qgsGeom );
case Qgis::WkbType::MultiLineString:
return QgsMultiLineString::cast( qgsGeom );
case Qgis::WkbType::MultiPolygon:
return QgsMultiPolygon::cast( qgsGeom );
case Qgis::WkbType::MultiPoint:
return QgsMultiPoint::cast( qgsGeom );
case Qgis::WkbType::MultiCurve:
return QgsMultiCurve::cast( qgsGeom );
case Qgis::WkbType::MultiSurface:
return QgsMultiSurface::cast( qgsGeom );
case Qgis::WkbType::GeometryCollection:
return QgsGeometryCollection::cast( qgsGeom );
case Qgis::WkbType::Triangle:
return QgsTriangle::cast( qgsGeom );
case Qgis::WkbType::PolyhedralSurface:
return QgsPolyhedralSurface::cast( qgsGeom );
case Qgis::WkbType::TIN:
return QgsTriangulatedSurface::cast( qgsGeom );
default:
return nullptr;
}
}
return nullptr;
}
#endif
protected:
/**

View File

@ -719,7 +719,7 @@ void TestQgsSfcgal::intersection()
QVERIFY2( intersectionGeom, ( QString( "intersectionGeom is NULL. SFCGAL msg: '%1'" ).arg( errorMsg ) ).toStdString().c_str() );
QCOMPARE( intersectionGeom->wkbType(), Qgis::WkbType::Polygon );
const QgsPolygon *intersectionPoly = qgsgeometry_cast<const QgsPolygon *>( intersectionGeom->asQgisGeometry( &errorMsg ) );
const QgsPolygon *intersectionPoly = qgsgeometry_cast<const QgsPolygon *>( intersectionGeom->asQgisGeometry( &errorMsg ).release() );
QVERIFY( intersectionPoly ); // check that the union created a feature
QVERIFY( intersectionPoly->exteriorRing()->length() > 0 ); // check that the union created a feature
QCOMPARE( intersectionPoly->exteriorRing()->asWkt(), QStringLiteral( "LineString (40 80, 40 40, 80 40, 80 80, 40 80)" ) );
@ -757,7 +757,7 @@ void TestQgsSfcgal::intersection3d()
"-129431703432785341454725506788272017716469477079/23313107857443583859443690159709871847505920 41489508487091336404601688874406905270455411499/11656553928721791929721845079854935923752960 20/1)"
")" ) );
const QgsMultiCurve *interCurve = qgsgeometry_cast<const QgsMultiCurve *>( scInterGeom->asQgisGeometry( &errorMsg ) );
const QgsMultiCurve *interCurve = qgsgeometry_cast<const QgsMultiCurve *>( scInterGeom->asQgisGeometry( &errorMsg ).release() );
QCOMPARE( interCurve->partCount(), 2 ); // check that the operation created 2 features
QCOMPARE( interCurve->curveN( 0 )->asWkt( 2 ), QStringLiteral( "LineString Z (-5863.79 3335.64 20, -5551.89 3559.33 20)" ) );
QCOMPARE( interCurve->curveN( 1 )->asWkt( 2 ), QStringLiteral( "LineString Z (-5520.8 3581.62 20, -5551.89 3559.33 20)" ) );
@ -775,7 +775,7 @@ void TestQgsSfcgal::intersection3d()
"-3694427387541401611431496726449054179068805833/593047719006612426355979511374504815230976 70556612052601521660517929315037655768347058877/18977527008211597643391344363984154087391232 0/1)"
")" ) );
const QgsMultiCurve *interCurve = qgsgeometry_cast<const QgsMultiCurve *>( scInterGeom->asQgisGeometry( &errorMsg ) );
const QgsMultiCurve *interCurve = qgsgeometry_cast<const QgsMultiCurve *>( scInterGeom->asQgisGeometry( &errorMsg ).release() );
QCOMPARE( interCurve->partCount(), 2 ); // check that the operation created 2 features
QCOMPARE( interCurve->curveN( 0 )->asWkt( 2 ), QStringLiteral( "LineString Z (-6321.91 3651.67 0, -6229.56 3717.9 0)" ) );
QCOMPARE( interCurve->curveN( 1 )->asWkt( 2 ), QStringLiteral( "LineString Z (-5814.13 4015.84 0, -6229.56 3717.9 0)" ) );
@ -795,7 +795,7 @@ void TestQgsSfcgal::intersection3d()
QCOMPARE( resultGeom->wkbType(), Qgis::WkbType::GeometryCollectionZ );
QCOMPARE( resultGeom->partCount(), 7 );
const QgsGeometryCollection *castGeom = qgsgeometry_cast<const QgsGeometryCollection *>( resultGeom->asQgisGeometry( &errorMsg ) );
const QgsGeometryCollection *castGeom = qgsgeometry_cast<const QgsGeometryCollection *>( resultGeom->asQgisGeometry( &errorMsg ).release() );
QVERIFY( castGeom != nullptr );
QCOMPARE( castGeom->partCount(), 7 );
@ -848,7 +848,7 @@ void TestQgsSfcgal::unionCheck1()
QVERIFY( combinedGeom->partCount() > 0 ); // check that the union did not fail
const QgsGeometryCollection *castGeom = qgsgeometry_cast<const QgsGeometryCollection *>( combinedGeom->asQgisGeometry( &errorMsg ) );
const QgsGeometryCollection *castGeom = qgsgeometry_cast<const QgsGeometryCollection *>( combinedGeom->asQgisGeometry( &errorMsg ).release() );
QVERIFY( castGeom != nullptr );
paintMultiPolygon( castGeom );
@ -873,7 +873,7 @@ void TestQgsSfcgal::unionCheck2()
QVERIFY( combinedGeom->partCount() > 0 ); // check that the union did not fail
const QgsPolygon *castGeom = qgsgeometry_cast<const QgsPolygon *>( combinedGeom->asQgisGeometry( &errorMsg ) );
const QgsPolygon *castGeom = qgsgeometry_cast<const QgsPolygon *>( combinedGeom->asQgisGeometry( &errorMsg ).release() );
QVERIFY( castGeom != nullptr );
paintPolygon( castGeom );
@ -895,7 +895,7 @@ void TestQgsSfcgal::differenceCheck1()
QVERIFY( diffGeom->partCount() > 0 ); // check that the union did not fail
const QgsPolygon *castGeom = qgsgeometry_cast<const QgsPolygon *>( diffGeom->asQgisGeometry( &errorMsg ) );
const QgsPolygon *castGeom = qgsgeometry_cast<const QgsPolygon *>( diffGeom->asQgisGeometry( &errorMsg ).release() );
QVERIFY( castGeom != nullptr );
paintPolygon( castGeom );
@ -914,7 +914,7 @@ void TestQgsSfcgal::differenceCheck2()
QVERIFY( diffGeom->partCount() > 0 ); // check that the union did not fail
const QgsPolygon *castGeom = qgsgeometry_cast<const QgsPolygon *>( diffGeom->asQgisGeometry( &errorMsg ) );
const QgsPolygon *castGeom = qgsgeometry_cast<const QgsPolygon *>( diffGeom->asQgisGeometry( &errorMsg ).release() );
QVERIFY( castGeom != nullptr );
paintPolygon( castGeom );
@ -963,7 +963,7 @@ void TestQgsSfcgal::difference3d()
QCOMPARE( scDiffGeom->wkbType(), Qgis::WkbType::TINZ );
QVERIFY2( scDiffGeom, ( QString( "diffGeom is NULL. SFCGAL msg: '%1'" ).arg( errorMsg ) ).toStdString().c_str() );
const QgsTriangulatedSurface *castGeom = qgsgeometry_cast<const QgsTriangulatedSurface *>( scDiffGeom->asQgisGeometry( &errorMsg ) );
const QgsTriangulatedSurface *castGeom = qgsgeometry_cast<const QgsTriangulatedSurface *>( scDiffGeom->asQgisGeometry( &errorMsg ).release() );
QVERIFY( castGeom != nullptr );
// 3rd: prepare compare