// bounding boxes intersection tests
// Rates 1D intersection of 2 segments A and B
// described respectively with a0,a1 and b0,b1
def "func:intersect_1d" {
// it is assumed that a1 > a0 and b1 > b0
const "d0", "$a0 >= $b0";
const "d1", "$a1 >= $b1";
when "$d0 and $d1 and $a0 < $b1"
// a and b are overlapped
when "not($d0) and not($d1) and $b0 < $a1"
// a and b are overlapped
// since orientation doesn't matter,
// rated same as previous symetrical overlapping
result "0"; /* no intersection*/
// Rates intersection A and B areas described with x,y,w and h
// attributes passed as $a and $b parameters.
const "x_intersect", "func:intersect_1d($a/@x, $a/@x+$a/@w, $b/@x, $b/@x+$b/@w)";
when "$x_intersect != 0"{
const "y_intersect", "func:intersect_1d($a/@y, $a/@y+$a/@h, $b/@y, $b/@y+$b/@h)";
result "$x_intersect * $y_intersect";