Пример #1
0
 public function testPoint()
 {
     $p1 = new WMPoint(10, 13);
     $p2 = new WMPoint(-40, 40);
     $p3 = new WMPoint(30, 33);
     $p4 = new WMPoint(10, 13);
     $p5 = new WMPoint(10.001, 13.001);
     $p6 = new WMPoint(10.1, 13.1);
     $p8 = new WMPoint(-10, 13);
     $this->assertTrue($p1->identical($p4));
     $this->assertTrue($p4->identical($p1));
     $this->assertFalse($p4->identical($p2));
     $this->assertTrue($p1->closeEnough($p5));
     $this->assertFalse($p1->closeEnough($p6));
     $p5->round();
     $this->assertTrue($p1->identical($p5));
     $p7 = $p1->copy();
     $this->assertTrue($p1->identical($p7));
     $this->assertEquals(sqrt(800), $p1->distanceToPoint($p3));
     $this->assertEquals(sqrt(800), $p3->distanceToPoint($p1));
     $this->assertEquals(20, $p1->distanceToPoint($p8));
     $this->assertEquals(20, $p8->distanceToPoint($p1));
     $v1 = new WMVector(10, 40);
     $v2 = $p1->vectorToPoint($p2);
     $p = $p1->LERPWith($p3, 0.5);
     $this->assertTrue($p->identical(new WMPoint(20, 23)));
     $p = $p1->LERPWith($p3, -0.5);
     $this->assertTrue($p->identical(new WMPoint(0, 3)));
     $p = $p1->LERPWith($p3, 2.0);
     $this->assertTrue($p->identical(new WMPoint(50, 53)));
     $this->assertEquals("(10.000000,13.000000)", $p1->asString());
     $this->assertEquals("(30.000000,33.000000)", $p3->asString());
     $this->assertEquals("(10.000000,13.000000)", "{$p1}");
     $this->assertEquals("(30.000000,33.000000)", "{$p3}");
     $p->addVector($v1, 1.0);
     $this->assertTrue($p->identical(new WMPoint(60, 93)));
     $p->addVector($v1, -2.0);
     $this->assertTrue($p->identical(new WMPoint(40, 13)));
     $p->addVector($v1, 0);
     $this->assertTrue($p->identical(new WMPoint(40, 13)));
     $l = $p->lineToPoint($p1);
     $this->assertEquals("/(40.000000,13.000000)-[-30.000000,0.000000]/", "{$l}");
 }
 /**
  * Given a start point on the spine, calculate the points for an arrowhead.
  *
  * @param WMPoint $startPoint - a point back from the end of the spine
  * @param WMPoint $endPoint - the actual end of the spine (the point of the arrow)
  * @param int $linkWidth - the width of the link
  * @param int $arrowWidth - the width of the arrowhead widest point
  *
  * @return WMPoint[]
  */
 function generateArrowhead($startPoint, $endPoint, $linkWidth, $arrowWidth)
 {
     $points = array();
     // Calculate a tangent
     $arrowDirection = $startPoint->vectorToPoint($endPoint);
     $arrowDirection->normalise();
     // and from that, a normal
     $arrowNormal = $arrowDirection->getNormal();
     $points[] = $startPoint->copy()->addVector($arrowNormal, $linkWidth);
     $points[] = $startPoint->copy()->addVector($arrowNormal, $arrowWidth);
     $points[] = $endPoint;
     $points[] = $startPoint->copy()->addVector($arrowNormal, -$arrowWidth);
     $points[] = $startPoint->copy()->addVector($arrowNormal, -$linkWidth);
     return $points;
 }