$X = $xs[$num]; $Y = $ys[$num]; if ($xMin > $X) { $xMin = $X; } if ($yMin > $Y) { $yMin = $Y; } if ($xMax < $X + $W) { $xMax = $X + $W; } if ($yMax < $Y + $H) { $yMax = $Y + $H; } //check for centering if (isHead(dechex($code)) or isTrunk(dechex($code))) { if ($centering == 0) { $cxMin = $X; $cxMax = $X + $W; $cyMin = $Y; $cyMax = $Y + $H; } else { if ($cxMin > $X) { $cxMin = $X; } if ($cyMin > $Y) { $cyMin = $Y; } if ($cxMax < $X + $W) { $cxMax = $X + $W; }
public function __construct($bsw) { $this->bsw = $bsw; $this->lane = substr($bsw, 0, 3); $this->cluster = bsw2cluster($bsw); $this->seq = bsw2seq($bsw); /** * Step 1: break apart */ $keys = array(); $xs = array(); // x position $ys = array(); // y position $ws = array(); // width $hs = array(); // height $bsw = bsw2cluster($bsw); $chars = str_split($bsw, 3); $cnt = count($chars); if ($bsw != "") { for ($i = 0; $i < $cnt; $i++) { $char = $chars[$i]; $i++; $fill = char2fill($chars[$i]); $i++; $rot = char2rot($chars[$i]); $key = $char . $fill . $rot; $keys[] = $key; $i++; $xs[] = hex2num($chars[$i]); $i++; $ys[] = hex2num($chars[$i]); $sym = new Symbol($key); $ws[] = $sym->getWidth(); $hs[] = $sym->getHeight(); } /** * Step 2: determing width, height, and center */ $xMin = $xs[0]; $xMax = $xMin + 2; $yMin = $ys[0]; $yMax = $yMin + 2; $cxMin = 0; $cxMax = 0; $cyMin = 0; $cyMax = 0; $centering = 0; // centering count } else { //make up values $xMin = 0; $xMax = $xMin + 2; $yMin = 0; $yMax = $yMin + 2; $cxMin = 0; $cxMax = 0; $cyMin = 0; $cyMax = 0; $centering = 0; // centering count } foreach ($keys as $num => $key) { $base = substr($key, 0, 3); $W = $ws[$num]; $H = $hs[$num]; $X = $xs[$num]; $Y = $ys[$num]; if ($xMin > $X) { $xMin = $X; } if ($yMin > $Y) { $yMin = $Y; } if ($xMax < $X + $W) { $xMax = $X + $W; } if ($yMax < $Y + $H) { $yMax = $Y + $H; } //check for centering if (isHead($base) or isTrunk($base)) { if ($centering == 0) { $cxMin = $X; $cxMax = $X + $W; $cyMin = $Y; $cyMax = $Y + $H; } else { if ($cxMin > $X) { $cxMin = $X; } if ($cyMin > $Y) { $cyMin = $Y; } if ($cxMax < $X + $W) { $cxMax = $X + $W; } if ($cyMax < $Y + $H) { $cyMax = $Y + $H; } } $centering++; } } $this->width = $xMax - $xMin; $this->height = $yMax - $yMin; if ($centering) { $this->centerX = ($cxMin + $cxMax) / 2 - $xMin; $this->centerY = ($cyMin + $cyMax) / 2 - $yMin; } else { $this->centerX = ($xMin + $xMax) / 2; $this->centerY = ($yMin + $yMax) / 2; } //rebuild bsw with zero relative x and y $this->bsw = $this->lane; foreach ($keys as $num => $key) { $this->bsw .= key2bsw($key); $X = $xs[$num]; $this->bsw .= num2hex($X - $xMin); //$this->centerX); $Y = $ys[$num]; $this->bsw .= num2hex($Y - $yMin); //$this->centerY); } //already zero based // $this->centerX -= $xMin; // $this->centerY -= $yMin; if ($this->seq) { $this->bsw .= '0fd' . $this->seq; } }
function char2token($char) { $token = '-'; switch ($char) { case "0fa": //left lane $token = 'L'; break; case "0fb": // sign box $token = 'B'; break; case "0fc": //right lane $token = 'R'; break; case "0fd": //sequence $token = 'Q'; break; } if (isHand($char)) { $token = 'h'; } if (isMove($char)) { $token = 'm'; } if (isDyn($char)) { $token = 'd'; } if (isHead($char)) { $token = 'f'; } if (isTrunk($char)) { $token = 't'; } if (isLimb($char)) { $token = 'x'; } if (isSeq($char)) { $token = 's'; } if (isPunc($char)) { $token = 'P'; } if (isFill($char)) { $token = 'i'; } if (isRot($char)) { $token = 'o'; } if (isNum($char)) { $token = 'n'; } return $token; }
function testRmRes() { $h1 = isHead(new folksoQuery(array(), array('folksores' => 'http://example.com/1'), array()), new folksoDBconnect('localhost', 'tester_dude', 'testy', 'testostonomie'), $this->fks); $this->assertEqual($h1->status, 200, 'example.com/1 not present acorrding to isHead. Test pb.'); $this->fks->startSession('vicktr-2010-001', true); $r = rmRes(new folksoQuery(array(), array('folksores' => 'http://example.com/1'), array()), new folksoDBconnect('localhost', 'tester_dude', 'testy', 'testostonomie'), $this->fks); $this->assertIsA($r, folksoResponse, 'rmRes does not return a folksoResponse object'); $this->assertEqual($r->status, 200, 'rmRes returns error code' . $r->status . $r->statusMessage . $r->body()); $h = isHead(new folksoQuery(array(), array('folksores' => 'http://example.com/1'), array()), new folksoDBconnect('localhost', 'tester_dude', 'testy', 'testostonomie'), $this->fks3); $this->assertEqual($h->status, 404, 'Removed resource still present in DB' . $r->status); }