calc_bezier_bbox

The Gravity PDF calc bezier bbox function.

Description

calc_bezier_bbox( $start, $c ); 

Parameters (2)

0. $start
The start.
1. $c
The c.

Usage

  1. if ( !function_exists( 'calc_bezier_bbox' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'gravity-pdf/vendor/blueliquiddesigns/mpdf/classes/svg.php'; 
  3.  
  4. // The start. 
  5. $start = null; 
  6.  
  7. // The c. 
  8. $c = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = calc_bezier_bbox($start, $c); 
  12.  

Defined (1)

The function is defined in the following location(s).

/vendor/blueliquiddesigns/mpdf/classes/svg.php  
  1. function calc_bezier_bbox($start, $c) 
  2. $P0 = array($start[0], $start[1]); 
  3. $P1 = array($c[0], $c[1]); 
  4. $P2 = array($c[2], $c[3]); 
  5. $P3 = array($c[4], $c[5]); 
  6. $bounds = array(); 
  7. $bounds[0][] = $P0[0]; 
  8. $bounds[1][] = $P0[1]; 
  9. $bounds[0][] = $P3[0]; 
  10. $bounds[1][] = $P3[1]; 
  11. for ($i = 0; $i <= 1; $i++) { 
  12. $b = 6 * $P0[$i] - 12 * $P1[$i] + 6 * $P2[$i]; 
  13. $a = -3 * $P0[$i] + 9 * $P1[$i] - 9 * $P2[$i] + 3 * $P3[$i]; 
  14. $c = 3 * $P1[$i] - 3 * $P0[$i]; 
  15. if ($a == 0) { 
  16. if ($b == 0) { 
  17. continue; 
  18. $t = -$c / $b; 
  19. if ($t > 0 && $t < 1) { 
  20. $bounds[$i][] = (pow((1 - $t), 3) * $P0[$i] + 3 * pow((1 - $t), 2) * $t * $P1[$i] + 3 * (1 - $t) * pow($t, 2) * $P2[$i] + pow($t, 3) * $P3[$i]); 
  21. continue; 
  22. $b2ac = pow($b, 2) - 4 * $c * $a; 
  23. if ($b2ac < 0) { 
  24. continue; 
  25. $t1 = (-$b + sqrt($b2ac)) / (2 * $a); 
  26. if ($t1 > 0 && $t1 < 1) { 
  27. $bounds[$i][] = (pow((1 - $t1), 3) * $P0[$i] + 3 * pow((1 - $t1), 2) * $t1 * $P1[$i] + 3 * (1 - $t1) * pow($t1, 2) * $P2[$i] + pow($t1, 3) * $P3[$i]); 
  28. $t2 = (-$b - sqrt($b2ac)) / (2 * $a); 
  29. if ($t2 > 0 && $t2 < 1) { 
  30. $bounds[$i][] = (pow((1 - $t2), 3) * $P0[$i] + 3 * pow((1 - $t2), 2) * $t2 * $P1[$i] + 3 * (1 - $t2) * pow($t2, 2) * $P2[$i] + pow($t2, 3) * $P3[$i]); 
  31. $x = min($bounds[0]); 
  32. $x2 = max($bounds[0]); 
  33. $y = min($bounds[1]); 
  34. $y2 = max($bounds[1]); 
  35. return array($x, $y, $x2, $y2);