0

link to theory

C and c mean curves with 3 points defined.

S and s mean curves with 2 points defined.

The relevant functions are (monkSVG + monkVG/openVG):

    void OpenVG_SVGHandler::onPathCubic( float x1, float y1, float x2, float y2, float x3, float y3 ) { 
        VGubyte seg = VG_CUBIC_TO | openVGRelative();
        VGfloat data[6];

        data[0] = x1; data[1] = y1;
        data[2] = x2; data[3] = y2;
        data[4] = x3; data[5] = y3;
        vgAppendPathData( _current_group->current_path->path, 1, &seg, data);

    }

    void OpenVG_SVGHandler::onPathSCubic( float x2, float y2, float x3, float y3 ) {
        VGubyte seg = VG_SCUBIC_TO | openVGRelative();
        VGfloat data[4];

        data[0] = x2; data[1] = y2;
        data[2] = x3; data[3] = y3;
        vgAppendPathData( _current_group->current_path->path, 1, &seg, data);

    }

The problem is the second function (with 2 points) result image look likes incorrect. So I want to try to replace it with a function which look likes workable.

I tried to store a point from a previous step but it gives an incorrect result:

float x2 = d_string_to_float( c, &c );
float y2 = d_string_to_float( c, &c );
float x3 = d_string_to_float( c, &c );
float y3 = d_string_to_float( c, &c );
float x1 = 2 * prevX - x2;
float y1 = 2 * prevY - x2;
_handler->onPathCubic(x1, y1, x2, y2, x3, y3);
prevX = x3;
prevY = y3;
user2083364
  • 744
  • 1
  • 7
  • 20

2 Answers2

0

Let's name the variables slightly differently. You have two cubic Bezier curves, one with four points A, B, C, D, and the other with points E, F, G, H.

The SCubic function tries to ensure that D=E and (C+F)/2 = D.

The first time you call onPathCubic, x1 = B, x2 = C, x3 = D. A is previously set. (I only discuss x for conciseness, but you would need x and y).

The second time you call onPathCubic, you need to compute F, and G and H are specified. How can you compute F? Well, F = 2 * D - C.

Let's look at how our letters map to variables in the second call:

D = E = prevX
F = x1
G = x2
H = x3

This is a problem, because you're not storing C, so you don't have enough information to compute F.

tfinniga
  • 6,693
  • 3
  • 32
  • 37
  • Your error and his are the same. The SCubic function according to the SVG documentations and the definitions of a smooth curve is actually the last previous control point point-reflected across the last anchor point. The missing control point is the point that makes the control point from the last curve have a midpoint at the point your last curve ended and next curve started. (It's the point that makes your last anchor point the midpoint between the last control point in the last curve and the missing one). – Tatarize Dec 08 '16 at 08:28
  • 1
    Saying the the last previous control point is reflected across the last anchor point is the same thing as saying (C+F)/2 = D. My response was to say that unless you store C, there's no way you can do that reflection. – tfinniga Dec 12 '16 at 02:31
0

My solution is to write code similar to the same in another library:

link

user2083364
  • 744
  • 1
  • 7
  • 20