From 8ac49d0bab94588ccbf3c6761cf45e3660c2e00c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 2 Aug 2023 16:26:17 +0100 Subject: [PATCH] General cleanup, coding standards, removal of dead code, etc. --- common/widgets/mathplot.cpp | 468 +---------------------------- eeschema/sim/sim_plot_tab.cpp | 6 +- include/widgets/mathplot.h | 545 ++++------------------------------ 3 files changed, 83 insertions(+), 936 deletions(-) diff --git a/common/widgets/mathplot.cpp b/common/widgets/mathplot.cpp index b097b27c2e..553809b51a 100644 --- a/common/widgets/mathplot.cpp +++ b/common/widgets/mathplot.cpp @@ -320,7 +320,7 @@ void mpFX::Plot( wxDC& dc, mpWindow& w ) iy = w.y2p( GetY( w.p2x( i ) ) ); // Draw the point only if you can draw outside margins or if the point is inside margins - if( (iy >= minYpx) && (iy <= maxYpx) ) + if( iy >= minYpx && iy <= maxYpx ) dc.DrawLine( i, iy, i, iy ); } } @@ -335,8 +335,7 @@ void mpFX::Plot( wxDC& dc, mpWindow& w ) if( (m_flags & mpALIGNMASK) == mpALIGN_RIGHT ) tx = (w.GetScrX() - tx) - w.GetMarginRight() - 8; else if( (m_flags & mpALIGNMASK) == mpALIGN_CENTER ) - tx = ( (w.GetScrX() - w.GetMarginRight() - w.GetMarginLeft() - tx) / 2 ) + - w.GetMarginLeft(); + tx = ( (w.GetScrX() - w.GetMarginRight() - w.GetMarginLeft() - tx) / 2 ) + w.GetMarginLeft(); else tx = w.GetMarginLeft() + 8; @@ -400,8 +399,7 @@ void mpFY::Plot( wxDC& dc, mpWindow& w ) if( (m_flags & mpALIGNMASK) == mpALIGN_TOP ) ty = w.GetMarginTop() + 8; else if( (m_flags & mpALIGNMASK) == mpALIGN_CENTER ) - ty = ( (w.GetScrY() - w.GetMarginTop() - w.GetMarginBottom() - ty) / 2 ) + - w.GetMarginTop(); + ty = ( ( w.GetScrY() - w.GetMarginTop() - w.GetMarginBottom() - ty) / 2 ) + w.GetMarginTop(); else ty = w.GetScrY() - 8 - ty - w.GetMarginBottom(); @@ -656,64 +654,6 @@ void mpFXY::Plot( wxDC& dc, mpWindow& w ) } -// ----------------------------------------------------------------------------- -// mpProfile implementation -// ----------------------------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS( mpProfile, mpLayer ) - -mpProfile::mpProfile( const wxString& name, int flags ) -{ - SetName( name ); - m_flags = flags; - m_type = mpLAYER_PLOT; -} - - -void mpProfile::Plot( wxDC& dc, mpWindow& w ) -{ - if( m_visible ) - { - dc.SetPen( m_pen ); - - wxCoord startPx = w.GetMarginLeft(); - wxCoord endPx = w.GetScrX() - w.GetMarginRight(); - wxCoord minYpx = w.GetMarginTop(); - wxCoord maxYpx = w.GetScrY() - w.GetMarginBottom(); - - // Plot profile linking subsequent point of the profile, instead of mpFY, which plots simple points. - for( wxCoord i = startPx; i < endPx; ++i ) - { - wxCoord c0 = w.y2p( GetY( w.p2x( i ) ) ); - wxCoord c1 = w.y2p( GetY( w.p2x( i + 1 ) ) ); - - c0 = (c0 <= maxYpx) ? ( (c0 >= minYpx) ? c0 : minYpx ) : maxYpx; - c1 = (c1 <= maxYpx) ? ( (c1 >= minYpx) ? c1 : minYpx ) : maxYpx; - - dc.DrawLine( i, c0, i + 1, c1 ); - } - - if( !m_name.IsEmpty() ) - { - dc.SetFont( m_font ); - - wxCoord tx, ty; - dc.GetTextExtent( m_name, &tx, &ty ); - - if( (m_flags & mpALIGNMASK) == mpALIGN_RIGHT ) - tx = (w.GetScrX() - tx) - w.GetMarginRight() - 8; - else if( (m_flags & mpALIGNMASK) == mpALIGN_CENTER ) - tx = ( (w.GetScrX() - w.GetMarginRight() - w.GetMarginLeft() - tx) / 2 ) + - w.GetMarginLeft(); - else - tx = w.GetMarginLeft() + 8; - - dc.DrawText( m_name, tx, w.y2p( GetY( w.p2x( tx ) ) ) ); - } - } -} - - // ----------------------------------------------------------------------------- // mpLayer implementations - furniture (scales, ...) // ----------------------------------------------------------------------------- @@ -749,9 +689,7 @@ void mpScaleX::recalculateTicks( wxDC& dc, mpWindow& w ) } } - double v = floor( minVvis / bestStep ) * bestStep; - double zeroOffset = 100000000.0; while( v < maxVvis ) @@ -771,9 +709,7 @@ void mpScaleX::recalculateTicks( wxDC& dc, mpWindow& w ) } for( double t : m_tickValues ) - { m_tickLabels.emplace_back( t ); - } updateTickLabels( dc, w ); } @@ -805,7 +741,7 @@ void mpScaleBase::computeLabelExtents( wxDC& dc, mpWindow& w ) m_maxLabelHeight = 0; m_maxLabelWidth = 0; - for( const TickLabel& tickLabel : m_tickLabels ) + for( const TICK_LABEL& tickLabel : m_tickLabels ) { int tx, ty; const wxString s = tickLabel.label; @@ -1129,7 +1065,7 @@ void mpScaleXBase::Plot( wxDC& dc, mpWindow& w ) // Actually draw labels, taking care of not overlapping them, and distributing them // regularly - for( const TickLabel& tickLabel : m_tickLabels ) + for( const TICK_LABEL& tickLabel : m_tickLabels ) { if( !tickLabel.visible ) continue; @@ -1281,7 +1217,7 @@ void mpScaleY::Plot( wxDC& dc, mpWindow& w ) } } - for( const TickLabel& tickLabel : m_tickLabels ) + for( const TICK_LABEL& tickLabel : m_tickLabels ) { double py = TransformToPlot( tickLabel.pos ); const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() ); @@ -1740,22 +1676,6 @@ void mpWindow::Fit( double xMin, double xMax, double yMin, double yMax, } -// Patch ngpaton -void mpWindow::DoZoomInXCalc( const int staticXpixel ) -{ - // Preserve the position of the clicked point: - double staticX = p2x( staticXpixel ); - - // Zoom in: - m_scaleX = m_scaleX * zoomIncrementalFactor; - // Adjust the new m_posx - m_posX = staticX - (staticXpixel / m_scaleX); - // Adjust desired - m_desiredXmin = m_posX; - m_desiredXmax = m_posX + ( m_scrX - (m_marginLeft + m_marginRight) ) / m_scaleX; -} - - void mpWindow::AdjustLimitedView() { if( !m_enableLimitedView ) @@ -1933,13 +1853,6 @@ void mpWindow::ZoomOut( const wxPoint& centerPoint, double zoomFactor ) } -void mpWindow::ZoomInX() -{ - m_scaleX = m_scaleX * zoomIncrementalFactor; - UpdateAll(); -} - - void mpWindow::ZoomRect( wxPoint p0, wxPoint p1 ) { // Compute the 2 corners in graph coordinates: @@ -2140,8 +2053,6 @@ void mpWindow::UpdateAll() } -// End patch ngpaton - void mpWindow::SetScaleX( double scaleX ) { if( scaleX != 0 ) @@ -2262,9 +2173,7 @@ mpInfoLayer* mpWindow::IsInsideInfoLayer( wxPoint& point ) void mpWindow::SetLayerVisible( const wxString& name, bool viewable ) { - mpLayer* lx = GetLayerByName( name ); - - if( lx ) + if( mpLayer* lx = GetLayerByName( name ) ) { lx->SetVisible( viewable ); UpdateAll(); @@ -2274,17 +2183,16 @@ void mpWindow::SetLayerVisible( const wxString& name, bool viewable ) bool mpWindow::IsLayerVisible( const wxString& name ) const { - const mpLayer* lx = GetLayerByName( name ); + if( const mpLayer* lx = GetLayerByName( name ) ) + return lx->IsVisible(); - return lx ? lx->IsVisible() : false; + return false; } void mpWindow::SetLayerVisible( const unsigned int position, bool viewable ) { - mpLayer* lx = GetLayer( position ); - - if( lx ) + if( mpLayer* lx = GetLayer( position ) ) { lx->SetVisible( viewable ); UpdateAll(); @@ -2294,9 +2202,10 @@ void mpWindow::SetLayerVisible( const unsigned int position, bool viewable ) bool mpWindow::IsLayerVisible( unsigned int position ) const { - mpLayer* lx = GetLayer( position ); + if( const mpLayer* lx = GetLayer( position ) ) + return lx->IsVisible(); - return (lx) ? lx->IsVisible() : false; + return false; } @@ -2390,21 +2299,12 @@ double mpScaleXLog::TransformFromPlot( double xplot ) const } -#if 0 -mpFSemiLogXVector::mpFSemiLogXVector( wxString name, int flags ) : - mpFXYVector( name, flags ) -{ -} - - -IMPLEMENT_DYNAMIC_CLASS( mpFSemiLogXVector, mpFXYVector ) -#endif // 0 - void mpFXYVector::Rewind() { m_index = 0; } + size_t mpFXYVector::GetCount() const { return m_xs.size(); @@ -2479,344 +2379,6 @@ void mpFXYVector::SetData( const std::vector& xs, const std::vector= 0 && offsetx <= 100 ) - m_offsetx = offsetx; - else - m_offsetx = 5; - - if( offsety >= 0 && offsety <= 100 ) - m_offsety = offsety; - else - m_offsety = 50; - - m_type = mpLAYER_INFO; -} - - -/** mpText Layer plot handler. - * This implementation will plot the text adjusted to the visible area. - */ - -void mpText::Plot( wxDC& dc, mpWindow& w ) -{ - if( m_visible ) - { - dc.SetPen( m_pen ); - dc.SetFont( m_font ); - - wxCoord tw = 0, th = 0; - dc.GetTextExtent( GetName(), &tw, &th ); - - int px = m_offsetx * ( w.GetScrX() - w.GetMarginLeft() - w.GetMarginRight() ) / 100; - int py = m_offsety * ( w.GetScrY() - w.GetMarginTop() - w.GetMarginBottom() ) / 100; - dc.DrawText( GetName(), px, py ); - } -} - - -// ----------------------------------------------------------------------------- -// mpMovableObject - provided by Jose Luis Blanco -// ----------------------------------------------------------------------------- -void mpMovableObject::TranslatePoint( double x, double y, double& out_x, double& out_y ) -{ - double ccos = cos( m_reference_phi ); // Avoid computing cos/sin twice. - double csin = sin( m_reference_phi ); - - out_x = m_reference_x + ccos * x - csin * y; - out_y = m_reference_y + csin * x + ccos * y; -} - - -// This method updates the buffers m_trans_shape_xs/ys, and the precomputed bounding box. -void mpMovableObject::ShapeUpdated() -{ - // Just in case... - if( m_shape_xs.size() != m_shape_ys.size() ) - { - } - else - { - double ccos = cos( m_reference_phi ); // Avoid computing cos/sin twice. - double csin = sin( m_reference_phi ); - - m_trans_shape_xs.resize( m_shape_xs.size() ); - m_trans_shape_ys.resize( m_shape_xs.size() ); - - std::vector::iterator itXi, itXo; - std::vector::iterator itYi, itYo; - - m_bbox_min_x = 1e300; - m_bbox_max_x = -1e300; - m_bbox_min_y = 1e300; - m_bbox_max_y = -1e300; - - for( itXo = m_trans_shape_xs.begin(), - itYo = m_trans_shape_ys.begin(), itXi = m_shape_xs.begin(), itYi = m_shape_ys.begin(); - itXo!=m_trans_shape_xs.end(); itXo++, itYo++, itXi++, itYi++ ) - { - *itXo = m_reference_x + ccos * (*itXi) - csin * (*itYi); - *itYo = m_reference_y + csin * (*itXi) + ccos * (*itYi); - - // Keep BBox: - if( *itXo < m_bbox_min_x ) - m_bbox_min_x = *itXo; - - if( *itXo > m_bbox_max_x ) - m_bbox_max_x = *itXo; - - if( *itYo < m_bbox_min_y ) - m_bbox_min_y = *itYo; - - if( *itYo > m_bbox_max_y ) - m_bbox_max_y = *itYo; - } - } -} - - -void mpMovableObject::Plot( wxDC& dc, mpWindow& w ) -{ - if( m_visible ) - { - dc.SetPen( m_pen ); - - - std::vector::iterator itX = m_trans_shape_xs.begin(); - std::vector::iterator itY = m_trans_shape_ys.begin(); - - if( !m_continuous ) - { - // for some reason DrawPoint does not use the current pen, - // so we use DrawLine for fat pens - if( m_pen.GetWidth() <= 1 ) - { - while( itX!=m_trans_shape_xs.end() ) - { - dc.DrawPoint( w.x2p( *(itX++) ), w.y2p( *(itY++) ) ); - } - } - else - { - while( itX!=m_trans_shape_xs.end() ) - { - wxCoord cx = w.x2p( *(itX++) ); - wxCoord cy = w.y2p( *(itY++) ); - dc.DrawLine( cx, cy, cx, cy ); - } - } - } - else - { - wxCoord cx0 = 0, cy0 = 0; - bool first = true; - - while( itX != m_trans_shape_xs.end() ) - { - wxCoord cx = w.x2p( *(itX++) ); - wxCoord cy = w.y2p( *(itY++) ); - - if( first ) - { - first = false; - cx0 = cx; cy0 = cy; - } - - dc.DrawLine( cx0, cy0, cx, cy ); - cx0 = cx; cy0 = cy; - } - } - - if( !m_name.IsEmpty() && m_showName ) - { - dc.SetFont( m_font ); - - wxCoord tx, ty; - dc.GetTextExtent( m_name, &tx, &ty ); - - if( HasBBox() ) - { - wxCoord sx = (wxCoord) ( ( m_bbox_max_x - w.GetPosX() ) * w.GetScaleX() ); - wxCoord sy = (wxCoord) ( (w.GetPosY() - m_bbox_max_y ) * w.GetScaleY() ); - - tx = sx - tx - 8; - ty = sy - 8 - ty; - } - else - { - const int sx = w.GetScrX() >> 1; - const int sy = w.GetScrY() >> 1; - - if( (m_flags & mpALIGNMASK) == mpALIGN_NE ) - { - tx = sx - tx - 8; - ty = -sy + 8; - } - else if( (m_flags & mpALIGNMASK) == mpALIGN_NW ) - { - tx = -sx + 8; - ty = -sy + 8; - } - else if( (m_flags & mpALIGNMASK) == mpALIGN_SW ) - { - tx = -sx + 8; - ty = sy - 8 - ty; - } - else - { - tx = sx - tx - 8; - ty = sy - 8 - ty; - } - } - - dc.DrawText( m_name, tx, ty ); - } - } -} - - -// ----------------------------------------------------------------------------- -// mpCovarianceEllipse - provided by Jose Luis Blanco -// ----------------------------------------------------------------------------- - -// Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes. -void mpCovarianceEllipse::RecalculateShape() -{ - m_shape_xs.clear(); - m_shape_ys.clear(); - - // Preliminary checks: - if( m_quantiles < 0 ) - return; - - if( m_cov_00 < 0 ) - return; - - if( m_cov_11 < 0 ) - return; - - m_shape_xs.resize( m_segments, 0 ); - m_shape_ys.resize( m_segments, 0 ); - - // Compute the two eigenvalues of the covariance: - // ------------------------------------------------- - double b = -m_cov_00 - m_cov_11; - double c = m_cov_00 * m_cov_11 - m_cov_01 * m_cov_01; - - double D = b * b - 4 * c; - - if( D < 0 ) - return; - - double eigenVal0 = 0.5 * ( -b + sqrt( D ) ); - double eigenVal1 = 0.5 * ( -b - sqrt( D ) ); - - // Compute the two corresponding eigenvectors: - // ------------------------------------------------- - double eigenVec0_x, eigenVec0_y; - double eigenVec1_x, eigenVec1_y; - - if( fabs( eigenVal0 - m_cov_00 ) > 1e-6 ) - { - double k1x = m_cov_01 / ( eigenVal0 - m_cov_00 ); - eigenVec0_y = 1; - eigenVec0_x = eigenVec0_y * k1x; - } - else - { - double k1y = m_cov_01 / ( eigenVal0 - m_cov_11 ); - eigenVec0_x = 1; - eigenVec0_y = eigenVec0_x * k1y; - } - - if( fabs( eigenVal1 - m_cov_00 ) > 1e-6 ) - { - double k2x = m_cov_01 / ( eigenVal1 - m_cov_00 ); - eigenVec1_y = 1; - eigenVec1_x = eigenVec1_y * k2x; - } - else - { - double k2y = m_cov_01 / ( eigenVal1 - m_cov_11 ); - eigenVec1_x = 1; - eigenVec1_y = eigenVec1_x * k2y; - } - - // Normalize the eigenvectors: - double len = sqrt( eigenVec0_x * eigenVec0_x + eigenVec0_y * eigenVec0_y ); - eigenVec0_x /= len; // It *CANNOT* be zero - eigenVec0_y /= len; - - len = sqrt( eigenVec1_x * eigenVec1_x + eigenVec1_y * eigenVec1_y ); - eigenVec1_x /= len; // It *CANNOT* be zero - eigenVec1_y /= len; - - - // Take the sqrt of the eigenvalues (required for the ellipse scale): - eigenVal0 = sqrt( eigenVal0 ); - eigenVal1 = sqrt( eigenVal1 ); - - // Compute the 2x2 matrix M = diag(eigVal) * (~eigVec) (each eigen vector is a row): - double M_00 = eigenVec0_x * eigenVal0; - double M_01 = eigenVec0_y * eigenVal0; - - double M_10 = eigenVec1_x * eigenVal1; - double M_11 = eigenVec1_y * eigenVal1; - - // The points of the 2D ellipse: - double ang; - double Aang = 6.283185308 / (m_segments - 1); - int i; - - for( i = 0, ang = 0; i < m_segments; i++, ang += Aang ) - { - double ccos = cos( ang ); - double csin = sin( ang ); - - m_shape_xs[i] = m_quantiles * (ccos * M_00 + csin * M_10 ); - m_shape_ys[i] = m_quantiles * (ccos * M_01 + csin * M_11 ); - } // end for points on ellipse - - ShapeUpdated(); -} - - -// ----------------------------------------------------------------------------- -// mpPolygon - provided by Jose Luis Blanco -// ----------------------------------------------------------------------------- -void mpPolygon::setPoints( const std::vector& points_xs, - const std::vector& points_ys, bool closedShape ) -{ - if( points_xs.size() == points_ys.size() ) - { - m_shape_xs = points_xs; - m_shape_ys = points_ys; - - if( closedShape && !points_xs.empty() ) - { - m_shape_xs.push_back( points_xs[0] ); - m_shape_ys.push_back( points_ys[0] ); - } - - ShapeUpdated(); - } -} - - void mpFXY::SetScale( mpScaleBase* scaleX, mpScaleBase* scaleY ) { m_scaleX = scaleX; diff --git a/eeschema/sim/sim_plot_tab.cpp b/eeschema/sim/sim_plot_tab.cpp index 9a8f3dc3b1..824757ebab 100644 --- a/eeschema/sim/sim_plot_tab.cpp +++ b/eeschema/sim/sim_plot_tab.cpp @@ -157,14 +157,14 @@ private: double sf = pow( 10.0, power ); - for( mpScaleBase::TickLabel& l : T_PARENT::m_tickLabels ) + for( mpScaleBase::TICK_LABEL& l : T_PARENT::m_tickLabels ) digits = std::max( digits, countDecimalDigits( l.pos / sf, MAX_DIGITS ) ); do { for( size_t ii = 0; ii < T_PARENT::m_tickLabels.size(); ++ii ) { - mpScaleBase::TickLabel& l = T_PARENT::m_tickLabels[ii]; + mpScaleBase::TICK_LABEL& l = T_PARENT::m_tickLabels[ii]; l.label = formatFloat( l.pos / sf, digits ) + suffix; l.visible = true; @@ -226,7 +226,7 @@ private: int power; int constexpr MAX_DIGITS = 3; - for( mpScaleBase::TickLabel& l : T_PARENT::m_tickLabels ) + for( mpScaleBase::TICK_LABEL& l : T_PARENT::m_tickLabels ) { getSISuffix( l.pos, m_unit, power, suffix ); double sf = pow( 10.0, power ); diff --git a/include/widgets/mathplot.h b/include/widgets/mathplot.h index ab2864b16e..caa7523e2a 100644 --- a/include/widgets/mathplot.h +++ b/include/widgets/mathplot.h @@ -110,7 +110,6 @@ class WXDLLIMPEXP_MATHPLOT mpFXYVector; class WXDLLIMPEXP_MATHPLOT mpScaleX; class WXDLLIMPEXP_MATHPLOT mpScaleY; class WXDLLIMPEXP_MATHPLOT mpWindow; -class WXDLLIMPEXP_MATHPLOT mpText; class WXDLLIMPEXP_MATHPLOT mpPrintout; /** Command IDs used by mpWindow */ @@ -302,7 +301,7 @@ public: /** Set layer brush * @param brush brush, will be copied to internal class member */ - void SetBrush( wxBrush brush ) { m_brush = brush; }; + void SetBrush( const wxBrush& brush ) { m_brush = brush; }; protected: @@ -377,15 +376,13 @@ public: * @return The rectangle size */ wxSize GetSize() const; - /** Returns the current rectangle coordinates. - * @return The info layer rectangle */ - const wxRect& GetRectangle() const { return m_dim; }; - protected: - wxRect m_dim; // !< The bounding rectangle of the box. It may be resized dynamically by the Plot method. - wxPoint m_reference; // !< Holds the reference point for movements - wxBrush m_brush; // !< The brush to be used for the background - int m_winX, m_winY; // !< Holds the mpWindow size. Used to rescale position when window is resized. + wxRect m_dim; // !< The bounding rectangle of the box. It may be resized dynamically + // by the Plot method. + wxPoint m_reference; // !< Holds the reference point for movements + wxBrush m_brush; // !< The brush to be used for the background + int m_winX; // !< Holds the mpWindow size. Used to rescale position when window is + int m_winY; // resized. DECLARE_DYNAMIC_CLASS( mpInfoLayer ) }; @@ -411,7 +408,7 @@ public: /** Plot method. * @param dc the device content where to plot * @param w the window to plot - * @sa mpLayer::Plot */ + */ virtual void Plot( wxDC& dc, mpWindow& w ) override; protected: @@ -492,8 +489,8 @@ public: virtual double GetY( double x ) const = 0; /** Layer plot handler. - * This implementation will plot the function in the visible area and - * put a label according to the alignment specified. + * This implementation will plot the function in the visible area and put a label according + * to the alignment specified. */ virtual void Plot( wxDC& dc, mpWindow& w ) override; @@ -505,8 +502,8 @@ protected: /** Abstract base class providing plot and labeling functionality for functions F:Y->X. * Override mpFY::GetX to implement a function. - * Optionally implement a constructor and pass a name (label) and a label alignment - * to the constructor mpFY::mpFY. If the layer name is empty, no label will be plotted. + * Optionally implement a constructor and pass a name (label) and a label alignment to the + * constructor mpFY::mpFY. If the layer name is empty, no label will be plotted. */ class WXDLLIMPEXP_MATHPLOT mpFY : public mpLayer { @@ -524,8 +521,8 @@ public: virtual double GetX( double y ) const = 0; /** Layer plot handler. - * This implementation will plot the function in the visible area and - * put a label according to the alignment specified. + * This implementation will plot the function in the visible area and put a label according + * to the alignment specified. */ virtual void Plot( wxDC& dc, mpWindow& w ) override; @@ -565,8 +562,8 @@ public: virtual size_t GetCount() const = 0; /** Layer plot handler. - * This implementation will plot the locus in the visible area and - * put a label according to the alignment specified. + * This implementation will plot the locus in the visible area and put a label according to + * the alignment specified. */ virtual void Plot( wxDC& dc, mpWindow& w ) override; @@ -597,39 +594,6 @@ protected: DECLARE_DYNAMIC_CLASS( mpFXY ) }; -/** Abstract base class providing plot and labeling functionality for functions F:Y->X. - * Override mpProfile::GetX to implement a function. - * This class is similar to mpFY, but the Plot method is different. The plot is in fact represented by lines instead of points, which gives best rendering of rapidly-varying functions, and in general, data which are not so close one to another. - * Optionally implement a constructor and pass a name (label) and a label alignment - * to the constructor mpProfile::mpProfile. If the layer name is empty, no label will be plotted. - */ -class WXDLLIMPEXP_MATHPLOT mpProfile : public mpLayer -{ -public: - /** @param name Label - * @param flags Label alignment, pass one of #mpALIGN_BOTTOM, #mpALIGN_CENTER, #mpALIGN_TOP. - */ - mpProfile( const wxString& name = wxEmptyString, int flags = mpALIGN_TOP ); - - /** Get function value for argument. - * Override this function in your implementation. - * @param x Argument - * @return Function value - */ - virtual double GetY( double x ) const = 0; - - /** Layer plot handler. - * This implementation will plot the function in the visible area and - * put a label according to the alignment specified. - */ - virtual void Plot( wxDC& dc, mpWindow& w ) override; - -protected: - int m_flags; // !< Holds label alignment - - DECLARE_DYNAMIC_CLASS( mpProfile ) -}; - /*@}*/ // ----------------------------------------------------------------------------- @@ -640,9 +604,8 @@ protected: * @{*/ /** Plot layer implementing a x-scale ruler. - * The ruler is fixed at Y=0 in the coordinate system. A label is plotted at - * the bottom-right hand of the ruler. The scale numbering automatically - * adjusts to view and zoom factor. + * The ruler is fixed at Y=0 in the coordinate system. A label is plotted at the bottom-right + * hand of the ruler. The scale numbering automatically adjusts to view and zoom factor. */ @@ -674,10 +637,6 @@ public: */ bool GetTicks() const { return m_ticks; }; - - // virtual double X2p( mpWindow &w, double x ) = 0; - // virtual double P2x( mpWindow &w, double x ) = 0; - void GetDataRange( double& minV, double& maxV ) const { minV = m_minV; @@ -746,9 +705,9 @@ public: virtual double TransformToPlot( double x ) const { return 0.0; }; virtual double TransformFromPlot( double xplot ) const { return 0.0; }; - struct TickLabel + struct TICK_LABEL { - TickLabel( double pos_ = 0.0, const wxString& label_ = wxT( "" ) ) : + TICK_LABEL( double pos_ = 0.0, const wxString& label_ = wxT( "" ) ) : pos( pos_ ), label( label_ ), visible( true ) @@ -761,32 +720,31 @@ public: protected: - void updateTickLabels( wxDC& dc, mpWindow& w ); - void computeLabelExtents( wxDC& dc, mpWindow& w ); + void updateTickLabels( wxDC& dc, mpWindow& w ); + void computeLabelExtents( wxDC& dc, mpWindow& w ); // virtual int getLabelDecimalDigits(int maxDigits) const; virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) {}; virtual void recalculateTicks( wxDC& dc, mpWindow& w ) {}; - virtual const wxString formatLabel( double value, int nDigits ) { return wxT( "" ); } virtual void formatLabels() {}; protected: - std::vector m_tickValues; - std::vector m_tickLabels; + std::vector m_tickValues; + std::vector m_tickLabels; - double m_offset, m_scale; - double m_absVisibleMaxV; - int m_flags; // !< Flag for axis alignment - int m_nameFlags; - bool m_ticks; // !< Flag to toggle between ticks or grid - double m_minV, m_maxV; - bool m_rangeSet; - bool m_axisLocked; - double m_axisMin; - double m_axisMax; - int m_maxLabelHeight; - int m_maxLabelWidth; + double m_offset, m_scale; + double m_absVisibleMaxV; + int m_flags; // !< Flag for axis alignment + int m_nameFlags; + bool m_ticks; // !< Flag to toggle between ticks or grid + double m_minV, m_maxV; + bool m_rangeSet; + bool m_axisLocked; + double m_axisMin; + double m_axisMax; + int m_maxLabelHeight; + int m_maxLabelWidth; }; class WXDLLIMPEXP_MATHPLOT mpScaleXBase : public mpScaleBase @@ -795,23 +753,19 @@ public: /** Full constructor. * @param name Label to plot by the ruler * @param flags Set the position of the scale with respect to the window. - * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for drawing the grid. + * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for + * drawing the grid. * @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */ - mpScaleXBase( const wxString& name = wxT("X"), int flags = mpALIGN_CENTER, - bool ticks = true, unsigned int type = mpX_NORMAL ); + mpScaleXBase( const wxString& name = wxT( "X" ), int flags = mpALIGN_CENTER, bool ticks = true, + unsigned int type = mpX_NORMAL ); virtual ~mpScaleXBase() {}; virtual bool IsHorizontal() const override { return true; } - /** Layer plot handler. - * This implementation will plot the ruler adjusted to the visible area. */ virtual void Plot( wxDC& dc, mpWindow& w ) override; virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override; - // unsigned int m_labelType; //!< Select labels mode: mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds - // wxString m_labelFormat; //!< Format string used to print labels - DECLARE_DYNAMIC_CLASS( mpScaleXBase ) }; @@ -822,24 +776,19 @@ public: /** Full constructor. * @param name Label to plot by the ruler * @param flags Set the position of the scale with respect to the window. - * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for drawing the grid. - * @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */ - mpScaleX( const wxString& name = wxT("X"), int flags = mpALIGN_CENTER, - bool ticks = true, unsigned int type = mpX_NORMAL ); + * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for + * drawing the grid. + * @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. + */ + mpScaleX( const wxString& name = wxT( "X" ), int flags = mpALIGN_CENTER, bool ticks = true, + unsigned int type = mpX_NORMAL ); - /** Layer plot handler. - * This implementation will plot the ruler adjusted to the visible area. */ - // virtual void Plot(wxDC & dc, mpWindow & w); - - // virtual double X2p( mpWindow &w, double x ); - // virtual double P2x( mpWindow &w, double x ); virtual double TransformToPlot( double x ) const override; virtual double TransformFromPlot( double xplot ) const override; protected: virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override; - DECLARE_DYNAMIC_CLASS( mpScaleX ) }; @@ -850,33 +799,19 @@ public: /** Full constructor. * @param name Label to plot by the ruler * @param flags Set the position of the scale with respect to the window. - * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for drawing the grid. + * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for + * drawing the grid. * @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */ - mpScaleXLog( const wxString& name = wxT("log(X)"), int flags = mpALIGN_CENTER, + mpScaleXLog( const wxString& name = wxT( "log(X)" ), int flags = mpALIGN_CENTER, bool ticks = true, unsigned int type = mpX_NORMAL ); virtual double TransformToPlot( double x ) const override; virtual double TransformFromPlot( double xplot ) const override; - /** Layer plot handler. - * This implementation will plot the ruler adjusted to the visible area. - */ - // virtual double X2p( mpWindow &w, double x ); - // virtual double P2x( mpWindow &w, double x ); - protected: void recalculateTicks( wxDC& dc, mpWindow& w ) override; - // int tickCount() const; - // int labelCount() const; - // const wxString getLabel( int n ); - // double getTickPos( int n ); - // double getLabelPos( int n ); - - void computeLabelExtents( wxDC& dc, mpWindow& w ); - - DECLARE_DYNAMIC_CLASS( mpScaleXLog ) }; @@ -893,7 +828,8 @@ class WXDLLIMPEXP_MATHPLOT mpScaleY : public mpScaleBase public: /** @param name Label to plot by the ruler * @param flags Set position of the scale respect to the window. - * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for drawing the grid + * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for + * drawing the grid */ mpScaleY( const wxString& name = wxT( "Y" ), int flags = mpALIGN_CENTER, bool ticks = true ); @@ -910,46 +846,20 @@ public: */ virtual bool HasBBox() const override { return false; } - /** Set Y axis alignment. - * @param align alignment (choose between mpALIGN_BORDER_LEFT, mpALIGN_LEFT, mpALIGN_CENTER, mpALIGN_RIGHT, mpALIGN_BORDER_RIGHT) */ - void SetAlign( int align ) { m_flags = align; }; - - /** Set Y axis ticks or grid - * @param ticks true to plot axis ticks, false to plot grid. */ - void SetTicks( bool ticks ) { m_ticks = ticks; }; - - /** Get Y axis ticks or grid - * @return true if plot is drawing axis ticks, false if the grid is active. */ - bool GetTicks() const { return m_ticks; }; - virtual double TransformToPlot( double x ) const override; virtual double TransformFromPlot( double xplot ) const override; - - void SetMasterScale( mpScaleY* masterScale ) - { - m_masterScale = masterScale; - } + void SetMasterScale( mpScaleY* masterScale ) { m_masterScale = masterScale; } protected: virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override; virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override; - // virtual int tickCount() const; - // virtual int labelCount() const; - // virtual const wxString getLabel( int n ); - // virtual double getTickPos( int n ); - // virtual double getLabelPos( int n ); - void computeLabelExtents( wxDC& dc, mpWindow& w ); void computeSlaveTicks( mpWindow& w ); mpScaleY* m_masterScale; - - // double m_minV, m_maxV; - - int m_flags; // !< Flag for axis alignment - bool m_ticks; // !< Flag to toggle between ticks or grid - // wxString m_labelFormat; //!< Format string used to print labels + int m_flags; // !< Flag for axis alignment + bool m_ticks; // !< Flag to toggle between ticks or grid DECLARE_DYNAMIC_CLASS( mpScaleY ) }; @@ -1008,7 +918,8 @@ public: /** Add a plot layer to the canvas. * @param layer Pointer to layer. The mpLayer object will get under control of mpWindow, * i.e. it will be delete'd on mpWindow destruction - * @param refreshDisplay States whether to refresh the display (UpdateAll) after adding the layer. + * @param refreshDisplay States whether to refresh the display (UpdateAll) after adding the + * layer. * @retval true Success * @retval false Failure due to out of memory. */ @@ -1016,8 +927,10 @@ public: /** Remove a plot layer from the canvas. * @param layer Pointer to layer. The mpLayer object will be destructed using delete. - * @param alsoDeleteObject If set to true, the mpLayer object will be also "deleted", not just removed from the internal list. - * @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the layer. + * @param alsoDeleteObject If set to true, the mpLayer object will be also "deleted", not just + * removed from the internal list. + * @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the + * layer. * @return true if layer is deleted correctly * * N.B. Only the layer reference in the mpWindow is deleted, the layer object still exists! @@ -1025,8 +938,10 @@ public: bool DelLayer( mpLayer* layer, bool alsoDeleteObject = false, bool refreshDisplay = true ); /** Remove all layers from the plot. - * @param alsoDeleteObject If set to true, the mpLayer objects will be also "deleted", not just removed from the internal list. - * @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the layers. + * @param alsoDeleteObject If set to true, the mpLayer objects will be also "deleted", not + * just removed from the internal list. + * @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the + * layers. */ void DelAllLayers( bool alsoDeleteObject, bool refreshDisplay = true ); @@ -1131,22 +1046,18 @@ public: /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale. * @sa p2y,x2p,y2p */ - // double p2x(wxCoord pixelCoordX, bool drawOutside = true ); // { return m_posX + pixelCoordX/m_scaleX; } inline double p2x( wxCoord pixelCoordX ) { return m_posX + pixelCoordX / m_scaleX; } /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale. * @sa p2x,x2p,y2p */ - // double p2y(wxCoord pixelCoordY, bool drawOutside = true ); //{ return m_posY - pixelCoordY/m_scaleY; } inline double p2y( wxCoord pixelCoordY ) { return m_posY - pixelCoordY / m_scaleY; } /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale. * @sa p2x,p2y,y2p */ - // wxCoord x2p(double x, bool drawOutside = true); // { return (wxCoord) ( (x-m_posX) * m_scaleX); } inline wxCoord x2p( double x ) { return (wxCoord) ( (x - m_posX) * m_scaleX ); } /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale. * @sa p2x,p2y,x2p */ - // wxCoord y2p(double y, bool drawOutside = true); // { return (wxCoord) ( (m_posY-y) * m_scaleY); } inline wxCoord y2p( double y ) { return (wxCoord) ( (m_posY - y) * m_scaleY ); } @@ -1191,18 +1102,6 @@ public: void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition ); void ZoomOut( const wxPoint& centerPoint, double zoomFactor ); - /** Zoom in current view along X and refresh display */ - void ZoomInX(); - - /** Zoom out current view along X and refresh display */ - void ZoomOutX(); - - /** Zoom in current view along Y and refresh display */ - void ZoomInY(); - - /** Zoom out current view along Y and refresh display */ - void ZoomOutY(); - /** Zoom view fitting given coordinates to the window (p0 and p1 do not need to be in any specific order) */ void ZoomRect( wxPoint p0, wxPoint p1 ); @@ -1314,8 +1213,7 @@ public: * @param bgColour Background colour * @param drawColour The colour used to draw all elements in foreground, axes excluded * @param axesColour The colour used to draw axes (but not their labels) */ - void SetColourTheme( const wxColour& bgColour, - const wxColour& drawColour, + void SetColourTheme( const wxColour& bgColour, const wxColour& drawColour, const wxColour& axesColour ); /** Get axes draw colour @@ -1337,7 +1235,6 @@ protected: void OnPaint( wxPaintEvent& event ); // !< Paint handler, will plot all attached layers void OnSize( wxSizeEvent& event ); // !< Size handler, will update scroll bar sizes - // void OnScroll2 (wxScrollWinEvent &event); //!< Scroll handler, will move canvas void OnShowPopupMenu( wxMouseEvent& event ); // !< Mouse handler, will show context menu void OnMouseMiddleDown( wxMouseEvent& event ); // !< Mouse handler, for detecting when the user @@ -1352,11 +1249,6 @@ protected: void OnMouseLeftDown( wxMouseEvent& event ); // !< Mouse left click (for rect zoom) void OnMouseLeftRelease( wxMouseEvent& event ); // !< Mouse left click (for rect zoom) - void DoZoomInXCalc( const int staticXpixel ); - void DoZoomInYCalc( const int staticYpixel ); - void DoZoomOutXCalc( const int staticXpixel ); - void DoZoomOutYCalc( const int staticYpixel ); - bool CheckXLimits( double& desiredMax, double& desiredMin ) const { return !( m_enableLimitedView @@ -1525,311 +1417,4 @@ protected: }; -#if 0 - -class WXDLLIMPEXP_MATHPLOT mpFSemiLogXVector : public mpFXYVector -{ -public: - /** @param name Label - * @param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE. - */ - mpFSemiLogXVector( wxString name = wxEmptyString, int flags = mpALIGN_NE ); - - virtual ~mpFSemiLogXVector() {} - - /** Changes the internal data: the set of points to draw. - * Both vectors MUST be of the same length. This method DOES NOT refresh the mpWindow; do it manually. - * @sa Clear - */ - - DECLARE_DYNAMIC_CLASS( mpFSemiLogXVector ) -}; -#endif - -// ----------------------------------------------------------------------------- -// mpText - provided by Val Greene -// ----------------------------------------------------------------------------- - -/** Plot layer implementing a text string. - * The text is plotted using a percentage system 0-100%, so the actual - * coordinates for the location are not required, and the text stays - * on the plot regardless of the other layers location and scaling - * factors. - */ -class WXDLLIMPEXP_MATHPLOT mpText : public mpLayer -{ -public: - /** @param name text to be drawn in the plot - * @param offsetx holds offset for the X location in percentage (0-100) - * @param offsety holds offset for the Y location in percentage (0-100) */ - mpText( const wxString& name = wxT("Title"), int offsetx = 5, int offsety = 50 ); - - /** Text Layer plot handler. - * This implementation will plot text adjusted to the visible area. */ - virtual void Plot( wxDC& dc, mpWindow& w ) override; - - /** mpText should not be used for scaling decisions. */ - virtual bool HasBBox() const override { return false; } - -protected: - int m_offsetx; // !< Holds offset for X in percentage - int m_offsety; // !< Holds offset for Y in percentage - - DECLARE_DYNAMIC_CLASS( mpText ) -}; - - -// ----------------------------------------------------------------------------- -// mpPrintout - provided by Davide Rondini -// ----------------------------------------------------------------------------- - -/** Printout class used by mpWindow to draw in the objects to be printed. - * The object itself can then used by the default wxWidgets printing system - * to print mppWindow objects. - */ -class WXDLLIMPEXP_MATHPLOT mpPrintout : public wxPrintout -{ -public: - mpPrintout( mpWindow* drawWindow, const wxChar* title = _T("wxMathPlot print output") ); - virtual ~mpPrintout() {}; - - void SetDrawState( bool drawState ) { drawn = drawState; }; - bool OnPrintPage( int page ) override; - bool HasPage( int page ) override; - -private: - bool drawn; - mpWindow* plotWindow; -}; - - -// ----------------------------------------------------------------------------- -// mpMovableObject - provided by Jose Luis Blanco -// ----------------------------------------------------------------------------- -/** This virtual class represents objects that can be moved to an arbitrary 2D location+rotation. - * The current transformation is set through SetCoordinateBase. - * To ease the implementation of descendent classes, mpMovableObject will - * be in charge of Bounding Box computation and layer rendering, assuming that - * the object updates its shape in m_shape_xs & m_shape_ys. - */ -class WXDLLIMPEXP_MATHPLOT mpMovableObject : public mpLayer -{ -public: - /** Default constructor (sets location and rotation to (0,0,0)) - */ - mpMovableObject() : - m_flags( 0 ), - m_reference_x( 0 ), - m_reference_y( 0 ), - m_reference_phi( 0 ), - m_shape_xs( 0 ), - m_shape_ys( 0 ), - m_bbox_min_x( 0 ), - m_bbox_max_x( 0 ), - m_bbox_min_y( 0 ), - m_bbox_max_y( 0 ) - { - m_type = mpLAYER_PLOT; - } - - virtual ~mpMovableObject() {}; - - /** Get the current coordinate transformation. - */ - void GetCoordinateBase( double& x, double& y, double& phi ) const - { - x = m_reference_x; - y = m_reference_y; - phi = m_reference_phi; - } - - /** Set the coordinate transformation (phi in radians, 0 means no rotation). - */ - void SetCoordinateBase( double x, double y, double phi = 0 ) - { - m_reference_x = x; - m_reference_y = y; - m_reference_phi = phi; - m_flags = mpALIGN_NE; - ShapeUpdated(); - } - - virtual bool HasBBox() const override { return m_trans_shape_xs.size()!=0; } - - /** Get inclusive left border of bounding box. - */ - virtual double GetMinX() const override { return m_bbox_min_x; } - - /** Get inclusive right border of bounding box. - */ - virtual double GetMaxX() const override { return m_bbox_max_x; } - - /** Get inclusive bottom border of bounding box. - */ - virtual double GetMinY() const override { return m_bbox_min_y; } - - /** Get inclusive top border of bounding box. - */ - virtual double GetMaxY() const override { return m_bbox_max_y; } - - virtual void Plot( wxDC& dc, mpWindow& w ) override; - - /** Set label axis alignment. - * @param align alignment (choose between mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGN_SE - */ - void SetAlign( int align ) { m_flags = align; }; - -protected: - int m_flags; // !< Holds label alignment - - /** The coordinates of the object (orientation "phi" is in radians). - */ - double m_reference_x, m_reference_y, m_reference_phi; - - /** A method for 2D translation and rotation, using the current transformation - * stored in m_reference_x,m_reference_y,m_reference_phi. - */ - void TranslatePoint( double x, double y, double& out_x, double& out_y ); - - /** This contains the object points, in local coordinates - * (to be transformed by the current transformation). - */ - std::vector m_shape_xs, m_shape_ys; - - /** The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh). - * - */ - std::vector m_trans_shape_xs, m_trans_shape_ys; - - /** The precomputed bounding box: - * @sa ShapeUpdated - */ - double m_bbox_min_x, m_bbox_max_x, m_bbox_min_y, m_bbox_max_y; - - /** Must be called by the descendent class after updating the shape (m_shape_xs/ys), - * or when the transformation changes. - * This method updates the buffers m_trans_shape_xs/ys, and the precomputed bounding box. - */ - void ShapeUpdated(); -}; - -// ----------------------------------------------------------------------------- -// mpCovarianceEllipse - provided by Jose Luis Blanco -// ----------------------------------------------------------------------------- -/** A 2D ellipse, described by a 2x2 covariance matrix. - * The relation between the multivariate Gaussian confidence interval and - * the "quantiles" in this class is: - * - 1 : 68.27% confidence interval - * - 2 : 95.45% - * - 3 : 99.73% - * - 4 : 99.994% - * For example, see http://en.wikipedia.org/wiki/Normal_distribution#Standard_deviation_and_confidence_intervals - * - * The ellipse will be always centered at the origin. Use mpMovableObject::SetCoordinateBase to move it. - */ -class WXDLLIMPEXP_MATHPLOT mpCovarianceEllipse : public mpMovableObject -{ -public: - /** Default constructor. - * Initializes to a unity diagonal covariance matrix, a 95% confidence interval (2 sigmas), - * 32 segments, and a continuous plot (m_continuous=true). - */ - mpCovarianceEllipse( double cov_00 = 1, - double cov_11 = 1, - double cov_01 = 0, - double quantiles = 2, - int segments = 32, - const wxString& layerName = wxT("") ) : - m_cov_00( cov_00 ), - m_cov_11( cov_11 ), - m_cov_01( cov_01 ), - m_quantiles( quantiles ), - m_segments( segments ) - { - m_continuous = true; - m_name = layerName; - RecalculateShape(); - m_type = mpLAYER_PLOT; - } - - virtual ~mpCovarianceEllipse() {} - - double GetQuantiles() const { return m_quantiles; } - - /** Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above). - */ - void SetQuantiles( double q ) - { - m_quantiles = q; - RecalculateShape(); - } - - void SetSegments( int segments ) { m_segments = segments; } - int GetSegments() const { return m_segments; } - - /** Returns the elements of the current covariance matrix: - */ - void GetCovarianceMatrix( double& cov_00, double& cov_01, double& cov_11 ) const - { - cov_00 = m_cov_00; - cov_01 = m_cov_01; - cov_11 = m_cov_11; - } - - /** Changes the covariance matrix: - */ - void SetCovarianceMatrix( double cov_00, double cov_01, double cov_11 ) - { - m_cov_00 = cov_00; - m_cov_01 = cov_01; - m_cov_11 = cov_11; - RecalculateShape(); - } - -protected: - /** The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix). - */ - double m_cov_00, m_cov_11, m_cov_01; - double m_quantiles; - - /** The number of line segments that build up the ellipse. - */ - int m_segments; - - /** Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes. - */ - void RecalculateShape(); -}; - -// ----------------------------------------------------------------------------- -// mpPolygon - provided by Jose Luis Blanco -// ----------------------------------------------------------------------------- -/** An arbitrary polygon, descendant of mpMovableObject. - * Use "setPoints" to set the list of N points. This class also can draw non-closed polygons by - * passing the appropriate parameters to "setPoints". To draw a point-cloud, call "SetContinuity(false)". - */ -class WXDLLIMPEXP_MATHPLOT mpPolygon : public mpMovableObject -{ -public: - /** Default constructor. - */ - mpPolygon( const wxString& layerName = wxT("") ) - { - m_continuous = true; - m_name = layerName; - } - - virtual ~mpPolygon() {} - - /** Set the points in the polygon. - * @param points_xs The X coordinates of the points. - * @param points_ys The Y coordinates of the points. - * @param closedShape If set to true, an additional segment will be added from the last to the first point. - */ - void setPoints( const std::vector& points_xs, - const std::vector& points_ys, - bool closedShape = true ); -}; - - #endif // _MP_MATHPLOT_H_