pub(super) fn intersect(
        first: &((i64, i64), (i64, i64)),
        second: &((i64, i64), (i64, i64)),
    ) -> Option<i64> {
        // Assumption 1: either `x` or `y` coords of each lines are equal
        // Assumption 2: lower coord is always on first point of line
        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(first.0 .1, second.0 .1);
                let y2 = min(first.1 .1, second.1 .1);
                if first.0 .0 == second.0 .0 && y1 < y2 {
                    Some(min(y1.abs(), y2.abs()))
                } else {
                    None
                }
            }
            // In both lines 'y' coords are equal
            (false, false) => {
                let x1 = max(first.0 .0, second.0 .0);
                let x2 = min(first.1 .0, second.1 .0);
                if first.0 .1 == second.0 .1 && x1 < x2 {
                    Some(min(x1.abs(), x2.abs()))
                } else {
                    None
                }
            }
            // In first line `x` are equal, in second `y` are equal
            (true, false) => {
                if second.0 .0 <= first.0 .0
                    && first.0 .0 <= second.1 .0
                    && first.0 .1 <= second.0 .1
                    && second.0 .1 <= first.1 .1
                {
                    Some(first.0 .0.abs() + second.0 .1.abs())
                } else {
                    None
                }
            }
            // In first line `y` are equal, in second `x` are equal
            (false, true) => {
                if second.0 .1 <= first.0 .1
                    && first.0 .1 <= second.1 .1
                    && first.0 .0 <= second.0 .0
                    && second.0 .0 <= first.1 .0
                {
                    Some(second.0 .0.abs() + first.0 .1.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: &((i64, i64), (i64, i64)),
        second: &((i64, i64), (i64, i64)),
    ) -> Option<i64> {
        // Assumption 1: either `x` or `y` coords of each lines are equal
        // Assumption 2: lower coord is always on first point of line
        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(first.0 .1, second.0 .1);
                let y2 = min(first.1 .1, second.1 .1);
                if first.0 .0 == second.0 .0 && y1 < y2 {
                    Some(min(y1.abs(), y2.abs()))
                } else {
                    None
                }
            }
            // In both lines 'y' coords are equal
            (false, false) => {
                let x1 = max(first.0 .0, second.0 .0);
                let x2 = min(first.1 .0, second.1 .0);
                if first.0 .1 == second.0 .1 && x1 < x2 {
                    Some(min(x1.abs(), x2.abs()))
                } else {
                    None
                }
            }
            // In first line `x` are equal, in second `y` are equal
            (true, false) => {
                if second.0 .0 <= first.0 .0
                    && first.0 .0 <= second.1 .0
                    && first.0 .1 <= second.0 .1
                    && second.0 .1 <= first.1 .1
                {
                    Some(first.0 .0.abs() + second.0 .1.abs())
                } else {
                    None
                }
            }
            // In first line `y` are equal, in second `x` are equal
            (false, true) => {
                if second.0 .1 <= first.0 .1
                    && first.0 .1 <= second.1 .1
                    && first.0 .0 <= second.0 .0
                    && second.0 .0 <= first.1 .0
                {
                    Some(second.0 .0.abs() + first.0 .1.abs())
                } else {
                    None
                }
            }
        }
    }
pub ( super ) fn intersect ( first : & ( ( i64 , i64 ) , ( i64 , i64 ) ) , second : & ( ( i64 , i64 ) , ( i64 , i64 ) ) , ) -> Option < i64 > { // Assumption 1: either `x` or `y` coords of each lines are equal // Assumption 2: lower coord is always on first point of line 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 ( first . 0 . 1 , second . 0 . 1 ) ; let y2 = min ( first . 1 . 1 , second . 1 . 1 ) ; if first . 0 . 0 == second . 0 . 0 && y1 < y2 { Some ( min ( y1 . abs ( ) , y2 . abs ( ) ) ) } else { None } } // In both lines 'y' coords are equal ( false , false ) => { let x1 = max ( first . 0 . 0 , second . 0 . 0 ) ; let x2 = min ( first . 1 . 0 , second . 1 . 0 ) ; if first . 0 . 1 == second . 0 . 1 && x1 < x2 { Some ( min ( x1 . abs ( ) , x2 . abs ( ) ) ) } else { None } } // In first line `x` are equal, in second `y` are equal ( true , false ) => { if second . 0 . 0 <= first . 0 . 0 && first . 0 . 0 <= second . 1 . 0 && first . 0 . 1 <= second . 0 . 1 && second . 0 . 1 <= first . 1 . 1 { Some ( first . 0 . 0 . abs ( ) + second . 0 . 1 . abs ( ) ) } else { None } } // In first line `y` are equal, in second `x` are equal ( false , true ) => { if second . 0 . 1 <= first . 0 . 1 && first . 0 . 1 <= second . 1 . 1 && first . 0 . 0 <= second . 0 . 0 && second . 0 . 0 <= first . 1 . 0 { Some ( second . 0 . 0 . abs ( ) + first . 0 . 1 . abs ( ) ) } else { None } } } }
Returns distance between intersection and (0, 0) if lines intersects
Returns distance between intersection and ( 0 0 ) if lines intersects
first
&((i64, i64), (i64, i64))
second
&((i64, i64), (i64, i64))