3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class CTransformator_2 { //public: function CTransformator() { $this->ro = 3.1415926535897932384626433832795 / 180; $this->InitPlane(); $this->InitEllipse(); } function Destroy() { } // default plane configuration: "TM-" function InitPlane($deg1 = 24.0, $min1 = 0.0, $sec1 = 0.0, $deg2 = 0.0, $min2 = 0.0, $sec2 = 0.0, $_cf3 = -6000000, $_cf4 = 500000, $_cf5 = 0, $_cf6 = 0.9996) { $this->cf1 = ($deg1 + $min1 / 60.0 + $sec1 / 3600.0) * $this->ro; $this->cf2 = ($deg2 + $min2 / 60.0 + $sec2 / 3600.0) * $this->ro; $this->cf3 = $_cf3; $this->cf4 = $_cf4; $this->cf5 = $_cf5; $this->cf6 = $_cf6; } // default elipse GRS80 = 6378137,298.2572221 function InitEllipse($_a = 6378137.0, $_alfa = 298.2572221) { $this->a = $_a; $this->alfa = $_alfa; $b = $this->a - $this->a / $this->alfa; $this->e2 = 1.0 - ($b * $b) / ($this->a * $this->a); $this->ep2 = ($this->a * $this->a) / ($b * $b) - 1.0; // for function mer() speed optimization $e2_2 = $this->e2 * $this->e2; $e2_3 = $e2_2 * $this->e2; $this->AA = 1.0 + (3.0/4.0)*$this->e2 + (45.0/64.0)*$e2_2 + (175.0/256.0)*$e2_3; $this->BB = ((3.0/4.0)*$this->e2 + (15.0/16.0)*$e2_2 + (525.0/512.0)*$e2_3) / 2.0; $this->CC = ((15.0/64.0)*$e2_2 + (105.0/256.0)*$e2_3) / 4.0; $this->DD = (( 35.0/512.0)*$e2_3) / 6.0; $this->a1e2 = $this->a*(1.0-$this->e2); } function GaussTU($B, $L, &$x, &$y, &$gam, &$merr) { $B *= $this->ro; $L *= $this->ro; $sinB = sin($B); $cosB = cos($B); $t = $sinB / $cosB; //tan(B); $t2 = $t * $t; $nn = $this->N($sinB); $M1 = $cosB * $cosB; $M2 = $M1 * $M1; $et2 = $this->ep2 * $M1; $et4 = $et2 * $et2; $X_L = $this->mer(0, $B); $l0 = $this->cf1; if ($this->cf2 > 0) { $l0 = abs($L - $this->cf1) + $this->cf2 / 2.0; $l0 = $this->IntPart($l0 / $this->cf2) * $this->cf2; if ($L < $this->cf1) $l0 = -$l0; $l0 += $this->cf1; } $ltd = $l0; // ------------------ WORK $lm = $L - $ltd; $lm2 = $lm * $lm; $lm4 = $lm2 * $lm2; $x = $X_L + ($lm2 / 2.0) * $nn * $sinB * $cosB * (1 + (($lm2 * $M1) / 12.0) * (5 - $t2 + 9*$et2 + 4*$et4) + (($lm4 * $M2) / 360.0) * (61 - 58*$t2 + $t2*$t2)); $y = $lm * $nn * $cosB * (1 + (($lm2 * $M1) / 6.0) * (1 - $t2 + $et2) + (($lm4 * $M2) / 120.0) * (5 - 18*$t2 + $t2*$t2 + 14*$et2 - 58*$et2*$t2)); $gam = $lm * $sinB * (1 + ($lm2/3.0) * $M1 * (1 + 3*$et2) + ($lm4/15.0) * $M2 * (2 - $t2)); $merr = 1 + ((1 + $et2) / 2.0) * $lm2 * $M1 + ((5 - 4*$t2) / 24.0) * $lm4 * $M2; $x = $x * $this->cf6 + $this->cf3; $y = $y * $this->cf6 + $this->cf4; if ($this->cf2 > 0) $y += $this->cf5 * ($ltd - $this->cf1) / $this->cf2; // ------------------ END OF WORK $merr *= $this->cf6; } function GaussPU($x, $y, &$B, &$L) { /*double Bx, dx, xa, yy, y2, y4, Mx, Mx2, Nx, Nx2, tx, tx2, eta2, dn;*/ $x = ($x - $this->cf3) / $this->cf6; $yy = $y - $this->cf4; $dn = 0; if ($this->cf5 > 0) { $dn = $this->IntPart($yy / $this->cf5 + (($yy < 0) ? -0.5 : +0.5)); $yy -= $dn * $this->cf5; } $yy /= $this->cf6; $y2 = $yy * $yy; $y4 = $y2 * $y2; // --------- Bx calculation ---------- $Bx = $x / $this->M(sin($x / $this->M(0) / 2.0)); $xa = $this->mer(0, $Bx); // xa = meridiana loka garums $dx = $x - $xa; // delta x while (abs($dx) > 0.0000001) { $Bx += $dx / $this->M(sin($Bx)); // jauna Bx vertiba $xa = $this->mer(0, $Bx); // xa = meridiana loka garums $dx = $x - $xa; // cikla kontroles aprekins } // --------- tx un eta aprekins ---------- $cosBx = cos($Bx); $sinBx = sin($Bx); $eta2 = $this->ep2 * $cosBx * $cosBx; $tx = $sinBx / $cosBx; // tan(Bx) $tx2 = $tx * $tx; // --------- Mx un Nx aprekins ---------- $Mx = $this->M($sinBx); $Mx2 = $Mx * $Mx; $Nx = $this->N($sinBx); $Nx2 = $Nx * $Nx; // --------- B aprekins ---------- $B = $Bx - ($y2 / (2*$Mx*$Nx)) * $tx * (1 - ($y2 / (12*$Nx2)) * (5 + 3*$tx2 + $eta2 - 9*$eta2 *$tx2) + ($y4 / (360*$Nx2*$Nx2)) * (61 + 90*$tx2 + 45*$tx2*$tx2)); // --------- L aprekins ---------- $L = ($yy / ($Nx*$cosBx)) * (1 - ($y2 / (6*$Nx2)) * (1 + 2*$tx2 + $eta2) + ($y4 / (120*$Nx2*$Nx2)) * (5 + 28*$tx2 + 24*$tx2*$tx2 + 6*$eta2 + 8*$eta2 *$tx2)); // Izmainit geodezisko garumu $L += $this->cf1; if ($this->cf2 > 0) $L += $dn * $this->cf2; $L /= $this->ro; $B /= $this->ro; } //private: function IntPart($d) { return ($d >= 0) ? floor($d) : ceil($d); } // round towards zero function W($sinB) { return sqrt(1-$this->e2*$sinB*$sinB); } function M($sinB) { $r = $this->W($sinB); return $this->a*(1-$this->e2)/($r*$r*$r); } function N($sinB) { return $this->a/$this->W($sinB); } function mer($b1, $b2) { if ($b1 == 0) // optimization return $this->a1e2 * ($this->AA*$b2 - $this->BB*sin(2*$b2) + $this->CC*sin(4*$b2) - $this->DD*sin(6*$b2)); else return $this->a1e2 * ($this->AA*($b2-$b1) - $this->BB*(sin(2*$b2)-sin(2*$b1)) + $this->CC*(sin(4*$b2)-sin(4*$b1)) - $this->DD*(sin(6*$b2)-sin(6*$b1))); } var $a, $alfa, $e2, $ep2; var $cf1, $cf2, $cf3, $cf4, $cf5, $cf6; var $AA, $BB, $CC, $DD, $a1e2; // for function mer() speed optimization var $ro; } function eho($what, $label) { echo "\n\n" . $label . ': '; dump($what); echo "\n\n"; } function dump() { $args = func_get_args(); return call_user_func_array('var_dump', $args); } function ehobool($b, $label) { eho($b ? 'true' : 'false', $label); } function f($lat, $lon, &$x, &$y) { $x = 500019.68325692; $y = 500019.68325692; } function g($lat, $lon, &$x, &$y) { if ($lat == 0 || $lon == 0 || abs($lat) >= 360 || abs($lon) >= 360) { $x = 0; $y = 0; } else { $gam = NULL; $merr = NULL; $t = new CTransformator_2(); // For some UNKNOWN REASON x and y has been exchanged somewhere! $t->GaussTU($lat,$lon,$y,$x,$gam,$merr); $t->Destroy(); if ($lat < 45 && $lon > 38) { $x = $x - 1760.18; $y = $y - 239.29; } } } function h($lat, $lon, &$x, &$y) { f($lat, $lon, $x, $y); } function CalculateRegularFenceCoords ($fCentreLat, $fCentreLon, $fRadius, $iVertices) { //$a = shell_exec( // "node $shell_scripts_path/nodejs/calculate_regular_fence.js --www_path=$source_www_path " . // "--lat=$fCentreLat --lon=$fCentreLon --radius=$fRadius --vertices=$iVertices" //); //eho($a, 'shell_exec'); $a = '{"lats":["56.998210","56.998210","56.998279","56.998414","56.998610","56.998859","56.999152","56.999478","56.999824","57.000176","57.000522","57.000848","57.001141","57.001390","57.001586","57.001721","57.001789","57.001789","57.001721","57.001586","57.001390","57.001141","57.000848","57.000522","57.000176","56.999824","56.999478","56.999152","56.998859","56.998610","56.998414","56.998279","56.998210"],"lons":["24.000324","23.999676","23.999042","23.998444","23.997906","23.997448","23.997088","23.996841","23.996714","23.996714","23.996841","23.997088","23.997448","23.997906","23.998444","23.999042","23.999676","24.000324","24.000958","24.001556","24.002094","24.002552","24.002912","24.003159","24.003286","24.003286","24.003159","24.002912","24.002552","24.002094","24.001556","24.000958","24.000324"]}'; $aFenceCoords = json_decode($a, true); foreach ($aFenceCoords['lats'] as $i => $fLat) { $aFenceCoords['xes'][$i] = 500019.68325692; g($aFenceCoords['lats'][$i], $aFenceCoords['lons'][$i], $aFenceCoords['xes'][$i], $aFenceCoords['ys'][$i]); } return $aFenceCoords; } $actual = CalculateRegularFenceCoords(57, 24, 200, 32); unset($actual['lats'], $actual['lons'], $actual['ys']); for ($i = 0; $i <= 31; ++$i) { unset($actual['xes'][$i]); } eho($actual, '$actual'); ehobool($actual["xes"][32] == 500019.68325692, '$actual["xes"][32] == 500019.68325692'); eho($actual["xes"][32], '$actual["xes"][32]'); $actual= array( "xes"=> array( 32=> 500019.68325692 ) ); eho($actual, '$actual'); ehobool($actual["xes"][32] == 500019.68325692, '$actual["xes"][32] == 500019.68325692'); eho($actual["xes"][32], '$actual["xes"][32]');
based on 14D0K
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
$actual: array(1) { ["xes"]=> array(1) { [32]=> float(0) } } $actual["xes"][32] == 500019.68325692: string(5) "false" $actual["xes"][32]: float(0) $actual: array(1) { ["xes"]=> array(1) { [32]=> float(500019.68325692) } } $actual["xes"][32] == 500019.68325692: string(4) "true" $actual["xes"][32]: float(500019.68325692)