- float acdx = cx-ax, acdy = cy-ay;
- float bddx = dx-bx, bddy = dy-by;
- float d = acdx*bddy - acdy*bddx;
- if( fabsf(d) < 1 ) d = 1;
- sx = (acdx*bddx*by - acdx*bddx*cy + acdx*bddy*cx - acdy*bddx*bx) / d;
- sy = (acdx*bddy*by - acdy*bddx*cy - acdy*bddy*bx + acdy*bddy*cx) / d;
- bclamp(sx, -4095.f, 4095.f);
- bclamp(sy, -4095.f, 4095.f);
-}
-
-static void smooth_pxy(
- float ax, float ay, float bx, float by,
- float cx, float cy, float dx, float dy,
- float &px, float &py)
-{
- float abdx = bx - ax, abdy = by - ay;
- float acdx = cx - ax, acdy = cy - ay;
- float cddx = dx - cx, cddy = dy - cy;
- float d = (2*(abdx*acdy - abdy*acdx - acdx*cddy + acdy*cddx));
- if( fabsf(d) < 1 ) d = 1;
- px = (-abdx*acdx*by + abdx*acdx*cy + 2*abdx*acdy*bx - abdy*acdx*bx - abdy*acdx*cx -
- acdx*bx*cddy - acdx*by*cddx + acdx*cddx*cy - acdx*cddy*cx + 2*acdy*bx*cddx) / d;
- py = (abdx*acdy*by + abdx*acdy*cy - 2*abdy*acdx*by + abdy*acdy*bx - abdy*acdy*cx -
- 2*acdx*by*cddy + acdy*bx*cddy + acdy*by*cddx + acdy*cddx*cy - acdy*cddy*cx) / d;
- bclamp(px, -4095.f, 4095.f);
- bclamp(py, -4095.f, 4095.f);
-}
-static void smooth_qxy(
- float ax, float ay, float bx, float by,
- float cx, float cy, float dx, float dy,
- float &qx, float &qy)
-{
- float abdx = bx - ax, abdy = by - ay;
- float bddx = dx - bx, bddy = dy - by;
- float cddx = dx - cx, cddy = dy - cy;
- float d = (2*(abdx*bddy - abdy*bddx - bddx*cddy + bddy*cddx));
- if( fabsf(d) < 1 ) d = 1;
- qx = (abdx*bddx*by - abdx*bddx*cy + 2*abdx*bddy*cx - abdy*bddx*bx - abdy*bddx*cx -
- bddx*bx*cddy + bddx*by*cddx - bddx*cddx*cy - bddx*cddy*cx + 2*bddy*cddx*cx) / d;
- qy = (abdx*bddy*by + abdx*bddy*cy - 2*abdy*bddx*cy - abdy*bddy*bx + abdy*bddy*cx -
- 2*bddx*cddy*cy - bddy*bx*cddy + bddy*by*cddx + bddy*cddx*cy + bddy*cddy*cx) / d;
- bclamp(qx, -4095.f, 4095.f);
- bclamp(qy, -4095.f, 4095.f);
+//middle of bd reflected around ctr
+// point ctr = b+d/2, dv=c-ctr, a=ctr-dv;
+ float xc = (bx+dx)*.5f, yc = (by+dy)*.5f;
+ float xd = cx - xc, yd = cy - yc;
+ ax = xc - xd; ay = yc - yd;
+}
+static void smooth_dxy(float &dx, float &dy,
+ float ax, float ay, float bx, float by, float cx, float cy)
+{
+//middle of ac reflected around ctr
+// point ctr = a+c/2, dv=c-ctr, d=ctr-dv;
+ float xc = (ax+cx)*.5f, yc = (ay+cy)*.5f;
+ float xd = bx - xc, yd = by - yc;
+ dx = xc - xd; dy = yc - yd;