Skip to content

Commit e15f666

Browse files
Use double (instead float) + performance (#8)
1 parent 132fccf commit e15f666

15 files changed

+356
-334
lines changed

include/ifcpp/Geometry/CVector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#include <concepts>
44

55
template<typename TVector>
6-
concept CVector = requires( TVector v, float f ) {
6+
concept CVector = requires( TVector v, double f ) {
77
{ TVector() } -> std::same_as<TVector>;
8-
{ v.x } -> std::convertible_to<float>;
9-
{ v.y } -> std::convertible_to<float>;
10-
{ v.z } -> std::convertible_to<float>;
8+
{ v.x } -> std::convertible_to<double>;
9+
{ v.y } -> std::convertible_to<double>;
10+
{ v.z } -> std::convertible_to<double>;
1111
{ v + v } -> std::same_as<TVector>;
1212
{ v - v } -> std::same_as<TVector>;
1313
{ -v } -> std::same_as<TVector>;

include/ifcpp/Geometry/CurveConverter.h

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,17 @@ class CurveConverter {
124124
if( conic ) {
125125
// ENTITY IfcConic ABSTRACT SUPERTYPE OF(ONEOF(IfcCircle, IfcEllipse))
126126
const auto placement = this->m_primitivesConverter->ConvertPlacement( conic->m_Position );
127-
float radius1 = 0.0f;
128-
float radius2 = 0.0f;
127+
double radius1 = 0.0;
128+
double radius2 = 0.0;
129129

130130
const auto ellipse = dynamic_pointer_cast<IfcEllipse>( conic );
131131
if( ellipse && ellipse->m_SemiAxis1 && ellipse->m_SemiAxis2 ) {
132-
radius1 = (float)ellipse->m_SemiAxis1->m_value;
133-
radius2 = (float)ellipse->m_SemiAxis2->m_value;
132+
radius1 = ellipse->m_SemiAxis1->m_value;
133+
radius2 = ellipse->m_SemiAxis2->m_value;
134134
}
135135
const auto circle = dynamic_pointer_cast<IfcCircle>( conic );
136136
if( circle && circle->m_Radius ) {
137-
radius1 = radius2 = (float)circle->m_Radius->m_value;
137+
radius1 = radius2 = circle->m_Radius->m_value;
138138
}
139139

140140
int n = this->m_parameters->m_numVerticesPerCircle; // TODO: should be calculated from radius
@@ -208,23 +208,23 @@ class CurveConverter {
208208
if( conic ) {
209209
// ENTITY IfcConic ABSTRACT SUPERTYPE OF(ONEOF(IfcCircle, IfcEllipse))
210210
const auto placement = this->m_primitivesConverter->ConvertPlacement( conic->m_Position );
211-
float radius1 = 0.0f;
212-
float radius2 = 0.0f;
211+
double radius1 = 0.0;
212+
double radius2 = 0.0;
213213

214214
const auto ellipse = dynamic_pointer_cast<IfcEllipse>( conic );
215215
if( ellipse && ellipse->m_SemiAxis1 && ellipse->m_SemiAxis2 ) {
216-
radius1 = (float)ellipse->m_SemiAxis1->m_value;
217-
radius2 = (float)ellipse->m_SemiAxis2->m_value;
216+
radius1 = ellipse->m_SemiAxis1->m_value;
217+
radius2 = ellipse->m_SemiAxis2->m_value;
218218
}
219219
shared_ptr<IfcCircle> circle = dynamic_pointer_cast<IfcCircle>( conic );
220220
if( circle && circle->m_Radius ) {
221-
radius1 = radius2 = (float)circle->m_Radius->m_value;
221+
radius1 = radius2 = circle->m_Radius->m_value;
222222
}
223223

224224
int n = this->m_parameters->m_numVerticesPerCircle; // TODO: should be calculated from radius
225225
n = std::max( n, this->m_parameters->m_minNumVerticesPerArc );
226226
if( radius1 > this->m_parameters->m_epsilon && radius2 > this->m_parameters->m_epsilon ) {
227-
result = this->m_geomUtils->BuildEllipse( radius1, radius2, 0.0f, (float)( M_PI * 2 ), n );
227+
result = this->m_geomUtils->BuildEllipse( radius1, radius2, 0.0, ( M_PI * 2 ), n );
228228
} else {
229229
result.push_back( AVector::New() );
230230
}
@@ -236,8 +236,8 @@ class CurveConverter {
236236
const auto origin = this->m_primitivesConverter->ConvertPoint( line->m_Pnt );
237237
const auto direction = AVector::Normalized( this->m_primitivesConverter->ConvertVector( line->m_Dir ) );
238238
result = {
239-
origin - direction * this->m_parameters->m_modelMaxSize * 0.5f,
240-
origin + direction * this->m_parameters->m_modelMaxSize * 0.5f,
239+
origin - direction * this->m_parameters->m_modelMaxSize * 0.5,
240+
origin + direction * this->m_parameters->m_modelMaxSize * 0.5,
241241
};
242242
}
243243

@@ -259,11 +259,12 @@ class CurveConverter {
259259
result = {};
260260
}
261261

262+
auto resultCopy = result;
262263
{
263264
#ifdef ENABLE_OPENMP
264265
ScopedLock lock( this->m_curveToPointsMapMutex );
265266
#endif
266-
this->m_curveToPointsMap[ curve ] = result;
267+
this->m_curveToPointsMap[ curve ] = std::move( resultCopy );
267268
}
268269
return result;
269270
}
@@ -304,10 +305,10 @@ class CurveConverter {
304305
}
305306

306307
private:
307-
std::tuple<float, float> GetTrimmingsForCircle( const std::vector<std::shared_ptr<IfcTrimmingSelect>>& t1,
308-
const std::vector<std::shared_ptr<IfcTrimmingSelect>>& t2, TVector center, bool senseAgreement ) {
309-
float l = this->GetTrimmingForCircle( t1, center );
310-
float r = this->GetTrimmingForCircle( t2, center );
308+
std::tuple<double, double> GetTrimmingsForCircle( const std::vector<std::shared_ptr<IfcTrimmingSelect>>& t1,
309+
const std::vector<std::shared_ptr<IfcTrimmingSelect>>& t2, TVector center, bool senseAgreement ) {
310+
double l = this->GetTrimmingForCircle( t1, center );
311+
double r = this->GetTrimmingForCircle( t2, center );
311312

312313
if( senseAgreement && l < r ) {
313314
return { l, r - l };
@@ -321,10 +322,10 @@ class CurveConverter {
321322
if( !senseAgreement && l > r ) {
322323
return { l, l - r };
323324
}
324-
return { l, 0.0f };
325+
return { l, 0.0 };
325326
}
326327

327-
float GetTrimmingForCircle( std::vector<std::shared_ptr<IfcTrimmingSelect>> t, TVector center ) {
328+
double GetTrimmingForCircle( std::vector<std::shared_ptr<IfcTrimmingSelect>> t, TVector center ) {
328329
if( t.size() > 1 && std::dynamic_pointer_cast<IfcParameterValue>( t[ 1 ] ) ) {
329330
std::swap( t[ 0 ], t[ 1 ] );
330331
}
@@ -333,34 +334,35 @@ class CurveConverter {
333334
const auto dir = AVector::Normalized( this->m_primitivesConverter->ConvertPoint( cartesianPoint ) - center );
334335
// TODO: Verify code
335336
if( dir.x >= this->m_parameters->m_epsilon && dir.y >= this->m_parameters->m_epsilon ) {
336-
return acosf( AVector::Dot( AVector::New( 1, 0, 0 ), dir ) );
337+
return acos( AVector::Dot( AVector::New( 1, 0, 0 ), dir ) );
337338
} else if( dir.x < -this->m_parameters->m_epsilon && dir.y >= this->m_parameters->m_epsilon ) {
338-
return M_PI_2 + acosf( AVector::Dot( AVector::New( 0, 1, 0 ), dir ) );
339+
return M_PI_2 + acos( AVector::Dot( AVector::New( 0, 1, 0 ), dir ) );
339340
} else if( dir.x < -this->m_parameters->m_epsilon && dir.y < -this->m_parameters->m_epsilon ) {
340-
return M_PI + acosf( AVector::Dot( AVector::New( -1, 0, 0 ), dir ) );
341+
return M_PI + acos( AVector::Dot( AVector::New( -1, 0, 0 ), dir ) );
341342
} else {
342-
return M_PI + M_PI_2 + acosf( AVector::Dot( AVector::New( 0, -1, 0 ), dir ) );
343+
return M_PI + M_PI_2 + acos( AVector::Dot( AVector::New( 0, -1, 0 ), dir ) );
343344
}
344345
}
345346
const auto parameterValue = std::dynamic_pointer_cast<IfcParameterValue>( t[ 0 ] );
346347
if( parameterValue ) {
347-
return (float)( parameterValue->m_value * this->m_parameters->m_angleFactor );
348+
return ( parameterValue->m_value * this->m_parameters->m_angleFactor );
348349
}
349350
// TODO: Log error
350351
return 0;
351352
}
352353

353-
std::tuple<float, float> GetTrimmingsForLine( const std::vector<std::shared_ptr<IfcTrimmingSelect>>& t1,
354-
const std::vector<std::shared_ptr<IfcTrimmingSelect>>& t2, TVector origin, TVector dir, bool senseArgement ) {
355-
float l = this->GetTrimmingForLine( t1, origin, dir );
356-
float r = this->GetTrimmingForLine( t2, origin, dir );
354+
std::tuple<double, double> GetTrimmingsForLine( const std::vector<std::shared_ptr<IfcTrimmingSelect>>& t1,
355+
const std::vector<std::shared_ptr<IfcTrimmingSelect>>& t2, TVector origin, TVector dir,
356+
bool senseArgement ) {
357+
double l = this->GetTrimmingForLine( t1, origin, dir );
358+
double r = this->GetTrimmingForLine( t2, origin, dir );
357359
if( senseArgement && l > r || !senseArgement && l < r ) {
358360
std::swap( l, r );
359361
}
360362
return { l, r };
361363
}
362364

363-
float GetTrimmingForLine( std::vector<std::shared_ptr<IfcTrimmingSelect>> t, TVector origin, TVector dir ) {
365+
double GetTrimmingForLine( std::vector<std::shared_ptr<IfcTrimmingSelect>> t, TVector origin, TVector dir ) {
364366
if( t.size() > 1 && std::dynamic_pointer_cast<IfcParameterValue>( t[ 1 ] ) ) {
365367
std::swap( t[ 0 ], t[ 1 ] );
366368
}
@@ -370,18 +372,18 @@ class CurveConverter {
370372
}
371373
const auto parameterValue = std::dynamic_pointer_cast<IfcParameterValue>( t[ 0 ] );
372374
if( parameterValue ) {
373-
return (float)parameterValue->m_value;
375+
return parameterValue->m_value;
374376
}
375377
// TODO: Log error
376378
return 0;
377379
}
378380

379381
TVector GetClosestPointOnCurve( const TCurve& curve, const TVector& point ) {
380382
TVector result = curve[ 0 ];
381-
float distance2 = AVector::Len2( point - result );
383+
double distance2 = AVector::Len2( point - result );
382384
for( int i = 1; i < curve.size(); i++ ) {
383385
TVector r = this->m_geomUtils->ClosestPointOnEdge( curve[ i - 1 ], curve[ i ], point );
384-
float d2 = AVector::Len2( point - r );
386+
double d2 = AVector::Len2( point - r );
385387
if( d2 < distance2 ) {
386388
result = r;
387389
distance2 = d2;

include/ifcpp/Geometry/Extruder.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ class Extruder {
8181
}
8282

8383
std::vector<TVector> rDirs, fDirs, uDirs;
84-
std::vector<float> k;
84+
std::vector<double> k;
8585

8686
fDirs.push_back( AVector::Normalized( sweepPoints[ 1 ] - sweepPoints[ 0 ] ) );
87-
k.push_back( 1.0f );
87+
k.push_back( 1.0 );
8888
for( int i = 1; i < sweepPoints.size() - 1; i++ ) {
8989
fDirs.push_back( AVector::Normalized( AVector::Normalized( sweepPoints[ i ] - sweepPoints[ i - 1 ] ) +
9090
AVector::Normalized( sweepPoints[ i + 1 ] - sweepPoints[ i ] ) ) );
91-
float angle = acosf( AVector::Dot( AVector::Normalized( sweepPoints[ i ] - sweepPoints[ i - 1 ] ),
91+
double angle = acos( AVector::Dot( AVector::Normalized( sweepPoints[ i ] - sweepPoints[ i - 1 ] ),
9292
AVector::Normalized( sweepPoints[ i ] - sweepPoints[ i + 1 ] ) ) );
93-
k.push_back( 1.0f / sinf( angle / 2.0f ) );
93+
k.push_back( 1.0 / sin( angle / 2.0 ) );
9494
}
9595
fDirs.push_back( AVector::Normalized( sweepPoints[ sweepPoints.size() - 1 ] - sweepPoints[ sweepPoints.size() - 2 ] ) );
96-
k.push_back( 1.0f );
96+
k.push_back( 1.0 );
9797

9898
auto up = AVector::New( 0, 0, 1 );
9999
for( int i = 0; i < sweepPoints.size(); i++ ) {
@@ -122,7 +122,7 @@ class Extruder {
122122

123123
return result;
124124
}
125-
std::vector<TLoop> Revolve( TLoop profile, const TVector& axisLocation, const TVector& axisDirection, float revolveAngle, bool asClosed = true ) {
125+
std::vector<TLoop> Revolve( TLoop profile, const TVector& axisLocation, const TVector& axisDirection, double revolveAngle, bool asClosed = true ) {
126126
if( profile.empty() ) {
127127
return {};
128128
}
@@ -142,9 +142,9 @@ class Extruder {
142142

143143
result.push_back( this->m_geomUtils->SimplifyLoop( profile ) );
144144
int n = this->m_parameters->m_numVerticesPerCircle;
145-
float deltaAngle = revolveAngle / (float)( n - 1 );
145+
double deltaAngle = revolveAngle / (double)( n - 1 );
146146
for( int i = 1; i < n; i++ ) {
147-
auto m = TMatrix::GetRotation( deltaAngle * (float)i, axisDirection );
147+
auto m = TMatrix::GetRotation( deltaAngle * i, axisDirection );
148148
auto p = m.GetTransformedLoop( profile );
149149
const auto connection = this->ConnectLoops( result[ i - 1 ], p );
150150
std::copy( std::begin( connection ), std::end( connection ), std::back_inserter( result ) );

0 commit comments

Comments
 (0)