Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latitude more than 65: Error value should not be infinite or NaN #37

Open
alhamri opened this issue Jun 29, 2022 · 4 comments
Open

latitude more than 65: Error value should not be infinite or NaN #37

alhamri opened this issue Jun 29, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@alhamri
Copy link

alhamri commented Jun 29, 2022

Describe the bug
latitude values between (-67.5944046 and -90) and between (65.9277379 and 90)
throw Unhandled exception!

To Reproduce
minimum code that reproduce the error:

import 'package:adhan/adhan.dart';

void main() async {

  //latitude values between (-67.5944046 and -90) and between (65.9277379 and 90)
  //throw Unhandled exception!

  // var prayerTimes = PrayerTimes(Coordinates(-67.5944046, 120),
  //     DateComponents.from(DateTime.now()), CalculationMethod.umm_al_qura.getParameters());
  var prayerTimes = PrayerTimes(Coordinates(65.9277379, 120),
      DateComponents.from(DateTime.now()), CalculationMethod.umm_al_qura.getParameters());
  print(prayerTimes.fajr);
}

Expected behavior
should output the actual time of the giving parameters.

but it throws an error:

C:/Flutter_SDK/flutter/bin/cache/dart-sdk/bin/dart.exe --enable-asserts "E:\Flutter_UI\hij_greg_temp - Copy\lib\main.dart"
Unhandled exception:
Invalid argument(s): value should not be infinite or NaN
#0      TimeComponents.fromDouble (package:adhan/src/data/time_components.dart:12:7)
#1      new PrayerTimes._ (package:adhan/src/prayer_times.dart:133:37)
#2      new PrayerTimes (package:adhan/src/prayer_times.dart:53:24)
#3      main (package:hij_greg_temp/main.dart:10:21)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

Process finished with exit code 255

run flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, 3.1.0-9.0.pre, on Microsoft Windows [Version 10.0.19043.1766], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[√] Chrome - develop for the web
[!] Visual Studio - develop for Windows (Visual Studio Enterprise 2019 16.11.1)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2021.1)
[√] Android Studio (version 4.1)
[√] Android Studio (version 4.2)
[√] VS Code (version 1.68.1)
[√] Connected device (4 available)
[√] HTTP Host Availability

! Doctor found issues in 1 category.

Environment(please complete the following information):

  • Adhan-Dart Version: [adhan: ^2.0.0-nullsafety.2]
@alhamri alhamri added the bug Something isn't working label Jun 29, 2022
@pk-acl
Copy link

pk-acl commented Jun 29, 2022

The error happens, because on the calculation of Astronomical.correctedHourAngle for sunrise with the coordinates given, the value passed to calculate degree is -1.0000000008014773. This is impossible to achieve hence error occurs.

@PK2011 PK2011 mentioned this issue Jun 29, 2022
Closed
@alhamri
Copy link
Author

alhamri commented Jun 29, 2022

The error happens, because on the calculation of Astronomical.correctedHourAngle for sunrise with the coordinates given, the value passed to calculate degree is -1.0000000008014773. This is impossible to achieve hence error occurs.

yes the bug is there. I tried to solve it in the plugin by checking the value passed to acos function:
if it is less than -1, assign -1 to the value
if it is greater than 1, assign 1 to the value.

snippet code (before changing):

final term1 = sin(radians(h0)) -
        (sin(radians(coordinates.latitude)) * sin(radians(delta2)));
final term2 = cos(radians(coordinates.latitude)) * cos(radians(delta2));
final H0 = degrees(acos(term1 / term2));
final m = afterTransit ? m0 + (H0 / 360) : m0 - (H0 / 360);

snippet code (after changing):

final term1 = sin(radians(h0)) -
        (sin(radians(coordinates.latitude)) * sin(radians(delta2)));
final term2 = cos(radians(coordinates.latitude)) * cos(radians(delta2));
var y = term1 / term2;
if(y < -1.0) y = -1.0;
if(y > 1.0) y = 1.0;
final H0 = degrees(acos(y));
final m = afterTransit ? m0 + (H0 / 360) : m0 - (H0 / 360);

the exception is gone and it worked as expected, but i am not sure if the time given is correct or not?

@alhamri alhamri closed this as completed Jul 11, 2022
@alhamri alhamri reopened this Aug 6, 2022
@JMApps
Copy link

JMApps commented Jan 31, 2023

Have you found a solution? At the moment, the library throws an exception if the latitude is greater than 73 degrees

@iamriajul
Copy link
Owner

iamriajul commented Sep 22, 2023

final term1 = sin(radians(h0)) -
(sin(radians(coordinates.latitude)) * sin(radians(delta2)));
final term2 = cos(radians(coordinates.latitude)) * cos(radians(delta2));
var y = term1 / term2;
if(y < -1.0) y = -1.0;
if(y > 1.0) y = 1.0;
final H0 = degrees(acos(y));
final m = afterTransit ? m0 + (H0 / 360) : m0 - (H0 / 360);

Changes are causing tests to fail!

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants