function plotPoints(&$im, $w, $h, $startPadding, $endPadding, $yAxis, $minY, $maxY, $xDivisions, $yDivisions, $lineColor, $xAxisEndPadding) { $x1 = $startPadding; $xMod = ($w - $xAxisEndPadding - $startPadding) / $xDivisions; for ($i = 0; $i < count($yAxis); $i++) { $y1 = $h - $startPadding - ($h - 2 * $startPadding) * ($yAxis[$i] - $minY) / ($maxY - $minY); drawPoint($im, $x1, $y1, $lineColor); if ($i + 1 < count($yAxis)) { $x2 = $x1 + $xMod; $y2 = $h - $startPadding - ($h - 2 * $startPadding) * ($yAxis[$i + 1] - $minY) / ($maxY - $minY); drawLine($im, $x1, $y1, $x2, $y2, $lineColor); } $x1 += $xMod; } }
<?php class notGpsCoord extends Exception { } class outOfBoundsCoord extends Exception { } function drawPoint($p) { if (is_string($p)) { throw new notGpsCoord("Invalid GPS coord. Must be number.\n"); } if ($p > 100000) { throw new outOfBoundsCoord("Invalid GPS coord. Too great.\n"); } } try { //drawPoint(100001); drawPoint('foo'); } catch (notGpsCoord $e) { echo $e->getMessage(); } catch (outOfBoundsCoord $e) { echo $e->getMessage(); }