Remove cover routines for std::vector.

They just make it harder to see if we're following std::vector's
contract.
This commit is contained in:
Jeff Young 2023-08-02 15:43:53 +01:00
parent 502b91ba6f
commit f897b4bac1
3 changed files with 35 additions and 73 deletions

View File

@ -805,14 +805,14 @@ void mpScaleBase::computeLabelExtents( wxDC& dc, mpWindow& w )
m_maxLabelHeight = 0;
m_maxLabelWidth = 0;
for( int n = 0; n < labelCount(); n++ )
for( const TickLabel& tickLabel : m_tickLabels )
{
int tx, ty;
const wxString s = getLabel( n );
int tx, ty;
const wxString s = tickLabel.label;
dc.GetTextExtent( s, &tx, &ty );
m_maxLabelHeight = std::max( ty, m_maxLabelHeight );
m_maxLabelWidth = std::max( tx, m_maxLabelWidth );
m_maxLabelHeight = std::max( ty, m_maxLabelHeight );
m_maxLabelWidth = std::max( tx, m_maxLabelWidth );
}
}
@ -1080,15 +1080,12 @@ void mpScaleXBase::Plot( wxDC& dc, mpWindow& w )
int labelH = m_maxLabelHeight; // Control labels height to decide where to put axis name (below labels or on top of axis)
// int maxExtent = tc.MaxLabelWidth();
for( int n = 0; n < tickCount(); n++ )
for( double tp : m_tickValues )
{
double tp = getTickPos( n );
double px = TransformToPlot( tp );
double px = TransformToPlot( tp );
const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
if( (p >= startPx) && (p <= endPx) )
if( p >= startPx && p <= endPx )
{
if( m_ticks ) // draw axis ticks
{
@ -1132,21 +1129,18 @@ void mpScaleXBase::Plot( wxDC& dc, mpWindow& w )
// Actually draw labels, taking care of not overlapping them, and distributing them
// regularly
for( int n = 0; n < labelCount(); n++ )
for( const TickLabel& tickLabel : m_tickLabels )
{
double tp = getLabelPos( n );
if( !m_tickLabels[n].visible )
if( !tickLabel.visible )
continue;
double px = TransformToPlot( tp );
double px = TransformToPlot( tickLabel.pos );
const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
if( (p >= startPx) && (p <= endPx) )
{
// Write ticks labels in s string
wxString s = m_tickLabels[n].label;
wxString s = tickLabel.label;
dc.GetTextExtent( s, &tx, &ty );
@ -1246,26 +1240,22 @@ void mpScaleY::Plot( wxDC& dc, mpWindow& w )
// Draw line
dc.DrawLine( orgx, minYpx, orgx, maxYpx );
wxCoord tx, ty;
wxString s;
wxString fmt;
int n = 0;
wxCoord tx, ty;
wxString s;
wxString fmt;
int labelW = 0;
// Before staring cycle, calculate label height
int labelHeight = 0;
s.Printf( fmt, n );
s.Printf( fmt, 0 );
dc.GetTextExtent( s, &tx, &labelHeight );
for( n = 0; n < tickCount(); n++ )
for( double tp : m_tickValues )
{
double tp = getTickPos( n );
double py = TransformToPlot( tp );
double py = TransformToPlot( tp );
const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
if( (p >= minYpx) && (p <= maxYpx) )
if( p >= minYpx && p <= maxYpx )
{
if( m_ticks ) // Draw axis ticks
{
@ -1291,19 +1281,17 @@ void mpScaleY::Plot( wxDC& dc, mpWindow& w )
}
}
for( n = 0; n < labelCount(); n++ )
for( const TickLabel& tickLabel : m_tickLabels )
{
double tp = getLabelPos( n );
double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
double py = TransformToPlot( tickLabel.pos );
const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
if( !m_tickLabels[n].visible )
if( !tickLabel.visible )
continue;
if( (p >= minYpx) && (p <= maxYpx) )
if( p >= minYpx && p <= maxYpx )
{
s = getLabel( n );
s = tickLabel.label;
dc.GetTextExtent( s, &tx, &ty );
if( m_flags == mpALIGN_BORDER_LEFT || m_flags == mpALIGN_RIGHT || m_flags == mpALIGN_FAR_RIGHT )

View File

@ -157,19 +157,19 @@ private:
double sf = pow( 10.0, power );
for( mpScaleBase::TickLabel& l : T_PARENT::TickLabels() )
for( mpScaleBase::TickLabel& l : T_PARENT::m_tickLabels )
digits = std::max( digits, countDecimalDigits( l.pos / sf, MAX_DIGITS ) );
do
{
for( size_t ii = 0; ii < T_PARENT::TickLabels().size(); ++ii )
for( size_t ii = 0; ii < T_PARENT::m_tickLabels.size(); ++ii )
{
mpScaleBase::TickLabel& l = T_PARENT::TickLabels()[ii];
mpScaleBase::TickLabel& l = T_PARENT::m_tickLabels[ii];
l.label = formatFloat( l.pos / sf, digits ) + suffix;
l.visible = true;
if( ii > 0 && l.label == T_PARENT::TickLabels()[ii-1].label )
if( ii > 0 && l.label == T_PARENT::m_tickLabels[ii-1].label )
duplicateLabels = true;
}
}
@ -226,7 +226,7 @@ private:
int power;
int constexpr MAX_DIGITS = 3;
for( mpScaleBase::TickLabel& l : T_PARENT::TickLabels() )
for( mpScaleBase::TickLabel& l : T_PARENT::m_tickLabels )
{
getSISuffix( l.pos, m_unit, power, suffix );
double sf = pow( 10.0, power );

View File

@ -748,18 +748,17 @@ public:
struct TickLabel
{
TickLabel( double pos_ = 0.0, const wxString& label_ = wxT("") ) :
pos( pos_ ), label( label_ ), pixelPos( 0 ), visible( true )
TickLabel( double pos_ = 0.0, const wxString& label_ = wxT( "" ) ) :
pos( pos_ ),
label( label_ ),
visible( true )
{}
double pos;
double pos;
wxString label;
int pixelPos;
bool visible;
bool visible;
};
std::vector<TickLabel>& TickLabels() { return m_tickLabels; };
protected:
void updateTickLabels( wxDC& dc, mpWindow& w );
@ -769,34 +768,9 @@ protected:
virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) {};
virtual void recalculateTicks( wxDC& dc, mpWindow& w ) {};
int tickCount() const
{
return (int) m_tickValues.size();
}
virtual int labelCount() const
{
return (int) m_tickLabels.size();
}
virtual const wxString formatLabel( double value, int nDigits ) { return wxT( "" ); }
virtual void formatLabels() {};
virtual double getTickPos( int n ) const
{
return m_tickValues[n];
}
virtual double getLabelPos( int n ) const
{
return m_tickLabels[n].pos;
}
virtual wxString getLabel( int n ) const
{
return m_tickLabels[n].label;
}
protected:
std::vector<double> m_tickValues;
std::vector<TickLabel> m_tickLabels;