このコードは 2 つの四角形の交点を見つけますが、完全には理解できません。紙にマッピングしようとすると、長方形にもなりません。
def rec_intersection(rect1, rect2)
x_min = [rect1[0][0], rect2[0][1]].max
x_max = [rect1[1][0], rect2[1][1]].min
y_min = [rect1[0][0], rect2[0][1]].max
y_max = [rect1[1][0], rect2[1][1]].min
return nil if ((x_max < x_min) || (y_max < y_min))
return [[x_min, y_min], [x_max, y_max]]
end
rec_intersection([[1, 1], [2, 2]],[[0, 0], [5, 5]])
上記のコードは を返します[[1, 1], [2, 2]]
。誰かがプロセスを説明できますか?