Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function zoverlaps($first_start, $first_end, $second_start, $second_end) {
- return !(
- ($first_start < $second_start && $first_end < $second_start)
- ||
- ($first_start > $second_end && $first_end > $second_end)
- );
- }
- function overlaps($a,$b,$c,$d) {return !((($a>$b?$b:$a)<($c>$d?$d:$c)&&($b>$a?$b:$a)<($c>$d?$d:$c))||(($a>$b?$b:$a)>($d>$c?$d:$c)&&($b>$a?$b:$a)>($d>$c?$d:$c)));}
- $tests = array(
- array( 'data' => array(10,20,30,40), 'result' => FALSE ),
- array( 'data' => array(30,40,10,20), 'result' => FALSE ),
- array( 'data' => array(10,40,20,30), 'result' => TRUE ),
- array( 'data' => array(20,30,10,40), 'result' => TRUE ),
- array( 'data' => array(10,30,20,40), 'result' => TRUE ),
- array( 'data' => array(20,40,10,30), 'result' => TRUE ),
- );
- foreach ($tests as $test) {
- $foo = overlaps(
- $test['data'][0],
- $test['data'][1],
- $test['data'][2],
- $test['data'][3]
- );
- echo ($foo == $test['result'] ? "ok\n" : "FAIL\n");
- $foo = overlaps(
- $test['data'][1],
- $test['data'][0],
- $test['data'][3],
- $test['data'][2]
- );
- echo ($foo == $test['result'] ? "ok\n" : "FAIL\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement