valentina/geometry/varc.cpp

99 lines
2.2 KiB
C++
Raw Normal View History

2013-08-05 10:37:56 +02:00
#define _USE_MATH_DEFINES
#include <cmath>
#include "varc.h"
#include <QDebug>
VArc::VArc (){
f1 = 0;
2013-08-06 09:56:09 +02:00
formulaF1 = QString();
2013-08-05 10:37:56 +02:00
f2 = 0;
2013-08-06 09:56:09 +02:00
formulaF2 = QString();
2013-08-05 10:37:56 +02:00
radius = 0;
2013-08-06 09:56:09 +02:00
formulaRadius = QString();
2013-08-05 10:37:56 +02:00
center = 0;
points = 0;
}
2013-08-06 09:56:09 +02:00
VArc::VArc (const QMap<qint64, VPointF> *points, qint64 center, qreal radius, QString formulaRadius,
qreal f1, QString formulaF1, qreal f2, QString formulaF2 ){
2013-08-05 10:37:56 +02:00
this->points = points;
2013-08-06 09:56:09 +02:00
this->f1 = f1;
this->formulaF1 = formulaF1;
this->f2 = f2;
this->formulaF2 = formulaF2;
this->radius = radius;
this->formulaRadius = formulaRadius;
this->center = center;
2013-08-05 10:37:56 +02:00
}
2013-08-06 09:56:09 +02:00
qreal VArc::GetF1() const{
2013-08-05 10:37:56 +02:00
return f1;
}
2013-08-06 09:56:09 +02:00
QString VArc::GetFormulaF1() const{
return formulaF1;
}
qreal VArc::GetF2() const{
2013-08-05 10:37:56 +02:00
return f2;
}
2013-08-06 09:56:09 +02:00
QString VArc::GetFormulaF2() const{
return formulaF2;
}
2013-08-05 10:37:56 +02:00
qreal VArc::GetLength () const{
2013-08-06 09:56:09 +02:00
return M_PI * radius/180 * (f2-f1);
2013-08-05 10:37:56 +02:00
}
2013-08-06 09:56:09 +02:00
qreal VArc::GetRadius() const{
2013-08-05 10:37:56 +02:00
return radius;
}
2013-08-06 09:56:09 +02:00
QString VArc::GetFormulaRadius() const{
return formulaRadius;
}
2013-08-05 10:37:56 +02:00
qint64 VArc::GetCenter() const{
return center;
}
QPointF VArc::GetCenterPoint() const{
if(points->contains(center)){
return points->value(center);
} else {
qCritical()<<"Не можу знайти id = "<<center<<" в таблиці.";
throw"Не можу знайти точку за id.";
}
return QPointF();
}
QPointF VArc::GetP1() const{
QPointF p1 ( GetCenterPoint().x () + radius, GetCenterPoint().y () );
QLineF centerP1(GetCenterPoint(), p1);
centerP1.setAngle(f1);
2013-08-06 09:56:09 +02:00
return centerP1.p2();
}
QPointF VArc::GetP2 () const{
2013-08-05 10:37:56 +02:00
QPointF p2 ( GetCenterPoint().x () + radius, GetCenterPoint().y () );
QLineF centerP2(GetCenterPoint(), p2);
centerP2.setAngle(f2);
2013-08-06 09:56:09 +02:00
return centerP2.p2();
2013-08-05 10:37:56 +02:00
}
2013-08-06 09:56:09 +02:00
const QMap<qint64, VPointF> *VArc::GetDataPoints() const{
return points;
2013-08-05 10:37:56 +02:00
}
QPainterPath VArc::GetPath() const{
QPainterPath Path;
2013-08-06 09:56:09 +02:00
QPointF center = GetCenterPoint();
QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2);
Path.moveTo(GetP1());
qreal angle = QLineF(center, GetP1()).angleTo(QLineF(center, GetP2()));
Path.arcTo(rect, GetF1(), angle);
2013-08-05 10:37:56 +02:00
return Path;
}