pub(super) fn intersect(
        first_steps: i64,
        first: &((i64, i64), (i64, i64)),
        second_steps: i64,
        second: &((i64, i64), (i64, i64)),
    ) -> Option<i64> {
        let steps = first_steps + second_steps;

        // Assumption 1: either `x` or `y` coords of each lines are equal
        match ((first.0 .0 == first.1 .0), (second.0 .0 == second.1 .0)) {
            // In both lines `x` coords are qual
            (true, true) => {
                let y1 = max(min(first.0 .1, first.1 .1), min(second.0 .1, second.1 .1));
                let y2 = min(max(first.0 .1, first.1 .1), max(second.0 .1, second.1 .1));
                if first.0 .0 == second.0 .0 && y1 < y2 {
                    let y = if y1.abs() < y2.abs() { y1 } else { y2 };
                    Some(steps + (first.0 .1 - y).abs() + (second.0 .1 - y).abs())
                } else {
                    None
                }
            }
            // In both lines 'y' coords are equal
            (false, false) => {
                let x1 = max(min(first.0 .0, first.1 .0), min(second.0 .0, second.1 .0));
                let x2 = min(max(first.1 .0, first.1 .0), min(second.0 .0, second.1 .0));
                if first.0 .1 == second.0 .1 && x1 < x2 {
                    let x = if x1.abs() < x2.abs() { x1 } else { x2 };
                    Some(steps + (first.0 .0 - x).abs() + (second.0 .0 - x).abs())
                } else {
                    None
                }
            }
            // In first line `x` are equal, in second `y` are equal
            (true, false) => {
                let fymin = min(first.0 .1, first.1 .1);
                let fymax = max(first.0 .1, first.1 .1);
                let sxmin = min(second.0 .0, second.1 .0);
                let sxmax = max(second.0 .0, second.1 .0);
                let x = first.0 .0;
                let y = second.0 .1;
                if sxmin <= x && x <= sxmax && fymin <= y && y <= fymax {
                    Some(steps + (first.0 .1 - y).abs() + (second.0 .0 - x).abs())
                } else {
                    None
                }
            }
            // In first line `y` are equal, in second `x` are equal
            (false, true) => {
                let fxmin = min(first.0 .0, first.1 .0);
                let fxmax = max(first.0 .0, first.1 .0);
                let symin = min(second.0 .1, second.1 .1);
                let symax = max(second.0 .1, second.1 .1);
                let x = second.0 .0;
                let y = first.0 .1;

                if symin <= y && y <= symax && fxmin <= x && x <= fxmax {
                    Some(steps + (first.0 .0 - x).abs() + (second.0 .1 - y).abs())
                } else {
                    None
                }
            }
        }
    }
// Returns distance between intersection and (0, 0) if lines intersects
Returns distance between intersection and (0, 0) if lines intersects
Returns distance between intersection and ( 0 0 ) if lines intersects
pub(super) fn intersect(
        first_steps: i64,
        first: &((i64, i64), (i64, i64)),
        second_steps: i64,
        second: &((i64, i64), (i64, i64)),
    ) -> Option<i64> {
        let steps = first_steps + second_steps;
        // Assumption 1: either `x` or `y` coords of each lines are equal
        match ((first.0 .0 == first.1 .0), (second.0 .0 == second.1 .0)) {
            // In both lines `x` coords are qual
            (true, true) => {
                let y1 = max(min(first.0 .1, first.1 .1), min(second.0 .1, second.1 .1));
                let y2 = min(max(first.0 .1, first.1 .1), max(second.0 .1, second.1 .1));
                if first.0 .0 == second.0 .0 && y1 < y2 {
                    let y = if y1.abs() < y2.abs() { y1 } else { y2 };
                    Some(steps + (first.0 .1 - y).abs() + (second.0 .1 - y).abs())
                } else {
                    None
                }
            }
            // In both lines 'y' coords are equal
            (false, false) => {
                let x1 = max(min(first.0 .0, first.1 .0), min(second.0 .0, second.1 .0));
                let x2 = min(max(first.1 .0, first.1 .0), min(second.0 .0, second.1 .0));
                if first.0 .1 == second.0 .1 && x1 < x2 {
                    let x = if x1.abs() < x2.abs() { x1 } else { x2 };
                    Some(steps + (first.0 .0 - x).abs() + (second.0 .0 - x).abs())
                } else {
                    None
                }
            }
            // In first line `x` are equal, in second `y` are equal
            (true, false) => {
                let fymin = min(first.0 .1, first.1 .1);
                let fymax = max(first.0 .1, first.1 .1);
                let sxmin = min(second.0 .0, second.1 .0);
                let sxmax = max(second.0 .0, second.1 .0);
                let x = first.0 .0;
                let y = second.0 .1;
                if sxmin <= x && x <= sxmax && fymin <= y && y <= fymax {
                    Some(steps + (first.0 .1 - y).abs() + (second.0 .0 - x).abs())
                } else {
                    None
                }
            }
            // In first line `y` are equal, in second `x` are equal
            (false, true) => {
                let fxmin = min(first.0 .0, first.1 .0);
                let fxmax = max(first.0 .0, first.1 .0);
                let symin = min(second.0 .1, second.1 .1);
                let symax = max(second.0 .1, second.1 .1);
                let x = second.0 .0;
                let y = first.0 .1;
                if symin <= y && y <= symax && fxmin <= x && x <= fxmax {
                    Some(steps + (first.0 .0 - x).abs() + (second.0 .1 - y).abs())
                } else {
                    None
                }
            }
        }
    }
