Ejemplo n.º 1
0
 public function test_move_returns_new_point()
 {
     $a = new Point(1, 1);
     $c = $a->move($by = new Point(2, 2));
     static::assertNotSame($a, $c);
     static::assertNotSame($by, $c);
 }
Ejemplo n.º 2
0
 /**
  * @param Point $a
  * @param Point $b
  *
  * @return Line
  */
 public static function combineToRisingLine(Point $a, Point $b)
 {
     $minX = min($a->getX(), $b->getX());
     $maxX = max($a->getX(), $b->getX());
     $minY = min($a->getY(), $b->getY());
     $maxY = max($a->getY(), $b->getY());
     return new self(new Point($minX, $minY), new Point($maxX, $maxY));
 }
Ejemplo n.º 3
0
 /**
  * @param Point $a
  * @param Point $b
  *
  * @return LinearFunction
  *
  * @throws \RuntimeException When $a and $b points have same x
  */
 public static function fromTwoPoints(Point $a, Point $b)
 {
     if ($a->getX() === $b->getX()) {
         throw new \RuntimeException('Line can be defined only by two points with different X');
     }
     $k = ($a->getY() - $b->getY()) / ($a->getX() - $b->getX());
     $n = $a->getY() - $k * $a->getX();
     return new self($k, $n);
 }
Ejemplo n.º 4
0
 /**
  * @return PointSet
  */
 public function produce()
 {
     $result = new PointSet();
     foreach ($this->lowerLeft->forXUpTo($this->upperRight) as $x) {
         foreach ($this->lowerLeft->forYUpTo($this->upperRight) as $y) {
             $point = new Point($x, $y);
             $value = $this->getValue($point);
             $result->attach($point, $value);
         }
     }
     return $result;
 }
 /**
  * @return PointSet
  */
 public function produce()
 {
     $result = new PointSet();
     foreach ($this->lowerLeft->forXTimes($this->width) as $x) {
         foreach ($this->lowerLeft->forYTimes($this->height) as $y) {
             $point = new Point($x, $y);
             $value = $this->getValue($point);
             $result->attach($point, $value);
         }
     }
     return $result;
 }
Ejemplo n.º 6
0
 /**
  * @param PointSet $result
  * @param Point    $a
  * @param Point    $b
  */
 private function addRow(PointSet $result, Point $a, Point $b)
 {
     if ($a->getX() > $b->getX()) {
         $t = $a;
         $a = $b;
         $b = $t;
     }
     if ($this->fill) {
         foreach ($a->forXUpTo($b) as $x) {
             $this->addPoint($result, new Point($x, $a->getY()));
         }
     } else {
         $this->addPoint($result, $a);
         $this->addPoint($result, $b);
     }
 }
Ejemplo n.º 7
0
 /**
  * @param float $x
  *
  * @return float|null
  */
 public function evaluate($x)
 {
     $nowPoint = new Point($x, 0);
     $containingLine = null;
     foreach ($this->path->getLineIterator() as $line) {
         if ($nowPoint->betweenX($line->getStartPoint(), $line->getEndPoint())) {
             $containingLine = $line;
             break;
         }
     }
     if (null === $containingLine) {
         if (false === $this->extrapolate) {
             return null;
         }
         if ($this->path->firstPoint()->getX() > $x) {
             $containingLine = $this->path->firstLine();
         } else {
             $containingLine = $this->path->lastLine();
         }
     }
     return $containingLine->getLinearFunction()->evaluate($x);
 }