public function closePath() 
    {
        $pathsCount = count($this->paths);
        if ($pathsCount > 0) {
            $path = $this->paths[$pathsCount - 1];
            $pathCount = count($path);
            
            if ($pathCount > 2) {
                // Close path
                if ($path[0] != $path[$pathCount - 2] ||
                    $path[1] != $path[$pathCount - 1]
                ) {
                    $path[] = $path[0];
                    $path[] = $path[1];
                }

                // Begin a new path
                $this->paths[] = array($path[0], $path[1]);
            }
        }
    }