PEMapModder

BulkCommands busy code

Apr 1st, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1.     public function isInside(Vector3 $p){
  2.         $v2 = new Vector2($p->x, $p->z);
  3.         $hash = $this->hash($v2);
  4.         if(isset($this->cache[$hash])){
  5.             return $this->cache[$hash];
  6.         }
  7.         $intersects = 0;
  8.         foreach($this->lines as $line){
  9.             $intersects += $line->isAbsolutelyAbove($v2);
  10.         }
  11.         $this->cache[$hash] = $result = (bool) ($intersects & 1);
  12.         return $result;
  13.     }
  14.  
  15.     public function isAbsolutelyAbove(Vector2 $pt){
  16.         $intercept = $this->getZInterceptByX($pt->x);
  17.         if($intercept > $pt->y){
  18.             return self::ABOVE;
  19.         }
  20.         if($intercept === $pt->y){
  21.             return self::INTERSECT;
  22.         }
  23.         return self::BELOW;
  24.     }
  25.     public function getSlope(){
  26.         return ($this->toz - $this->fromz) / ($this->tox - $this->fromx);
  27.     }
  28.     public function getZInterceptByX($x0){
  29.         return $this->fromz - ($this->fromx - $x0) * $this->getSlope(); // c=mx-y
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment