pub fn iblerp(self, point: Vec2f) -> IBLerpResult {
        let p0mp = self.points.0 - point;
        let p1mp = self.points.1 - point;
        let p0mp3 = self.points.0 - self.points.3;
        let p1mp2 = self.points.1 - self.points.2;

        let a = p0mp.cross(p0mp3);
        let b0 = p0mp.cross(p1mp2);
        let b1 = p1mp.cross(p0mp3);
        let b = (b0 + b1) / 2.0;
        let c = p1mp.cross(p1mp2);

        let calc_st = |s| {
            let den = (1.0 - s) * p0mp3.x + s * p1mp2.x;
            let t = if den == 0.0 {
                // TODO(nicholasbishop): perhaps there's a more
                // efficient way to solve this, the SO post doesn't
                // seem to cover this case
                let rb = self.points.0.lerp(self.points.1, s);
                let rt = self.points.3.lerp(self.points.2, s);
                Line2f::new(rb, rt).closest_parametric_point(point)
            }
            else {
                ((1.0 - s) * (p0mp.x) + s * p1mp.x) / den
            };
            Vec2f::new(s, t)
        };

        let den = a - (2.0 * b) + c;
        if den == 0.0 {
            let m = a - c;
            if m == 0.0 {
                if a == 0.0 {
                    IBLerpResult::ManySolutions
                }
                else {
                    IBLerpResult::NoSolution
                }
            }
            else {
                IBLerpResult::OneSolution(calc_st(a / m))
            }
        }
        else {
            let left = a - b;
            let right = (b.powi(2) - a*c).sqrt();
            let s0 = (left + right) / den;
            let s1 = (left - right) / den;
            IBLerpResult::TwoSolutions(calc_st(s0), calc_st(s1))
        }
    }
/// Inverse bilinear interpolation
///
/// Adapted from stackoverflow.com/questions/808441
Inverse bilinear interpolation
Adapted from stackoverflow.com/questions/808441
Inverse bilinear interpolation Adapted from stackoverflow . com / questions / 808441
pub fn iblerp(self, point: Vec2f) -> IBLerpResult {
        let p0mp = self.points.0 - point;
        let p1mp = self.points.1 - point;
        let p0mp3 = self.points.0 - self.points.3;
        let p1mp2 = self.points.1 - self.points.2;
        let a = p0mp.cross(p0mp3);
        let b0 = p0mp.cross(p1mp2);
        let b1 = p1mp.cross(p0mp3);
        let b = (b0 + b1) / 2.0;
        let c = p1mp.cross(p1mp2);
        let calc_st = |s| {
            let den = (1.0 - s) * p0mp3.x + s * p1mp2.x;
            let t = if den == 0.0 {
                // TODO(nicholasbishop): perhaps there's a more
                // efficient way to solve this, the SO post doesn't
                // seem to cover this case
                let rb = self.points.0.lerp(self.points.1, s);
                let rt = self.points.3.lerp(self.points.2, s);
                Line2f::new(rb, rt).closest_parametric_point(point)
            }
            else {
                ((1.0 - s) * (p0mp.x) + s * p1mp.x) / den
            };
            Vec2f::new(s, t)
        };
        let den = a - (2.0 * b) + c;
        if den == 0.0 {
            let m = a - c;
            if m == 0.0 {
                if a == 0.0 {
                    IBLerpResult::ManySolutions
                }
                else {
                    IBLerpResult::NoSolution
                }
            }
            else {
                IBLerpResult::OneSolution(calc_st(a / m))
            }
        }
        else {
            let left = a - b;
            let right = (b.powi(2) - a*c).sqrt();
            let s0 = (left + right) / den;
            let s1 = (left - right) / den;
            IBLerpResult::TwoSolutions(calc_st(s0), calc_st(s1))
        }
    }
pub fn iblerp ( self , point : Vec2f ) -> IBLerpResult { let p0mp = self . points . 0 - point ; let p1mp = self . points . 1 - point ; let p0mp3 = self . points . 0 - self . points . 3 ; let p1mp2 = self . points . 1 - self . points . 2 ; let a = p0mp . cross ( p0mp3 ) ; let b0 = p0mp . cross ( p1mp2 ) ; let b1 = p1mp . cross ( p0mp3 ) ; let b = ( b0 + b1 ) / 2.0 ; let c = p1mp . cross ( p1mp2 ) ; let calc_st = | s | { let den = ( 1.0 - s ) * p0mp3 . x + s * p1mp2 . x ; let t = if den == 0.0 { // TODO(nicholasbishop): perhaps there's a more // efficient way to solve this, the SO post doesn't // seem to cover this case let rb = self . points . 0 . lerp ( self . points . 1 , s ) ; let rt = self . points . 3 . lerp ( self . points . 2 , s ) ; Line2f :: new ( rb , rt ) . closest_parametric_point ( point ) } else { ( ( 1.0 - s ) * ( p0mp . x ) + s * p1mp . x ) / den } ; Vec2f :: new ( s , t ) } ; let den = a - ( 2.0 * b ) + c ; if den == 0.0 { let m = a - c ; if m == 0.0 { if a == 0.0 { IBLerpResult :: ManySolutions } else { IBLerpResult :: NoSolution } } else { IBLerpResult :: OneSolution ( calc_st ( a / m ) ) } } else { let left = a - b ; let right = ( b . powi ( 2 ) - a * c ) . sqrt ( ) ; let s0 = ( left + right ) / den ; let s1 = ( left - right ) / den ; IBLerpResult :: TwoSolutions ( calc_st ( s0 ) , calc_st ( s1 ) ) } }
Inverse bilinear interpolation
Adapted from stackoverflow.com/questions/808441
Inverse bilinear interpolation Adapted from stackoverflow . com / questions / 808441
self
point
Vec2f
self
point
Vec2f