Comment detail

長方形の交差判定 (Nested Flatten)
普通に。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
class Rectangle{
	private $top;
	private $left;
	private $right;
	private $bottom;

	public function __construct($top, $left, $right, $bottom){
		$this->top = $top;
		$this->left = $left;
		$this->right = $right;
		$this->bottom = $bottom;
	}

	public function isOverlapped($rectangle){
		if(	$this->right >$rectangle->left
			&& $this->left < $rectangle->right
			&& $this->bottom > $rectangle->top
			&& $this->top < $rectangle->bottom){
			return "overlapped";
		}else{
			return "not overlapped";
		}
	}
}

$rect1 = new Rectangle(0, 0, 100, 100);
$rect2 = new Rectangle(0, 0, 50, 50);

echo($rect1->isOverlapped($rect2));
?>

Index

Feed

Other

Link

Pathtraq

loading...