pub ( super ) fn intersect ( first_steps : i64 , first : & ( ( i64 , i64 ) , ( i64 , i64 ) ) , second_steps : i64 , second : & ( ( i64 , i64 ) , ( i64 , i64 ) ) , ) -> Option < i64 > { let steps = first_steps + second_steps ; // Assumption 1: either `x` or `y` coords of each lines are equal match ( ( first . 0 . 0 == first . 1 . 0 ) , ( second . 0 . 0 == second . 1 . 0 ) ) { // In both lines `x` coords are qual ( true , true ) => { let y1 = max ( min ( first . 0 . 1 , first . 1 . 1 ) , min ( second . 0 . 1 , second . 1 . 1 ) ) ; let y2 = min ( max ( first . 0 . 1 , first . 1 . 1 ) , max ( second . 0 . 1 , second . 1 . 1 ) ) ; if first . 0 . 0 == second . 0 . 0 && y1 < y2 { let y = if y1 . abs ( ) < y2 . abs ( ) { y1 } else { y2 } ; Some ( steps + ( first . 0 . 1 - y ) . abs ( ) + ( second . 0 . 1 - y ) . abs ( ) ) } else { None } } // In both lines 'y' coords are equal ( false , false ) => { let x1 = max ( min ( first . 0 . 0 , first . 1 . 0 ) , min ( second . 0 . 0 , second . 1 . 0 ) ) ; let x2 = min ( max ( first . 1 . 0 , first . 1 . 0 ) , min ( second . 0 . 0 , second . 1 . 0 ) ) ; if first . 0 . 1 == second . 0 . 1 && x1 < x2 { let x = if x1 . abs ( ) < x2 . abs ( ) { x1 } else { x2 } ; Some ( steps + ( first . 0 . 0 - x ) . abs ( ) + ( second . 0 . 0 - x ) . abs ( ) ) } else { None } } // In first line `x` are equal, in second `y` are equal ( true , false ) => { let fymin = min ( first . 0 . 1 , first . 1 . 1 ) ; let fymax = max ( first . 0 . 1 , first . 1 . 1 ) ; let sxmin = min ( second . 0 . 0 , second . 1 . 0 ) ; let sxmax = max ( second . 0 . 0 , second . 1 . 0 ) ; let x = first . 0 . 0 ; let y = second . 0 . 1 ; if sxmin <= x && x <= sxmax && fymin <= y && y <= fymax { Some ( steps + ( first . 0 . 1 - y ) . abs ( ) + ( second . 0 . 0 - x ) . abs ( ) ) } else { None } } // In first line `y` are equal, in second `x` are equal ( false , true ) => { let fxmin = min ( first . 0 . 0 , first . 1 . 0 ) ; let fxmax = max ( first . 0 . 0 , first . 1 . 0 ) ; let symin = min ( second . 0 . 1 , second . 1 . 1 ) ; let symax = max ( second . 0 . 1 , second . 1 . 1 ) ; let x = second . 0 . 0 ; let y = first . 0 . 1 ; if symin <= y && y <= symax && fxmin <= x && x <= fxmax { Some ( steps + ( first . 0 . 0 - x ) . abs ( ) + ( second . 0 . 1 - y ) . abs ( ) ) } else { None } } } }
Returns distance between intersection and (0, 0) if lines intersects
Returns distance between intersection and ( 0 0 ) if lines intersects
first_steps
i64
first
&((i64, i64), (i64, i64))
second_steps
i64
second
&((i64, i64), (i64, i64))