source: ntrip/trunk/BNC/qwtpolar/qwt_polar_fitter.cpp@ 9550

Last change on this file since 9550 was 4272, checked in by mervart, 12 years ago
File size: 2.3 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * QwtPolar Widget Library
3 * Copyright (C) 2008 Uwe Rathmann
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the Qwt License, Version 1.0
7 *****************************************************************************/
8
9#include "qwt_polar_fitter.h"
10
11class QwtPolarFitter::PrivateData
12{
13public:
14 PrivateData():
15 stepCount( 5 )
16 {
17 }
18
19 int stepCount;
20};
21
22/*!
23 Constructor
24
25 \param stepCount Number of points, that will be inserted between 2 points
26 \sa setStepCount()
27*/
28QwtPolarFitter::QwtPolarFitter( int stepCount )
29{
30 d_data = new PrivateData;
31 d_data->stepCount = stepCount;
32}
33
34//! Destructor
35QwtPolarFitter::~QwtPolarFitter()
36{
37 delete d_data;
38}
39
40/*!
41 Assign the number of points, that will be inserted between 2 points
42 The default value is 5.
43
44 \param stepCount Number of steps
45
46 \sa stepCount()
47*/
48void QwtPolarFitter::setStepCount( int stepCount )
49{
50 d_data->stepCount = qMax( stepCount, 0 );
51}
52
53/*!
54 \return Number of points, that will be inserted between 2 points
55 \sa setStepCount()
56*/
57int QwtPolarFitter::stepCount() const
58{
59 return d_data->stepCount;
60}
61
62/*!
63 Insert stepCount() number of additional points between 2 elements
64 of points.
65
66 \param points Array of points
67 \return Array of points including the additional points
68*/
69QPolygonF QwtPolarFitter::fitCurve( const QPolygonF &points ) const
70{
71 if ( d_data->stepCount <= 0 || points.size() <= 1 )
72 return points;
73
74 QPolygonF fittedPoints;
75
76 int numPoints = points.size() + ( points.size() - 1 ) * d_data->stepCount;
77
78 fittedPoints.resize( numPoints );
79
80 int index = 0;
81 fittedPoints[index++] = points[0];
82 for ( int i = 1; i < points.size(); i++ )
83 {
84 const QPointF &p1 = points[i-1];
85 const QPointF &p2 = points[i];
86
87 const double dx = ( p2.x() - p1.x() ) / d_data->stepCount;
88 const double dy = ( p2.y() - p1.y() ) / d_data->stepCount;
89 for ( int j = 1; j <= d_data->stepCount; j++ )
90 {
91 const double x = p1.x() + j * dx;
92 const double y = p1.y() + j * dy;
93
94 fittedPoints[index++] = QPointF( x, y );
95 }
96 }
97 fittedPoints.resize( index );
98
99 return fittedPoints;
100}
Note: See TracBrowser for help on using the repository browser.