Skip to content
Merged
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
9 changes: 9 additions & 0 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
*/

#pragma once
#define _USE_MATH_DEFINES
#include <cmath>

#include <limits>
#include <set>
#include <string>
#include <vector>
Expand Down Expand Up @@ -79,4 +82,10 @@ namespace e57

/// generates a new random GUID
std::string generateRandomGUID();

inline bool isZero( double d )
{
return ( std::abs( d ) < std::numeric_limits<double>::epsilon() ) && !std::isnan( d ) &&
!std::isinf( d );
}
}
5 changes: 2 additions & 3 deletions src/E57SimpleData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
#include "E57SimpleData.h"

#include "Common.h"
#include "StringFunctions.h"

namespace e57
{
/// @private
/// Validates a Data3D and throws on error.
constexpr void _validateData3D( const Data3D &inData3D )
constexpr void _validateData3DNodeTypes( const Data3D &inData3D )
{
if ( inData3D.pointFields.pointRangeNodeType == NumericalNodeType::Integer )
{
Expand Down Expand Up @@ -49,7 +48,7 @@ namespace e57
{
static_assert( std::is_floating_point<COORDTYPE>::value, "Floating point type required." );

_validateData3D( data3D );
_validateData3DNodeTypes( data3D );

constexpr bool cIsFloat = std::is_same<COORDTYPE, float>::value;

Expand Down
9 changes: 4 additions & 5 deletions src/E57SimpleWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ namespace
const bool cWriteSphericalBounds =
cUsingSpherical && ( ioData3DHeader.sphericalBounds == e57::SphericalBounds{} );

// IF we are using scaled ints for timestamps
// AND we haven't set either min or max
// IF we haven't set either min or max timestamp
// THEN calculate them from the points
// NOTE: timestamp is always a double in Data3DPointsData_t and not affected by the COORDTYPE
double timeMinimum = std::numeric_limits<double>::max();
Expand Down Expand Up @@ -200,7 +199,7 @@ namespace e57
{
if ( inData3D.pointFields.intensityNodeType == NumericalNodeType::ScaledInteger )
{
if ( inData3D.pointFields.intensityScale == 0.0 )
if ( isZero( inData3D.pointFields.intensityScale ) )
{
throw E57_EXCEPTION2( ErrorInvalidData3DValue, "intensityScale cannot be 0" );
}
Expand All @@ -215,7 +214,7 @@ namespace e57
}
else if ( inData3D.pointFields.pointRangeNodeType == NumericalNodeType::ScaledInteger )
{
if ( inData3D.pointFields.pointRangeScale == 0.0 )
if ( isZero( inData3D.pointFields.pointRangeScale ) )
{
throw E57_EXCEPTION2( ErrorInvalidData3DValue, "pointRangeScale cannot be 0" );
}
Expand All @@ -231,7 +230,7 @@ namespace e57
}
else if ( inData3D.pointFields.angleNodeType == NumericalNodeType::ScaledInteger )
{
if ( inData3D.pointFields.angleScale == 0.0 )
if ( isZero( inData3D.pointFields.angleScale ) )
{
throw E57_EXCEPTION2( ErrorInvalidData3DValue, "angleScale cannot be 0" );
}
Expand Down
4 changes: 2 additions & 2 deletions src/ReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ namespace e57
{
const IntegerNode integerIntensity( intensityProto );

if ( data3DHeader.intensityLimits.intensityMaximum == 0.0 )
if ( isZero( data3DHeader.intensityLimits.intensityMaximum ) )
{
data3DHeader.intensityLimits.intensityMinimum =
static_cast<double>( integerIntensity.minimum() );
Expand All @@ -1346,7 +1346,7 @@ namespace e57
double scale = scaledIntensity.scale();
double offset = scaledIntensity.offset();

if ( data3DHeader.intensityLimits.intensityMaximum == 0.0 )
if ( isZero( data3DHeader.intensityLimits.intensityMaximum ) )
{
const int64_t minimum = scaledIntensity.minimum();
const int64_t maximum = scaledIntensity.maximum();
Expand Down
Loading