/** * */ public function testOperations() { $p1 = new Point2d(2, 5); $p2 = new Point2d(1, 2); $p3 = new Point2d(1, 3); $p4 = new Point2d(1, 3); $p5 = new Point2d(1, 0); $v1 = new Vector2d(1, 2); $v2 = new Vector2d(1, 3); $this->assertEquals($p3, $p4); $this->assertEquals($p3, Point2d::subtract($p1, $v1)); $this->assertEquals($p1, Point2d::add($p2, $v2)); $this->assertEquals($v2, Point2d::subtractP($p1, $p2)); $p1->offset(-1, -5); $this->assertEquals($p1, $p5); }
/** * Apply a vector on each point and return a new instance of Polygon * * @param Vector2d $vector * @return Polygon */ public function translate(Vector2d $vector) { $buffer = clone $this; foreach ($buffer->_points as $index => $point) { $buffer->setPoint($index, Point2d::add($point, $vector)); } return $buffer; }