패키지, 저장소 및 앱 카테고리 검색

패키지 상세v4.1.0+2.10.3

sweph

Flutter용 크로스플랫폼 스위스 에페메리스 API 바인딩.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
23
좋아요
27
Pub 점수
150

패키지 설치

flutter pub add sweph

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Sweph는 고정밀 천문학 라이브러리인 스위스 에페메리스를 위한 크로스플랫폼 Dart 바인딩을 제공합니다. 행성 위치, 일식 및 기타 천체 사건을 계산하는 데 사용됩니다. Flutter 애플리케이션에서 안드로이드, iOS, 웹, macOS, Windows, 리눅스에서 정확한 천문학적 계산을 수행할 수 있게 해줍니다. 원래의 C 기반 스위스 에페메리스 API를 감싸며 최소한의 오버헤드로 Dart에서 접근 가능하게 합니다. 점성 계산, 천문학 도구 또는 시간 기반 천체 데이터가 필요한 앱에 적합합니다.

사용 사례

  • 역학 애플리케이션
  • 천문학 및 우주 교육 도구
  • 시간 기반 천체 이벤트 예측
  • 캘린더 및 별자리 생성기
  • 행성 운동을 포함한 과학적 시뮬레이션

주요 기능

  • 고정밀 천체 위치 계산
  • 다중 플랫폼 지원
  • C 바인딩을 통한 네이티브 성능
  • 주요 행성과 소행성에 대한 지원
  • Flutter 앱과의 간편한 통합

적합한 대상

  • 운세 앱을 개발하는 개발자
  • 천문학 교육 소프트웨어
  • 정확한 천체 데이터가 필요한 앱
  • 크로스 플랫폼 과학 도구

고려 사항

  • 천문학적 개념을 이해해야 합니다
  • 기본 사용법을 넘어서는 문서가 제한적
  • 비-Flutter 환경을 위한 추가 설정이 필요할 수 있습니다
  • 완전한 기능을 위해 네이티브 C 라이브러리에 의존합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Sweph

Cross-platform bindings of Swiss Ephemeris APIs for Dart & Flutter. Everything you need to create Astrology and Astronomy applications with Dart and Flutter.

  • 100% API coverage
  • Dart friendly parameters and return values
  • Supported on all platforms. Uses dart:ffi for non-Web platforms and universal_ffi / wasm_ffi for Web
  • Original Swiss Ephemeris version used as build number for reference

References:

Usage example

import 'package:sweph/sweph.dart';

Future<void> main() async {
  // Sweph comes bundled with some ephe files. These are available for Flutter but not for vanilla Dart.
  // These or any other bundled ephe files can be initialized during Sweph.init.
  // For non-Web platforms, these are copied to the epheFilesPath (e.g. <ApplicationSupportDirectory>/ephe_files).
  // For Web, this is the only way to provide ephe files, and they are loaded into Wasm memory.
  // NOTE: For standard Flutter apps, omit `modulePath` (it defaults to null to use native plugin loading).
  await Sweph.init(
    epheAssets: [
      "packages/sweph/assets/ephe/sefstars.txt",
    ],
    assetLoader: SomeLoader(), // platform-specific asset loader (e.g. rootBundle).
    epheFilesPath: 'ephe_files', // where to store ephe files.
  );
  // refer to example. Both Flutter and vanilla Dart examples are available

  // alternately if a folder already contains ephe files, Sweph can be used in sync mode like this:
  // await Sweph.swe_set_ephe_path(<path-to-existing-folder>)
  // This is not available for Web

  print('sweph.swe_version = ${Sweph.swe_version()}');
  print('Moon longitude on 2022-06-29 02:52:00 UTC = ${Sweph.swe_calc_ut(Sweph.swe_julday(2022, 6, 29, (2 + 52 / 60), CalendarType.SE_GREG_CAL), HeavenlyBody.SE_MOON, SwephFlag.SEFLG_SWIEPH).longitude}');

  // Most methods use positional parameters, not named. So if some positional parameters take default values, please refer to original documentation
  // If only some specific flags are allowed for a method, it is restricted via the enumerated flags
  // For example, to set the sidereal mode to Lahiri with projection onto solar system plane and custom t0 in UT
  Sweph.swe_set_sid_mode(SiderealMode.SE_SIDM_LAHIRI, SiderealModeFlag.SE_SIDBIT_SSY_PLANE, 123.45 /* t0 */);
  // or, to set the sidereal mode to Lahiri with no flags and custom ayan_t0 in UT
  Sweph.swe_set_sid_mode(SiderealMode.SE_SIDM_LAHIRI, SiderealModeFlag.SE_SIDBIT_NONE, 0.0 /* t0 */, 987.65 /* ayan_t0 */);
}

Licensing

This library follows the licensing model of the Swiss Ephemeris by Astrodienst AG. Detailed information and material classification are documented in LICENSING.md.

AGPL-3.0-only (Open Source Path)

By default, this package and the bundled Swiss Ephemeris code are licensed under the GNU Affero General Public License Version 3 (AGPL-3.0-only).

LGPL-3.0-only (Professional License Path)

