MCPcopy Create free account
hub / github.com/KAlO2/PerfectShow / calcuateDistance

Function calcuateDistance

jni/venus/region_operation.cpp:1458–1484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1456}
1457
1458Vec4f calcuateDistance(Point2f& pivot, const Point2f& left, const Point2f& right, const Point2f& top, const Point2f& bottom)
1459{
1460 assert(left.x < right.x && top.y < bottom.y);
1461 assert(top.y < left.y && left.y < bottom.y && top.y < right.y && right.y < bottom.y);
1462 assert(left.x < top.x && top.x < right.x && left.x < bottom.x && bottom.x < right.x);
1463#if 0
1464 // non-skew version
1465 pivot = Point2f((top.x + bottom.x)/2, (left.y + right.y)/2);
1466 return Vec4f(pivot.x - left.x, right.x - pivot.x, pivot.y - top.y, bottom.y - pivot.y);
1467#else
1468 float denorm = (left.x - right.x)*(top.y - bottom.y) - (left.y - right.y)*(top.x - bottom.x);
1469 assert(std::abs(denorm) > std::numeric_limits<float>::epsilon());
1470
1471 float z = left.x*right.y - left.y*right.x;
1472 float w = top.x*bottom.y - top.y*bottom.x;
1473 float x = z*(top.x - bottom.x) - w*(left.x - right.x);
1474 float y = z*(top.y - bottom.y) - w*(left.y - right.y);
1475 pivot.x = x/denorm;
1476 pivot.y = y/denorm;
1477
1478 x = venus::distance(pivot, left);
1479 y = venus::distance(pivot, right);
1480 z = venus::distance(pivot, top);
1481 w = venus::distance(pivot, bottom);
1482 return Vec4f(x, y, z, w);
1483#endif
1484}
1485
1486} /* namespace venus */

Calls 1

distanceFunction · 0.85

Tested by

no test coverage detected