コード例 #1
0
ファイル: renderer.c プロジェクト: jkoenen/paperbomb
static uint addQuadraticCurvePointsRec(const float2* p0, const float2* p1, const float2* p2)
{
    const float2 points[3u] = { *p0, *p1, *p2 };
    uint addedPointCount=0u;

    float2 linearMidPoint;
    float2_sub(&linearMidPoint,p2,p0);
    float2_addScaled1f(&linearMidPoint,p0,&linearMidPoint,0.5f);

    float2 curveMidPoint;
    evaluateQuadraticCurve(&curveMidPoint,points,0.5f);

    const float threshold=0.5f;
    const float squareThreshold=threshold*threshold;
    if(float2_squareDistance(&linearMidPoint,&curveMidPoint)>squareThreshold)
    {
        // subdivide..
        SYS_TRACE_DEBUG("subd\n");
    }
    else
    {
        if( pushStrokePoint( p2 ) )
        {
            addedPointCount++;
        }
    }
    return addedPointCount;
}
コード例 #2
0
ファイル: renderer.c プロジェクト: jkoenen/paperbomb
static uint addQuadraticCurvePoints(const float2* pPoints,uint stepCount,int addLastPoint)
{
    float x = 0.0f;
    float dx = 1.0f / (float)(stepCount-1u);

    uint addedPointCount = 0u;
    
    float2 point;
    if( !addLastPoint )
    {
        stepCount--;
    }
    const float distanceThreshold=0.01f;
    float2 lastPoint;
    float2 lastNormal;
    for( uint i = 0u; i < stepCount; ++i )
    {
        evaluateQuadraticCurve(&point,pPoints,x);
        if( i == 0 || i == stepCount - 1 || float2_distance(&point,&lastPoint)>distanceThreshold)
        {
            float2 tangent;
            evaluateQuadraticCurveTangent(&tangent,pPoints,x);
            float2 normal;
            float2_perpendicular(&normal,&tangent);
            float2_normalize(&normal);

            if( i > 0 && float2_dot( &normal, &lastNormal ) < 0.0f )
            {
                float2_scale1f( &normal, &normal, -1.0f );
            }

            if( pushStrokePointWithNormal( &point, &normal ) )
            {
                addedPointCount++;
            }
            lastPoint=point;
            lastNormal=normal;
        }

        x += dx;
    }
    return addedPointCount;
}
コード例 #3
0
ファイル: FTContour.cpp プロジェクト: OpenXIP/xip-libraries
FTContour::FTContour( FT_Vector* contour, char* pointTags, unsigned int numberOfPoints)
{
    for( unsigned int pointIndex = 0; pointIndex < numberOfPoints; ++ pointIndex)
    {
        char pointTag = pointTags[pointIndex];
        
        if( pointTag == FT_Curve_Tag_On || numberOfPoints < 2)
        {
            AddPoint( contour[pointIndex].x, contour[pointIndex].y);
            continue;
        }
        
        FTPoint controlPoint( contour[pointIndex]);
        FTPoint previousPoint = ( 0 == pointIndex)
                                ? FTPoint( contour[numberOfPoints - 1])
                                : pointList[pointList.size() - 1];

        FTPoint nextPoint = ( pointIndex == numberOfPoints - 1)
                            ? pointList[0]
                            : FTPoint( contour[pointIndex + 1]);

        if( pointTag == FT_Curve_Tag_Conic)
        {
            char nextPointTag = ( pointIndex == numberOfPoints - 1)
                                ? pointTags[0]
                                : pointTags[pointIndex + 1];
            
            while( nextPointTag == FT_Curve_Tag_Conic)
            {
                nextPoint = ( controlPoint + nextPoint) * 0.5f;

                controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
                controlPoints[1][0] = controlPoint.X();  controlPoints[1][1] = controlPoint.Y();
                controlPoints[2][0] = nextPoint.X();     controlPoints[2][1] = nextPoint.Y();
                
                evaluateQuadraticCurve();
                ++pointIndex;
                
                previousPoint = nextPoint;
                controlPoint = FTPoint( contour[pointIndex]);
                nextPoint = ( pointIndex == numberOfPoints - 1)
                            ? pointList[0]
                            : FTPoint( contour[pointIndex + 1]);
                nextPointTag = ( pointIndex == numberOfPoints - 1)
                               ? pointTags[0]
                               : pointTags[pointIndex + 1];
            }
            
            controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
            controlPoints[1][0] = controlPoint.X();  controlPoints[1][1] = controlPoint.Y();
            controlPoints[2][0] = nextPoint.X();     controlPoints[2][1] = nextPoint.Y();
            
            evaluateQuadraticCurve();
            continue;
        }

        if( pointTag == FT_Curve_Tag_Cubic)
        {
            FTPoint controlPoint2 = nextPoint;
            
            FTPoint nextPoint = ( pointIndex == numberOfPoints - 2)
                                ? pointList[0]
                                : FTPoint( contour[pointIndex + 2]);
            
            controlPoints[0][0] = previousPoint.X(); controlPoints[0][1] = previousPoint.Y();
            controlPoints[1][0] = controlPoint.X();  controlPoints[1][1] = controlPoint.Y();
            controlPoints[2][0] = controlPoint2.X(); controlPoints[2][1] = controlPoint2.Y();
            controlPoints[3][0] = nextPoint.X();     controlPoints[3][1] = nextPoint.Y();
        
            evaluateCubicCurve();
            ++pointIndex;
            continue;
        }
    }
}
コード例 #4
0
ファイル: FTContour.cpp プロジェクト: joaocc/ta3d-git
FTContour::FTContour(FT_Vector* contour, char* tags, unsigned int n)
{
    FTPoint prev, cur(contour[(n - 1) % n]), next(contour[0]);
    FTPoint a, b = next - cur;
    double olddir, dir = atan2((next - cur).Y(), (next - cur).X());
    double angle = 0.0;

    // See http://freetype.sourceforge.net/freetype2/docs/glyphs/glyphs-6.html
    // for a full description of FreeType tags.
    for(unsigned int i = 0; i < n; i++)
    {
        prev = cur;
        cur = next;
        next = FTPoint(contour[(i + 1) % n]);
        olddir = dir;
        dir = atan2((next - cur).Y(), (next - cur).X());

        // Compute our path's new direction.
        double t = dir - olddir;
        if(t < -M_PI) t += 2 * M_PI;
        if(t > M_PI) t -= 2 * M_PI;
        angle += t;

        // Only process point tags we know.
        if(n < 2 || FT_CURVE_TAG(tags[i]) == FT_Curve_Tag_On)
        {
            AddPoint(cur);
        }
        else if(FT_CURVE_TAG(tags[i]) == FT_Curve_Tag_Conic)
        {
            FTPoint prev2 = prev, next2 = next;

            // Previous point is either the real previous point (an "on"
            // point), or the midpoint between the current one and the
            // previous "conic off" point.
            if(FT_CURVE_TAG(tags[(i - 1 + n) % n]) == FT_Curve_Tag_Conic)
            {
                prev2 = (cur + prev) * 0.5;
                AddPoint(prev2);
            }

            // Next point is either the real next point or the midpoint.
            if(FT_CURVE_TAG(tags[(i + 1) % n]) == FT_Curve_Tag_Conic)
            {
                next2 = (cur + next) * 0.5;
            }

            evaluateQuadraticCurve(prev2, cur, next2);
        }
        else if(FT_CURVE_TAG(tags[i]) == FT_Curve_Tag_Cubic
                 && FT_CURVE_TAG(tags[(i + 1) % n]) == FT_Curve_Tag_Cubic)
        {
            evaluateCubicCurve(prev, cur, next,
                               FTPoint(contour[(i + 2) % n]));
        }
    }

    // If final angle is positive (+2PI), it's an anti-clockwise contour,
    // otherwise (-2PI) it's clockwise.
    clockwise = (angle < 0.0);
}