function intersectsLine($line) { global $svg; $intersects = false; $rect2 = new Rectangle(); $rect2->lineBbox($line); if ($this->intersectsRect($rect2)) { if (!$intersects) { // top $side = new Line($this->x, $this->y, $this->x + $this->w, $this->y); $intersects = $line->lineSegmentTouchesOrCrossesLine($side); //if ($intersects) { echo "top\n"; $svg .= $side->toSvg(); } } if (!$intersects) { // right $side = new Line($this->x + $this->w, $this->y, $this->x + $this->w, $this->y + $this->h); $intersects = $line->lineSegmentTouchesOrCrossesLine($side); //if ($intersects) { echo "right\n"; $svg .= $side->toSvg(); } } if (!$intersects) { // bottom $side = new Line($this->x, $this->y + $this->h, $this->x + $this->w, $this->y + $this->h); $intersects = $line->lineSegmentTouchesOrCrossesLine($side); //if ($intersects) { echo "bottom\n"; $svg .= $side->toSvg(); } } if (!$intersects) { // left $side = new Line($this->x, $this->y, $this->x, $this->y + $this->h); $intersects = $line->lineSegmentTouchesOrCrossesLine($side); //if ($intersects) { echo "left\n"; $svg .= $side->toSvg(); } } } return $intersects; }