For users who hold an applicable Swiss Ephemeris Professional License purchased directly from Astrodienst AG:

  • Clearly maintainer-authored portions of sweph.dart may additionally be used under LGPL-3.0-only.
  • This grant does not relicense material owned by Astrodienst AG (Swiss Ephemeris C source, ephemeris data files, and derived binaries remain governed by your Astrodienst license agreement).
  • See LICENSING.md for exact material classifications, notice preservation rules, and version-specific declarations (such as doc/licensing/3.2.1+2.10.3.md).

Versioning

This package integrates the upstream Swiss Ephemeris version into its composite version string using the format:

<package_version>+<sweph_version>

For example, in 4.0.0+2.10.3:

  • Package Version (4.0.0): Follows Semantic Versioning (SemVer) for Dart/Flutter wrapper APIs, platform integrations, build tooling, and package-level features or fixes:
    • Major: Breaking API changes, major platform requirement shifts, or major toolchain updates.
    • Minor: Backward-compatible new functionality or wrapper enhancements.
    • Patch: Backward-compatible bug fixes and minor adjustments.
  • Build Number (+2.10.3): Denotes the exact upstream Swiss Ephemeris C library version bundled in the release (extracted directly from SE_VERSION in native/sweph/src/sweph.h). Whenever the underlying Swiss Ephemeris C sources are upgraded, this build component is updated to reflect the upstream calculation engine version.

Platform build files (pubspec.yaml, iOS/macOS Podspecs, Android Gradle, and Linux/Windows CMake) are synchronized automatically via tool/bump_version.dart.

Ephemeris files

The following ephemeris files are bundled with this plugin:

  • seas_18.se1 - main ephemeris for asteroids (1800-2400 CE)
  • semo_18.se1 - main ephemeris for moon (1800-2400 CE)
  • sepl_18.se1 - main ephemeris for planets (1800-2400 CE)
  • seasnam.txt - list of asteroids
  • sefstars.txt - fixed stars data file
  • seleapsec.txt - dates of leap seconds to be taken into account
  • seorbel.txt - orbital elements of ficticious planets :)

These could also be download from https://www.astro.com/ftp/swisseph/ephe/. More information can be found in the Swiss Ephemeris files documentation.

Platform Support and Packaging

Sweph supports all Flutter platforms:

  • macOS & iOS: Fully supports both Swift Package Manager (default in Flutter 3.44+) and CocoaPods. Package.swift manifests are included for each platform, compiling the canonical C sources cleanly as dynamic frameworks.
  • Android: Modernized Gradle build supporting 16 KB page sizes with NDK r28 and compileSdk 36.
  • Linux & Windows: CMake-based native library compilation.
  • Web: Compiled to WebAssembly using Emscripten and standalone Wasm, loaded via universal_ffi / wasm_ffi, and fully supported under both dart2js (normal Flutter Web) and dart2wasm (Flutter Web with --wasm).
Native Library Loading

In ordinary Flutter applications, simply call Sweph.init() without specifying a modulePath:

await Sweph.init();

Flutter's plugin loader handles resolution of the native shared library/framework on all platforms automatically.

For custom standalone Dart CLI scripts, desktop builds without Flutter tooling, or custom library paths, you can provide an explicit path:

await Sweph.init(modulePath: '/path/to/libsweph.dylib');

Alternatively, set the SWEPH_DYLIB_PATH environment variable.

Testing with flutter_test

Because flutter test executes in a headless host test runner (flutter_tester) that does not automatically build or bundle native platform frameworks into @rpath:

  1. Sweph.init() includes automatic fallback resolution: if the application was previously built (via flutter build macos, flutter run, etc.), Sweph.init() locates the compiled framework in the project's build output (build/macos/Build/Products/...) and loads it seamlessly.
  2. Alternatively, specify an explicit library location via Sweph.init(modulePath: ...) or the SWEPH_DYLIB_PATH environment variable.
  3. For pure Dart unit tests that do not need Swiss Ephemeris calculations, you can test higher-level logic independently, or run integration tests via flutter test integration_test where the full native application bundle is executed.

Using bundled Ephemeris files

Sweph.init accepts a list of ephemeris files as assets. These could be any of the bundled ones or other app assets. It does not accept local file path!

non-Web

These are cached in <ApplicationSupportDirectory>/ephe_files folder. First load will be slow. Async methods swe_set_ephe_path & swe_set_jpl_file could be called to set new ephe files. If file already present, it is not overwritten, unless forceOverwrite is true.

Web

Sweph.init is the only way to provide ephe files, and they are loaded into Wasm memory during initialization. This is a limitation of the Web plugin. Calls to swe_set_ephe_path have no effect on Web. Only the loaded assets are used. If custom JPL files are needed, they need to be loaded with the name "jpl_file.eph" during init and swe_set_jpl_file could be called.

Contributing

If you find any innacuracy or bug in this library, or if you find an update that is not yet included in this library, feel free to open an issue or a pull request.

Known Issues and Caveats

  • The included ephe files are available async only
  • Due to how the underlying C library operates, you may find that the error field returned by some functions will contain random data even if there is no actual error. This can happen when existing memory buffers are recycled therefore the user must always check the returned flag values as per the Swiss Ephemeris documentation.

Author

Copyright © 2022, VM75

카테고리

의존성

의존성 목록 2 개

  • path^1.9.0
  • universal_ffi^1.5.1

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.