code simplified

This commit is contained in:
Uwe Rathmann 2024-05-31 13:40:22 +02:00
parent bc066c8103
commit a849a8d9f4
1 changed files with 30 additions and 29 deletions

View File

@ -25,6 +25,29 @@ static inline QskVertex::ColoredLine* qskAllocateColoredLines(
return reinterpret_cast< QskVertex::ColoredLine* >( geometry.vertexData() ); return reinterpret_cast< QskVertex::ColoredLine* >( geometry.vertexData() );
} }
static inline QPointF qskThicknessVector( qreal w, qreal h, qreal cos, qreal sin )
{
// normalized normal vector of the tangent at a specific angle
if ( qFuzzyIsNull( cos ) )
return { cos, sin };
const qreal m = ( w / h ) * ( sin / cos );
/*
We know: x² + y² = 1.0 and y = m * x;
=> x² + m² * x² = 1.0;
=> x = 1.0 / sqrt( 1.0 + m² );
*/
const qreal t = 1.0 / qSqrt( 1.0 + m * m );
const auto x = ( cos >= 0.0 ) ? t : -t;
const auto y = m * x;
return { x, y };
}
namespace namespace
{ {
class AngleIterator class AngleIterator
@ -100,7 +123,7 @@ namespace
private: private:
int arcLineCount( qreal radians = 2.0 * M_PI ) const; int arcLineCount( qreal radians = 2.0 * M_PI ) const;
QLineF fillLineAt( qreal x, qreal y, qreal sin, qreal cos ) const; QLineF fillLineAt( qreal w, qreal h, qreal sin, qreal cos ) const;
const QRectF& m_rect; const QRectF& m_rect;
const QskArcMetrics& m_metrics; const QskArcMetrics& m_metrics;
@ -204,13 +227,10 @@ namespace
return l - lines; return l - lines;
} }
inline qreal sqr( qreal x )
{
return x * x;
}
QLineF Stroker::fillLineAt( qreal w, qreal h, qreal cos, qreal sin ) const QLineF Stroker::fillLineAt( qreal w, qreal h, qreal cos, qreal sin ) const
{ {
const auto off = 0.5 * m_metrics.thickness() * qskThicknessVector( w, h, cos, sin );
const auto x = w * cos; const auto x = w * cos;
const auto y = h * sin; const auto y = h * sin;
@ -219,30 +239,11 @@ namespace
normal vector of the tangent at the ellipse point. normal vector of the tangent at the ellipse point.
*/ */
const auto t = 0.5 * m_metrics.thickness(); const auto x1 = x + off.x();
const auto y1 = y + off.y();
if ( qFuzzyIsNull( sin ) ) const auto x2 = x - off.x();
{ const auto y2 = y - off.y();
const qreal dx = cos * t;
return QLineF( x + dx, y, x - dx, y );
}
else if ( qFuzzyIsNull( cos ) )
{
const qreal dy = sin * t;
return QLineF( x, y + dy, x, y - dy );
}
const qreal m = qSqrt( w * w - x * x ) * ( w / h ) / x;
const auto dt = t * qSqrt( ( 1.0 / ( 1.0 + m * m ) ) );
const qreal dx = ( x >= 0 ) ? dt : -dt;
const qreal dy = m * ( ( y >= 0 ) ? dx : -dx );
const auto x1 = x + dx;
const auto y1 = y + dy;
const auto x2 = x - dx;
const auto y2 = y - dy;
return QLineF( x1, y1, x2, y2 ); return QLineF( x1, y1, x2, y2 );
} }