[TASK] Fixed a bug in the movePointer() function.
This commit is contained in:
+24
-5
@@ -36,12 +36,27 @@ class BoxImage {
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($size) {
|
||||
public function __construct($size, $mode) {
|
||||
if($size < 1) throw new Exception("This cannot be done!");
|
||||
|
||||
//determine width+height
|
||||
$this->height = ceil(sqrt($size));
|
||||
$this->width = $this->height;
|
||||
switch($mode) {
|
||||
case "square":
|
||||
$this->height = ceil(sqrt($size));
|
||||
$this->width = $this->height;
|
||||
break;
|
||||
case "line":
|
||||
$this->height = 1;
|
||||
$this->width = $size;
|
||||
break;
|
||||
case "bar":
|
||||
$this->height = $size;
|
||||
$this->width = 1;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown mode given!");
|
||||
break;
|
||||
}
|
||||
|
||||
//prepare image for PNG with transparency using the calculated size.
|
||||
$this->image = imagecreatetruecolor($this->width, $this->height);
|
||||
@@ -98,6 +113,8 @@ class BoxImage {
|
||||
* @return void
|
||||
*/
|
||||
public function movePointer($offset) {
|
||||
//echo $this->pointer_x.",".$this->pointer_y." --> ";
|
||||
|
||||
if($offset === 0) return;
|
||||
if($offset > 0) $step = 1;
|
||||
if($offset < 0){
|
||||
@@ -125,14 +142,16 @@ class BoxImage {
|
||||
//increase x-pointer
|
||||
$this->pointer_x += 1;
|
||||
//handle y-jumps
|
||||
if($this->pointer_x > $this->width) {
|
||||
if($this->pointer_x >= $this->width) {
|
||||
$this->pointer_x = 0;
|
||||
$this->pointer_y += 1;
|
||||
//out of range?
|
||||
if($this->pointer_y > $this->height) throw new Exception("Out of range! (height)");
|
||||
if($this->pointer_y >= $this->height) throw new Exception("Out of range! (height)");
|
||||
}
|
||||
} //end of if
|
||||
} //end of for
|
||||
|
||||
//echo $this->pointer_x.",".$this->pointer_y."\n";
|
||||
} //end of function
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user