Skip to content

Commit

Permalink
Refactor: simplify conditionals.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Oct 16, 2024
1 parent 784fa8b commit d2d17f8
Showing 1 changed file with 23 additions and 49 deletions.
72 changes: 23 additions & 49 deletions ApplicationLibCode/ProjectDataModel/RimContourMapProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,24 @@ std::vector<cvf::Vec3d> RimContourMapProjection::generatePickPointPolygon()

if ( !m_pickPoint.isUndefined() )
{
{
#ifndef NDEBUG
cvf::Vec2d cellDiagonal( sampleSpacing() * 0.5, sampleSpacing() * 0.5 );
cvf::Vec2ui pickedCell = m_contourMapGrid->ijFromLocalPos( m_pickPoint );
cvf::Vec2d cellCenter = m_contourMapGrid->cellCenterPosition( pickedCell.x(), pickedCell.y() );
cvf::Vec2d cellCorner = cellCenter - cellDiagonal;
points.push_back( cvf::Vec3d( cellCorner, 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), 0.0 ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), 0.0 ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( 0.0, sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( 0.0, sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner, 0.0 ) );
cvf::Vec2d cellDiagonal( sampleSpacing() * 0.5, sampleSpacing() * 0.5 );
cvf::Vec2ui pickedCell = m_contourMapGrid->ijFromLocalPos( m_pickPoint );
cvf::Vec2d cellCenter = m_contourMapGrid->cellCenterPosition( pickedCell.x(), pickedCell.y() );
cvf::Vec2d cellCorner = cellCenter - cellDiagonal;
points.push_back( cvf::Vec3d( cellCorner, 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), 0.0 ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), 0.0 ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( sampleSpacing(), sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( 0.0, sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner + cvf::Vec2d( 0.0, sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( cellCorner, 0.0 ) );
#endif
points.push_back( cvf::Vec3d( m_pickPoint - cvf::Vec2d( 0.5 * sampleSpacing(), 0.0 ), 0.0 ) );
points.push_back( cvf::Vec3d( m_pickPoint + cvf::Vec2d( 0.5 * sampleSpacing(), 0.0 ), 0.0 ) );
points.push_back( cvf::Vec3d( m_pickPoint - cvf::Vec2d( 0.0, 0.5 * sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( m_pickPoint + cvf::Vec2d( 0.0, 0.5 * sampleSpacing() ), 0.0 ) );
}
points.push_back( cvf::Vec3d( m_pickPoint - cvf::Vec2d( 0.5 * sampleSpacing(), 0.0 ), 0.0 ) );
points.push_back( cvf::Vec3d( m_pickPoint + cvf::Vec2d( 0.5 * sampleSpacing(), 0.0 ), 0.0 ) );
points.push_back( cvf::Vec3d( m_pickPoint - cvf::Vec2d( 0.0, 0.5 * sampleSpacing() ), 0.0 ) );
points.push_back( cvf::Vec3d( m_pickPoint + cvf::Vec2d( 0.0, 0.5 * sampleSpacing() ), 0.0 ) );
}
return points;
}
Expand Down Expand Up @@ -256,10 +254,7 @@ QString RimContourMapProjection::resultAggregationText() const
QString RimContourMapProjection::caseName() const
{
RimCase* rimCase = baseView()->ownerCase();
if ( !rimCase )
{
return QString();
}
if ( !rimCase ) return QString();

return rimCase->caseUserDescription();
}
Expand All @@ -270,10 +265,7 @@ QString RimContourMapProjection::caseName() const
QString RimContourMapProjection::currentTimeStepName() const
{
RimCase* rimCase = baseView()->ownerCase();
if ( !rimCase || m_currentResultTimestep == -1 )
{
return QString();
}
if ( !rimCase || m_currentResultTimestep == -1 ) return QString();

return rimCase->timeStepName( m_currentResultTimestep );
}
Expand Down Expand Up @@ -576,15 +568,10 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s
//--------------------------------------------------------------------------------------------------
bool RimContourMapProjection::gridMappingNeedsUpdating() const
{
if ( m_projected3dGridIndices.size() != numberOfCells() )
{
return true;
}
if ( m_projected3dGridIndices.size() != numberOfCells() ) return true;

if ( m_cellGridIdxVisibility.isNull() ) return true;

if ( m_cellGridIdxVisibility.isNull() )
{
return true;
}
cvf::ref<cvf::UByteArray> currentVisibility = getCellVisibility();

CVF_ASSERT( currentVisibility->size() == m_cellGridIdxVisibility->size() );
Expand All @@ -601,21 +588,8 @@ bool RimContourMapProjection::gridMappingNeedsUpdating() const
//--------------------------------------------------------------------------------------------------
bool RimContourMapProjection::resultsNeedsUpdating( int timeStep ) const
{
if ( m_aggregatedResults.size() != numberOfCells() )
{
return true;
}

if ( m_aggregatedVertexResults.size() != numberOfVertices() )
{
return true;
}

if ( timeStep != m_currentResultTimestep )
{
return true;
}
return false;
return ( m_aggregatedResults.size() != numberOfCells() || m_aggregatedVertexResults.size() != numberOfVertices() ||
timeStep != m_currentResultTimestep );
}

//--------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit d2d17f8

Please sign in to comment.