mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-20 00:21:31 +00:00
Standardise clamp function
std::clamp and alg:clamp had different argument orders. Since std::clamp is constexpr, we might as well just use that now we have it.
This commit is contained in:
parent
58669f2b9f
commit
4bad76825c
3d-viewer/3d_canvas
common
eeschema
include/preview_items
libs/core/include/core
pcbnew
@ -322,7 +322,7 @@ void BOARD_ADAPTER::createTrackWithMargin( const PCB_TRACK* aTrack, CONTAINER_2D
|
||||
else
|
||||
{
|
||||
circlesegcount = KiROUND( arcsegcount * 360.0 / std::abs( arc_angle.AsDegrees() ) );
|
||||
circlesegcount = alg::clamp( 1, circlesegcount, 128 );
|
||||
circlesegcount = std::clamp( circlesegcount, 1, 128 );
|
||||
}
|
||||
|
||||
createArcSegments( center, arc->GetStart(), arc_angle, circlesegcount,
|
||||
|
@ -394,7 +394,7 @@ void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent )
|
||||
wxCHECK( config(), /* void */ );
|
||||
|
||||
int idx = config()->m_Window.grid.last_size_idx;
|
||||
idx = alg::clamp( 0, idx, (int) m_gridSelectBox->GetCount() - 1 );
|
||||
idx = std::clamp( idx, 0, (int) m_gridSelectBox->GetCount() - 1 );
|
||||
|
||||
if( idx != m_gridSelectBox->GetSelection() )
|
||||
m_gridSelectBox->SetSelection( idx );
|
||||
|
@ -413,8 +413,8 @@ void EDA_TEXT::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
|
||||
int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
|
||||
int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
|
||||
|
||||
aNewSize = VECTOR2I( alg::clamp( min, aNewSize.x, max ),
|
||||
alg::clamp( min, aNewSize.y, max ) );
|
||||
aNewSize = VECTOR2I( std::clamp( aNewSize.x, min, max ),
|
||||
std::clamp( aNewSize.y, min, max ) );
|
||||
}
|
||||
|
||||
m_attributes.m_Size = aNewSize;
|
||||
@ -429,7 +429,7 @@ void EDA_TEXT::SetTextWidth( int aWidth )
|
||||
int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
|
||||
int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
|
||||
|
||||
m_attributes.m_Size.x = alg::clamp( min, aWidth, max );
|
||||
m_attributes.m_Size.x = std::clamp( aWidth, min, max );
|
||||
ClearRenderCache();
|
||||
m_bounding_box_cache_valid = false;
|
||||
}
|
||||
@ -440,7 +440,7 @@ void EDA_TEXT::SetTextHeight( int aHeight )
|
||||
int min = m_IuScale.get().mmToIU( TEXT_MIN_SIZE_MM );
|
||||
int max = m_IuScale.get().mmToIU( TEXT_MAX_SIZE_MM );
|
||||
|
||||
m_attributes.m_Size.y = alg::clamp( min, aHeight, max );
|
||||
m_attributes.m_Size.y = std::clamp( aHeight, min, max );
|
||||
ClearRenderCache();
|
||||
m_bounding_box_cache_valid = false;
|
||||
}
|
||||
|
@ -576,10 +576,10 @@ EDA_COLOR_T COLOR4D::FindNearestLegacyColor( int aR, int aG, int aB )
|
||||
|
||||
COLOR4D& COLOR4D::FromCSSRGBA( int aRed, int aGreen, int aBlue, double aAlpha )
|
||||
{
|
||||
r = alg::clamp( 0, aRed, 255 ) / 255.0;
|
||||
g = alg::clamp( 0, aGreen, 255 ) / 255.0;
|
||||
b = alg::clamp( 0, aBlue, 255 ) / 255.0;
|
||||
a = alg::clamp( 0.0, aAlpha, 1.0 );
|
||||
r = std::clamp( aRed, 0, 255 ) / 255.0;
|
||||
g = std::clamp( aGreen, 0, 255 ) / 255.0;
|
||||
b = std::clamp( aBlue, 0, 255 ) / 255.0;
|
||||
a = std::clamp( aAlpha, 0.0, 1.0 );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ int COMMON_TOOLS::GridPreset( int idx, bool aFromHotkey )
|
||||
{
|
||||
int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
|
||||
|
||||
currentGrid = alg::clamp( 0, idx, (int) m_grids.size() - 1 );
|
||||
currentGrid = std::clamp( idx, 0, (int) m_grids.size() - 1 );
|
||||
|
||||
return OnGridChanged( aFromHotkey );
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ DIALOG_SIM_FORMAT_VALUE::DIALOG_SIM_FORMAT_VALUE( wxWindow* aParent, SPICE_VALUE
|
||||
|
||||
bool DIALOG_SIM_FORMAT_VALUE::TransferDataFromWindow()
|
||||
{
|
||||
m_format->Precision = alg::clamp( 1, m_precisionCtrl->GetValue(), 9 );
|
||||
m_format->Precision = std::clamp( m_precisionCtrl->GetValue(), 1, 9 );
|
||||
|
||||
if( m_rangeCtrl->GetSelection() == 0 )
|
||||
m_format->Range = wxS( "~" ) + m_units;
|
||||
|
@ -57,7 +57,7 @@ void SPICE_VALUE_FORMAT::FromString( const wxString& aString )
|
||||
|
||||
wxString SPICE_VALUE_FORMAT::ToString() const
|
||||
{
|
||||
return wxString::Format( wxS( "%d%s" ), alg::clamp( 0, Precision, 9 ), Range );
|
||||
return wxString::Format( wxS( "%d%s" ), std::clamp( Precision, 0, 9 ), Range );
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,7 +171,7 @@ private:
|
||||
m_step += aForward ? 1 : -1;
|
||||
|
||||
// clamp to allowed values
|
||||
m_step = alg::clamp( 0, m_step, getMaxStep() );
|
||||
m_step = std::clamp( m_step, 0, getMaxStep() );
|
||||
}
|
||||
|
||||
///< Has the geometry changed such that a client should redraw?
|
||||
|
@ -201,12 +201,6 @@ bool signbit( T v )
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
T clamp( T min, T value, T max )
|
||||
{
|
||||
return std::max( min, std::min( value, max ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the length of the longest common subset of values between two containers.
|
||||
*/
|
||||
|
@ -223,7 +223,7 @@ void DIALOG_DRC::OnActivateDlg( wxActivateEvent& aEvent )
|
||||
|
||||
bool DIALOG_DRC::updateUI()
|
||||
{
|
||||
double cur = alg::clamp( 0.0, (double) m_progress.load() / m_maxProgress, 1.0 );
|
||||
double cur = std::clamp( (double) m_progress.load() / m_maxProgress, 0.0, 1.0 );
|
||||
|
||||
int newValue = KiROUND( cur * 1000.0 );
|
||||
m_gauge->SetValue( newValue );
|
||||
|
@ -277,7 +277,7 @@ FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::New( KIWAY* aKiway, wxWindow*
|
||||
panel->GetGAL()->SetGridVisibility( gridCfg.show );
|
||||
|
||||
//Bounds checking cannot include number of elements as an index!
|
||||
int gridIdx = alg::clamp( 0, gridCfg.last_size_idx, (int) gridCfg.grids.size() - 1 );
|
||||
int gridIdx = std::clamp( gridCfg.last_size_idx, 0, (int) gridCfg.grids.size() - 1 );
|
||||
double gridSizeX = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILS,
|
||||
gridCfg.grids[gridIdx].x );
|
||||
double gridSizeY = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILS,
|
||||
|
@ -450,7 +450,7 @@ void PAD::SetRoundRectCornerRadius( PCB_LAYER_ID aLayer, double aRadius )
|
||||
|
||||
void PAD::SetRoundRectRadiusRatio( PCB_LAYER_ID aLayer, double aRadiusScale )
|
||||
{
|
||||
m_padStack.SetRoundRectRadiusRatio( alg::clamp( 0.0, aRadiusScale, 0.5 ), aLayer );
|
||||
m_padStack.SetRoundRectRadiusRatio( std::clamp( aRadiusScale, 0.0, 0.5 ), aLayer );
|
||||
|
||||
SetDirty();
|
||||
}
|
||||
@ -458,14 +458,14 @@ void PAD::SetRoundRectRadiusRatio( PCB_LAYER_ID aLayer, double aRadiusScale )
|
||||
|
||||
void PAD::SetFrontRoundRectRadiusRatio( double aRadiusScale )
|
||||
{
|
||||
m_padStack.SetRoundRectRadiusRatio( alg::clamp( 0.0, aRadiusScale, 0.5 ), F_Cu );
|
||||
m_padStack.SetRoundRectRadiusRatio( std::clamp( aRadiusScale, 0.0, 0.5 ), F_Cu );
|
||||
SetDirty();
|
||||
}
|
||||
|
||||
|
||||
void PAD::SetChamferRectRatio( PCB_LAYER_ID aLayer, double aChamferScale )
|
||||
{
|
||||
m_padStack.SetChamferRatio( alg::clamp( 0.0, aChamferScale, 0.5 ), aLayer );
|
||||
m_padStack.SetChamferRatio( std::clamp( aChamferScale, 0.0, 0.5 ), aLayer );
|
||||
|
||||
SetDirty();
|
||||
}
|
||||
|
@ -3991,7 +3991,7 @@ PCB_DIMENSION_BASE* PCB_IO_KICAD_SEXPR_PARSER::parseDIMENSION( BOARD_ITEM* aPare
|
||||
if( dim->Type() == PCB_DIM_ORTHOGONAL_T )
|
||||
{
|
||||
PCB_DIM_ORTHOGONAL* ortho = static_cast<PCB_DIM_ORTHOGONAL*>( dim.get() );
|
||||
orientation = alg::clamp( 0, orientation, 1 );
|
||||
orientation = std::clamp( orientation, 0, 1 );
|
||||
ortho->SetOrientation( static_cast<PCB_DIM_ORTHOGONAL::DIR>( orientation ) );
|
||||
}
|
||||
|
||||
@ -4031,7 +4031,7 @@ PCB_DIMENSION_BASE* PCB_IO_KICAD_SEXPR_PARSER::parseDIMENSION( BOARD_ITEM* aPare
|
||||
case T_units_format:
|
||||
{
|
||||
int format = parseInt( "dimension units format" );
|
||||
format = alg::clamp( 0, format, 3 );
|
||||
format = std::clamp( format, 0, 3 );
|
||||
dim->SetUnitsFormat( static_cast<DIM_UNITS_FORMAT>( format ) );
|
||||
NeedRIGHT();
|
||||
break;
|
||||
@ -4118,7 +4118,7 @@ PCB_DIMENSION_BASE* PCB_IO_KICAD_SEXPR_PARSER::parseDIMENSION( BOARD_ITEM* aPare
|
||||
PCB_DIM_LEADER* leader = static_cast<PCB_DIM_LEADER*>( dim.get() );
|
||||
|
||||
int textFrame = parseInt( "text frame mode" );
|
||||
textFrame = alg::clamp( 0, textFrame, 3 );
|
||||
textFrame = std::clamp( textFrame, 0, 3 );
|
||||
leader->SetTextBorder( static_cast<DIM_TEXT_BORDER>( textFrame ));
|
||||
NeedRIGHT();
|
||||
break;
|
||||
|
@ -2027,7 +2027,7 @@ void ZONE_FILLER::buildThermalSpokes( const ZONE* aZone, PCB_LAYER_ID aLayer,
|
||||
// and the algo to count the actual number of spokes can fail
|
||||
int spoke_max_allowed_w = std::min( pad->GetSize( aLayer ).x, pad->GetSize( aLayer ).y );
|
||||
|
||||
spoke_w = alg::clamp( constraint.Value().Min(), spoke_w, constraint.Value().Max() );
|
||||
spoke_w = std::clamp( spoke_w, constraint.Value().Min(), constraint.Value().Max() );
|
||||
|
||||
// ensure the spoke width is smaller than the pad minor size
|
||||
spoke_w = std::min( spoke_w, spoke_max_allowed_w );
|
||||
|
Loading…
Reference in New Issue
Block a user