/** * Rectangle constructor. * * @param Point2d $pointA A point * @param Point2d $pointB B point * @param Point2d $pointC C point * @param Point2d $pointD D point * @throws Exception */ public function __construct(Point2d $pointA, Point2d $pointB, Point2d $pointC, Point2d $pointD) { parent::__construct(); $test1 = Point2d::getAngle($pointA, $pointD, $pointB); $test2 = Point2d::getAngle($pointB, $pointA, $pointC); $test3 = Point2d::getAngle($pointC, $pointB, $pointD); $test4 = Point2d::getAngle($pointD, $pointC, $pointA); if ($test1 != deg2rad(90) || $test2 != deg2rad(90) || $test3 != deg2rad(90) || $test4 != deg2rad(90)) { throw new Exception('Points must be draw a rectangle!'); } $this->setPointA($pointA); $this->setPointB($pointB); $this->setPointC($pointC); $this->setPointD($pointD); }
/** * @expectedException Exception * @expectedExceptionMessage Points must be different than the center point! */ public function testGetAngleException() { $p1 = new Point2d(0, 0); $p2 = new Point2d(0, 0); $p3 = new Point2d(0, 3); Point2d::getAngle($p1, $p2, $p3); }
/** * Determines if this triangle is right * * @return bool */ public function isRight() { $angles = [Point2d::getAngle($this->getPointA(), $this->getPointB(), $this->getPointC()), Point2d::getAngle($this->getPointB(), $this->getPointA(), $this->getPointC()), Point2d::getAngle($this->getPointC(), $this->getPointA(), $this->getPointB())]; return in_array(deg2rad(90), $angles); }