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

feat: lla FromPosition constructor #306

Merged
merged 5 commits into from
Jan 6, 2025

Conversation

vishwa2710
Copy link
Contributor

@vishwa2710 vishwa2710 commented Jan 4, 2025

Summary by CodeRabbit

  • New Features

    • Added from_lla method to Position class for creating position from latitude, longitude, and altitude
    • Added from_position method to LLA class for converting position to latitude, longitude, and altitude
    • Enhanced coordinate conversion capabilities between different representations
  • Tests

    • Added comprehensive test cases for new coordinate conversion methods
    • Improved error handling and validation for coordinate transformations
  • Documentation

    • Updated docstrings for improved clarity and consistency
    • Enhanced method descriptions for new coordinate-related functionality

@vishwa2710 vishwa2710 self-assigned this Jan 4, 2025
@vishwa2710 vishwa2710 linked an issue Jan 4, 2025 that may be closed by this pull request
Copy link

coderabbitai bot commented Jan 4, 2025

Walkthrough

The pull request introduces new methods for converting between Position and LLA (Latitude, Longitude, Altitude) coordinate representations in the Open Space Toolkit Physics library. Two new static methods are added: FromLLA in the Position class and FromPosition in the LLA class. These methods enable convenient coordinate transformations with optional celestial object specification, improving the library's coordinate conversion capabilities.

Changes

File Change Summary
bindings/python/src/OpenSpaceToolkitPhysicsPy/Coordinate/Position.cpp Added from_lla method with docstring updates
bindings/python/src/OpenSpaceToolkitPhysicsPy/Coordinate/Spherical/LLA.cpp Added from_position method
bindings/python/test/coordinate/spherical/test_lla.py Added test for from_position method
bindings/python/test/coordinate/test_position.py Refactored tests using fixtures, added test_from_lla
include/OpenSpaceToolkit/Physics/Coordinate/Position.hpp Added namespaces and FromLLA method declaration
include/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.hpp Added FromPosition method declaration
src/OpenSpaceToolkit/Physics/Coordinate/Position.cpp Implemented FromLLA method
src/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.cpp Implemented FromPosition method
test/OpenSpaceToolkit/Physics/Coordinate/Position.test.cpp Added FromLLA test case
test/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.test.cpp Added FromPosition test case

Sequence Diagram

sequenceDiagram
    participant User
    participant Position
    participant LLA
    participant Celestial
    participant Environment

    User->>Position: FromLLA(lla, celestial?)
    alt celestial not provided
        Position->>Environment: getGlobalInstance()
        Environment-->>Position: centralBody
    end
    Position->>Celestial: getEquatorialRadius()
    Position->>Celestial: getFlattening()
    Position->>Position: Convert LLA to Cartesian
    Position-->>User: Return Position

    User->>LLA: FromPosition(position, celestial?)
    alt celestial not provided
        LLA->>Environment: getGlobalInstance()
        Environment-->>LLA: centralBody
    end
    LLA->>Celestial: getEquatorialRadius()
    LLA->>Celestial: getFlattening()
    LLA->>LLA: Convert Position to LLA
    LLA-->>User: Return LLA
Loading

Possibly related issues

Poem

🐰 Coordinates dancing, a mathematical delight,
From LLA to Position, now converting with might!
Spherical to Cartesian, a transformation so neat,
With celestial guidance, our conversion is sweet! 🌍
Open Space Toolkit, making science take flight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (8)
test/Global.test.hpp (1)

16-33: Consolidate common numeric comparison logic.

