/** * \return Approximation for ellipse arc length. */ double REllipse::getLength() const { double a1, a2; if (isFullEllipse()) { a1 = 0.0; a2 = 2*M_PI; } else { a1 = RMath::getNormalizedAngle(startParam); a2 = RMath::getNormalizedAngle(endParam); } if (reversed) { double t = a1; a1 = a2; a2 = t; } if (RMath::fuzzyCompare(a2, 0.0)) { a2 = 2*M_PI; } if (fabs(a1-a2)<RS::AngleTolerance) { return 0.0; } if (a1<a2) { if (a1<M_PI && a2<=M_PI) { return getSimpsonLength(a1, a2); } if (a1<M_PI && a2>M_PI) { return getSimpsonLength(a1, M_PI) + getSimpsonLength(M_PI, a2); } if (a1>=M_PI && a2>M_PI) { return getSimpsonLength(a1, a2); } } else { if (a1>M_PI && a2<M_PI) { return getSimpsonLength(a1, 2*M_PI) + getSimpsonLength(0, a2); } if (a1>M_PI && a2>M_PI) { return getSimpsonLength(a1, 2*M_PI) + getSimpsonLength(0, M_PI) + getSimpsonLength(M_PI, a2); } if (a1<M_PI && a2<M_PI) { return getSimpsonLength(a1, M_PI) + getSimpsonLength(M_PI, 2*M_PI) + getSimpsonLength(0, a2); } } return RNANDOUBLE; }
void REllipse::print(QDebug dbg) const { dbg.nospace() << "REllipse("; RShape::print(dbg); dbg.nospace() << ", startPoint: " << getStartPoint() << ", endPoint: " << getEndPoint() << ", center: " << getCenter() << ", majorPoint: " << getMajorPoint() << ", majorRadius: " << getMajorRadius() << ", minorRadius: " << getMinorRadius() << ", ratio: " << getRatio() << ", startAngle: " << RMath::rad2deg(getStartParam()) << ", endAngle: " << RMath::rad2deg(getEndParam()) << ", full: " << isFullEllipse() << ", clockwise: " << isReversed() << ")"; }
bool REllipseData::moveReferencePoint(const RVector& referencePoint, const RVector& targetPoint) { RVector startPoint = getStartPoint(); RVector endPoint = getEndPoint(); if (!isFullEllipse()) { if (referencePoint.equalsFuzzy(startPoint)) { moveStartPoint(targetPoint, true); return true; } if (referencePoint.equalsFuzzy(endPoint)) { moveEndPoint(targetPoint, true); return true; } } if (referencePoint.equalsFuzzy(center+majorPoint)) { double minorRadius = getMinorRadius(); majorPoint = targetPoint-center; setRatio(minorRadius / getMajorRadius()); return true; } if (referencePoint.equalsFuzzy(center-majorPoint)) { double minorRadius = getMinorRadius(); majorPoint = -(targetPoint-center); setRatio(minorRadius / getMajorRadius()); return true; } if (referencePoint.equalsFuzzy(center+getMinorPoint())) { setMinorPoint(targetPoint-center); return true; } if (referencePoint.equalsFuzzy(center-getMinorPoint())) { setMinorPoint(-(targetPoint-center)); return true; } if (referencePoint.equalsFuzzy(center)) { center = targetPoint; return true; } return false; }
QList<RRefPoint> REllipseData::getReferencePoints(RS::ProjectionRenderingHint hint) const { Q_UNUSED(hint) QList<RRefPoint> ret; ret.append(RRefPoint(center, RRefPoint::Center)); ret.append(RRefPoint(center+majorPoint, RRefPoint::Secondary)); ret.append(RRefPoint(center-majorPoint, RRefPoint::Secondary)); ret.append(RRefPoint(center+getMinorPoint(), RRefPoint::Secondary)); ret.append(RRefPoint(center-getMinorPoint(), RRefPoint::Secondary)); ret.append(RRefPoint::toRefPointList(getFoci(), RRefPoint::Secondary)); if (!isFullEllipse()) { ret.append(RRefPoint(getStartPoint(), RRefPoint::Start)); ret.append(RRefPoint(getEndPoint(), RRefPoint::End)); } return ret; }
QList<RVector> REllipseData::getReferencePoints( RS::ProjectionRenderingHint hint) const { Q_UNUSED(hint) QList<RVector> ret; ret.append(center); ret.append(center+majorPoint); ret.append(center-majorPoint); ret.append(center+getMinorPoint()); ret.append(center-getMinorPoint()); ret.append(getFoci()); if (!isFullEllipse()) { ret.append(getStartPoint()); ret.append(getEndPoint()); } return ret; }
bool REllipse::mirror(const RLine& axis) { RVector mp = center + majorPoint; RVector sp = getStartPoint(); RVector ep = getEndPoint(); center.mirror(axis); mp.mirror(axis); majorPoint = mp - center; if (!isFullEllipse()) { reversed = (!reversed); sp.mirror(axis); setStartParam(getParamTo(sp)); ep.mirror(axis); setEndParam(getParamTo(ep)); } return true; }