Function tiny_skia_path::stroker::cubic_in_line

source ยท
fn cubic_in_line(cubic: &[Point; 4]) -> bool
Expand description

Given a cubic, determine if all four points are in a line.

Return true if the inner points is close to a line connecting the outermost points.

Find the outermost point by looking for the largest difference in X or Y. Given the indices of the outermost points, and that outer_1 is greater than outer_2, this table shows the index of the smaller of the remaining points:

                  outer_2
              0    1    2    3
  outer_1     ----------------
     0     |  -    2    1    1
     1     |  -    -    0    0
     2     |  -    -    -    0
     3     |  -    -    -    -

If outer_1 == 0 and outer_2 == 1, the smaller of the remaining indices (2 and 3) is 2.

This table can be collapsed to: (1 + (2 >> outer_2)) >> outer_1

Given three indices (outer_1 outer_2 mid_1) from 0..3, the remaining index is:

mid_2 == (outer_1 ^ outer_2 ^ mid_1)