These macros share logic that compares vector sizes and element differences. Consider extracting or refactoring the repeated comparison logic into a shared inline function for DRY (Don't Repeat Yourself) code, though macros can be more convenient in testing contexts.

include/OpenSpaceToolkit/Physics/Coordinate/Position.hpp (1)

166-174: Confirm usage of global environment references.

The FromLLA method references the global environment if aCelestialSPtr is null. While convenient, it introduces a hidden dependency that may complicate testing or multi-threaded scenarios if the global environment is modified concurrently.

bindings/python/test/coordinate/test_position.py (1)

100-101: Re-evaluate the skipped test.

The test_is_near method is currently skipped. If this test is outdated or incomplete, consider removing the skip or adding the pending scenarios to ensure coverage of the Position.is_near method.

src/OpenSpaceToolkit/Physics/Coordinate/Position.cpp (1)

222-225: Method signature well-intentioned, but please verify parameter naming consistency.
Consider changing aLLA to something like anLLA or lla for consistent parameter naming across other methods.

test/OpenSpaceToolkit/Physics/Coordinate/Position.test.cpp (1)

259-285: Comprehensive coverage of FromLLA.

  1. Tests undefined LLA → expected Undefined exception.
  2. Tests missing Celestial → expected runtime error.
  3. Tests valid Earth pointer → ensures correct Cartesian coords.
  4. Tests fallback to global environment → ensures correct fallback.
    Suggest adding an additional test for lat/long extremes (poles) if feasible.
include/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.hpp (1)

339-348: FromPosition method signature is clear and modular.

  1. Defaults to global environment’s central celestial if none provided.
  2. Matches existing pattern in Position::FromLLA.
    Consider clarifying that altitudes can be negative if below reference ellipsoid.
bindings/python/src/OpenSpaceToolkitPhysicsPy/Coordinate/Spherical/LLA.cpp (1)

417-432: Add a usage note for None as celestial.
Everything looks good in this newly introduced static method. However, consider noting in the docstring or code comments that passing None for celestial defers to the global environment's central celestial object, ensuring future maintainers are crystal-clear about this fallback mechanism.

src/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.cpp (1)

534-554: Check validity of ellipsoid parameters before converting.
This new FromPosition method is well-structured and properly checks for undefined inputs. However, consider verifying that the retrieved equatorialRadius and flattening from celestialSPtr are themselves defined; while unusual, an undefined radius or flattening might cause downstream runtime issues.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e534a8e and a589c0c.

📒 Files selected for processing (11)
  • bindings/python/src/OpenSpaceToolkitPhysicsPy/Coordinate/Position.cpp (9 hunks)
  • bindings/python/src/OpenSpaceToolkitPhysicsPy/Coordinate/Spherical/LLA.cpp (1 hunks)
  • bindings/python/test/coordinate/spherical/test_lla.py (2 hunks)
  • bindings/python/test/coordinate/test_position.py (1 hunks)
  • include/OpenSpaceToolkit/Physics/Coordinate/Position.hpp (3 hunks)
  • include/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.hpp (3 hunks)
  • src/OpenSpaceToolkit/Physics/Coordinate/Position.cpp (2 hunks)
  • src/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.cpp (2 hunks)
  • test/Global.test.hpp (1 hunks)
  • test/OpenSpaceToolkit/Physics/Coordinate/Position.test.cpp (3 hunks)
  • test/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.test.cpp (1 hunks)
🧰 Additional context used
📓 Learnings (2)
include/OpenSpaceToolkit/Physics/Coordinate/Position.hpp (1)
Learnt from: vishwa2710
PR: open-space-collective/open-space-toolkit-physics#278
File: src/OpenSpaceToolkit/Physics/Environment.cpp:46-46
Timestamp: 2024-11-12T02:57:39.443Z
Learning: In the `Environment` class, `aCentralCelestialObject` is a shared pointer to a `const Object`, ensuring immutability and preventing shared mutability concerns when assigning to `centralCelestialObject_`.
include/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.hpp (1)
Learnt from: vishwa2710
PR: open-space-collective/open-space-toolkit-physics#278
File: src/OpenSpaceToolkit/Physics/Environment.cpp:46-46
Timestamp: 2024-11-12T02:57:39.443Z
Learning: In the `Environment` class, `aCentralCelestialObject` is a shared pointer to a `const Object`, ensuring immutability and preventing shared mutability concerns when assigning to `centralCelestialObject_`.
🔇 Additional comments (20)
test/Global.test.hpp (1)

35-53: Be mindful of test severity differences.

Using FAIL() instead of ADD_FAILURE() in ASSERT_VECTORS_ALMOST_EQUAL can halt test execution, which makes sense for critical mismatches. Ensure this approach aligns with your testing philosophy, as it may prevent subsequent checks from running in the same test.

bindings/python/src/OpenSpaceToolkitPhysicsPy/Coordinate/Position.cpp (1)

202-217: Ensure robust error handling when celestial is undefined.

The from_lla method uses a default None for the celestial parameter, relying on the global environment if not provided. Consider explicitly raising an error if no valid celestial can be determined at runtime, to prevent silent failures or unexpected defaults.

src/OpenSpaceToolkit/Physics/Coordinate/Position.cpp (5)

10-12: Includes look appropriate.
The newly added headers are necessary for the LLA and Celestial object references.


226-229: Good validation for undefined LLA.
Throwing an exception is consistent with the rest of the codebase’s approach.


231-233: Verify fallback logic for celestial object.
Ensuring we retrieve the global environment's central celestial object is a good fallback.


235-238: Check for potential race conditions in retrieving global environment.
If the global environment could be reset in parallel, consider a locking mechanism or more robust check.

Would you like a shell script that searches for concurrent environment resets in the codebase?


240-242: Conversion logic appears correct and consistent with ITRF usage.
Given that altitudes can be negative, confirm that Earth flattening is accurate across negative altitudes as well.

test/OpenSpaceToolkit/Physics/Coordinate/Position.test.cpp (3)

5-6: New includes for Environment and Earth recognized.
They are essential for the new tests targeting the global environment usage.


17-19: Updated using statements look fine.
Bringing LLA, Environment, and Earth into scope is aligned with your new tests.


257-258: Test name is well chosen.
“FromLLA” indicates coverage of the new functionality.

bindings/python/test/coordinate/spherical/test_lla.py (5)

11-13: Imports are consistent and necessary.
They align with the new test methods referencing Position and Earth.


494-498: Setup for test_from_position is clear.
These lines define the Earth model, frame, and a sample equatorial position.


499-507: Validation of resulting LLA correctness is thorough.

  1. Latitude near zero → equator.
  2. Longitude near zero → prime meridian.
  3. Altitude near zero → up close to Earth's surface.

508-511: Undefined position test is valuable.
It confirms the method raises a runtime error when Position lacks definition.


512-514: Global environment test is well-structured.
This ensures coverage of the optional celestial pointer fallback.

include/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.hpp (4)

9-9: Added <OpenSpaceToolkit/Core/Type/Shared.hpp> is appropriate.
This is essential for the new Shared pointer usage.


23-31: New forward declarations for Celestial object.
This reduces overall compile times and is consistent with the environment folder structure.


34-36: Forward declaration of Position fosters loose coupling.
Avoiding direct includes helps keep compile units small.


43-43: Added Shared alias similarly used across codebase.
This matches code style in other classes.

test/OpenSpaceToolkit/Physics/Coordinate/Spherical/LLA.test.cpp (1)

1107-1139: Thorough test coverage for FromPosition.
Great job covering all relevant scenarios: valid conversion, undefined position, and null celestial with or without a global environment. Tests appear robust and validate the new method extensively.

bindings/python/test/coordinate/test_position.py Outdated Show resolved Hide resolved
@vishwa2710 vishwa2710 changed the base branch from main to feat/position-from-lla January 4, 2025 23:45
Copy link

codecov bot commented Jan 5, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 82.89%. Comparing base (fb96ac2) to head (a589c0c).
Report is 1 commits behind head on feat/position-from-lla.

Files with missing lines Patch % Lines
...nSpaceToolkit/Physics/Coordinate/Spherical/LLA.cpp 91.66% 1 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##           feat/position-from-lla     #306      +/-   ##
==========================================================
+ Coverage                   82.87%   82.89%   +0.01%     
==========================================================
  Files                         102      102              
  Lines                        8019     8031      +12     
==========================================================
+ Hits                         6646     6657      +11     
- Misses                       1373     1374       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@apaletta3 apaletta3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small nit

@vishwa2710 vishwa2710 merged commit 71dada3 into feat/position-from-lla Jan 6, 2025
14 checks passed
@vishwa2710 vishwa2710 deleted the feat/lla-from-position branch January 6, 2025 17:11
vishwa2710 added a commit that referenced this pull request Jan 6, 2025
* feat: Add FromPosition static constructor to LLA class

* feat: Add FromPosition test case for LLA coordinate conversion

* feat: Add FromPosition method tests for LLA Python bindings

* test: Add FromPosition test for LLA coordinate conversion

* feat: add tests for from position
vishwa2710 added a commit that referenced this pull request Jan 6, 2025
* feat: FromLLA constructor for position

* chore: style

* feat: lla FromPosition constructor (#306)

* feat: Add FromPosition static constructor to LLA class

* feat: Add FromPosition test case for LLA coordinate conversion

* feat: Add FromPosition method tests for LLA Python bindings

* test: Add FromPosition test for LLA coordinate conversion

* feat: add tests for from position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] add convenience method to create an LLA from position
3 participants