示例#1
0
 static function do_hash($s)
 {
     $b = 378551;
     $a = 63689;
     $hash = 0;
     $i = 0;
     $_g1 = 0;
     $_g = strlen($s);
     while ($_g1 < $_g) {
         $i1 = $_g1++;
         $hash = $hash * $a + _hx_char_code_at($s, $i1);
         $a = $a * $b;
         unset($i1);
     }
     return Math::abs($hash);
 }
示例#2
0
 static function getMoonTimes($date, $lat, $lng, $inUTC = null)
 {
     if ($inUTC === null) {
         $inUTC = false;
     }
     if ($inUTC) {
         $this1 = datetime__DateTime_DateTime_Impl_::utc(suncalc_SunCalc_0($date, $inUTC, $lat, $lng));
         $date = Date::fromTime(($this1 - 62135596800.0) * 1000);
         $date = new Date($date->getFullYear(), $date->getMonth(), $date->getDate(), 0, 0, 0);
     } else {
         $date = new Date($date->getFullYear(), $date->getMonth(), $date->getDate(), 0, 0, 0);
     }
     $hc = 0.133 * suncalc_SunCalc::$rad;
     $h0 = suncalc_SunCalc::getMoonPosition($date, $lat, $lng)->altitude - $hc;
     $h1 = null;
     $h2 = null;
     $rise = 0.0;
     $set = 0.0;
     $a = null;
     $b = null;
     $xe = null;
     $ye = 0.0;
     $d = null;
     $roots = null;
     $x1 = 0.0;
     $x2 = 0.0;
     $dx = null;
     $i = 1;
     while ($i <= 24) {
         $h1 = suncalc_SunCalc::getMoonPosition(suncalc_SunCalc::hoursLater($date, $i), $lat, $lng)->altitude - $hc;
         $h2 = suncalc_SunCalc::getMoonPosition(suncalc_SunCalc::hoursLater($date, $i + 1), $lat, $lng)->altitude - $hc;
         $a = ($h0 + $h2) / 2 - $h1;
         $b = ($h2 - $h0) / 2;
         $xe = -$b / (2 * $a);
         $ye = ($a * $xe + $b) * $xe + $h1;
         $d = $b * $b - 4 * $a * $h1;
         $roots = 0;
         if ($d >= 0) {
             $dx = Math::sqrt($d) / (Math::abs($a) * 2);
             $x1 = $xe - $dx;
             $x2 = $xe + $dx;
             if (Math::abs($x1) <= 1) {
                 $roots++;
             }
             if (Math::abs($x2) <= 1) {
                 $roots++;
             }
             if ($x1 < -1) {
                 $x1 = $x2;
             }
         }
         if ($roots === 1) {
             if ($h0 < 0) {
                 $rise = $i + $x1;
             } else {
                 $set = $i + $x1;
             }
         } else {
             if ($roots === 2) {
                 $rise = $i + ($ye < 0 ? $x2 : $x1);
                 $set = $i + ($ye < 0 ? $x1 : $x2);
             }
         }
         if (!_hx_equal($rise, 0) && !_hx_equal($set, 0)) {
             break;
         }
         $h0 = $h2;
         $i += 2;
     }
     $result = new haxe_ds_StringMap();
     if (!_hx_equal($rise, 0)) {
         $v = suncalc_SunCalc::hoursLater($date, $rise);
         $result->set("rise", $v);
         $v;
     }
     if (!_hx_equal($set, 0)) {
         $v1 = suncalc_SunCalc::hoursLater($date, $set);
         $result->set("set", $v1);
         $v1;
     }
     if (_hx_equal($rise, 0) && _hx_equal($set, 0)) {
         $result->set($ye > 0 ? "alwaysUp" : "alwaysDown", true);
         true;
     }
     return $result;
 }