Loading...
Searching...
No Matches
qwt_polar_fitter.cpp
/******************************************************************************
* QwtPolar Widget Library
* Copyright (C) 2008 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_polar_fitter.h"
#include <qpolygon.h>
#include <qpainterpath.h>
class QwtPolarFitter::PrivateData
{
public:
PrivateData()
: stepCount( 5 )
{
}
int stepCount;
};
QwtPolarFitter::QwtPolarFitter( int stepCount )
: QwtCurveFitter( QwtPolarFitter::Polygon )
{
m_data = new PrivateData;
m_data->stepCount = stepCount;
}
QwtPolarFitter::~QwtPolarFitter()
{
delete m_data;
}
void QwtPolarFitter::setStepCount( int stepCount )
{
m_data->stepCount = qMax( stepCount, 0 );
}
int QwtPolarFitter::stepCount() const
{
return m_data->stepCount;
}
QPolygonF QwtPolarFitter::fitCurve( const QPolygonF& points ) const
{
if ( m_data->stepCount <= 0 || points.size() <= 1 )
return points;
QPolygonF fittedPoints;
int numPoints = points.size() + ( points.size() - 1 ) * m_data->stepCount;
fittedPoints.resize( numPoints );
int index = 0;
fittedPoints[index++] = points[0];
for ( int i = 1; i < points.size(); i++ )
{
const QPointF& p1 = points[i - 1];
const QPointF& p2 = points[i];
const double dx = ( p2.x() - p1.x() ) / m_data->stepCount;
const double dy = ( p2.y() - p1.y() ) / m_data->stepCount;
for ( int j = 1; j <= m_data->stepCount; j++ )
{
const double x = p1.x() + j * dx;
const double y = p1.y() + j * dy;
fittedPoints[index++] = QPointF( x, y );
}
}
fittedPoints.resize( index );
return fittedPoints;
}
QPainterPath QwtPolarFitter::fitCurvePath( const QPolygonF& points ) const
{
QPainterPath path;
path.addPolygon( fitCurve( points ) );
return path;
}
QwtCurveFitter
Abstract base class for a curve fitter.
Definition qwt_curve_fitter.h:22
QwtPolarFitter
A simple curve fitter for polar points.
Definition qwt_polar_fitter.h:25
QwtPolarFitter::stepCount
int stepCount() const
Definition qwt_polar_fitter.cpp:60
QwtPolarFitter::setStepCount
void setStepCount(int size)
Definition qwt_polar_fitter.cpp:51
QwtPolarFitter::fitCurvePath
virtual QPainterPath fitCurvePath(const QPolygonF &) const override
Definition qwt_polar_fitter.cpp:110
QwtPolarFitter::QwtPolarFitter
QwtPolarFitter(int stepCount=5)
Definition qwt_polar_fitter.cpp:30
QwtPolarFitter::fitCurve
virtual QPolygonF fitCurve(const QPolygonF &) const override
Definition qwt_polar_fitter.cpp:72
QwtPolarFitter::~QwtPolarFitter
virtual ~QwtPolarFitter()
Destructor.
Definition qwt_polar_fitter.cpp:38