$fbswml .= '<sign lane="' . char2lane($first) . '"><br>'; for ($i = 0; $i < count($chars); $i++) { //first 3 are symbol $sbsw = $chars[$i]; $i++; $sbsw .= $chars[$i]; $i++; $sbsw .= $chars[$i]; //next 2 are coordinates $i++; $sx = hex2num($chars[$i]); $i++; $sy = hex2num($chars[$i]); //center coordinates on symbol $sym = new Symbol($sbsw); $scx = round($sx + $sym->getWidth() / 2); $scy = round($sy + $sym->getHeight() / 2); //now to determine degrees //convoluted for easy... $sd = $scx < 0 ? round(rad2deg(atan2($scx, -$scy))) + 360 : round(rad2deg(atan2($scx, -$scy))); // $sd = round(rad2deg(atan2(-$scy, -$scx))); //now to determine length $sl = round(sqrt(pow($scx, 2) + pow($scy, 2))); $fswcm .= bsw2utf($sbsw, 1) . $sx . ',' . $sy; if (count($chars) == 5) { $fswpm .= bsw2utf($sbsw, 1) . '0°0'; } else { $fswpm .= bsw2utf($sbsw, 1) . $sd . '°' . $sl; } $fbswml .= ' <sym x="' . $sx . '" y="' . $sy . '">' . bsw2key($sbsw) . '</sym><br>'; }
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; } }