-
Notifications
You must be signed in to change notification settings - Fork 7
feat: bindings for physics data classes #210
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba29c7f
feat: add bindings for Data
e3bf5a2
feat: add bindings for Direction
1546b8d
feat: add python tests
9cfe653
feat: fix test
vishwa2710 79ea8e9
feat: fix test
vishwa2710 5b4909b
Apply suggestions from code review
vishwa2710 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// Apache License 2.0 | ||
|
||
#include <OpenSpaceToolkitPhysicsPy/Data/Scalar.cpp> | ||
#include <OpenSpaceToolkitPhysicsPy/Data/Vector.cpp> | ||
#include <OpenSpaceToolkitPhysicsPy/Data/Direction.cpp> | ||
|
||
inline void OpenSpaceToolkitPhysicsPy_Data(pybind11::module& aModule) | ||
{ | ||
using namespace pybind11; | ||
|
||
// Create "data" python submodule | ||
auto data = aModule.def_submodule("data"); | ||
|
||
// Add objects to python "data" submodules | ||
OpenSpaceToolkitPhysicsPy_Data_Scalar(data); | ||
OpenSpaceToolkitPhysicsPy_Data_Vector(data); | ||
OpenSpaceToolkitPhysicsPy_Data_Direction(data); | ||
} |
31 changes: 31 additions & 0 deletions
31
bindings/python/src/OpenSpaceToolkitPhysicsPy/Data/Direction.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/// Apache License 2.0 | ||
|
||
#include <OpenSpaceToolkit/Physics/Data/Direction.hpp> | ||
|
||
inline void OpenSpaceToolkitPhysicsPy_Data_Direction(pybind11::module& aModule) | ||
{ | ||
using namespace pybind11; | ||
|
||
using ostk::core::type::Shared; | ||
|
||
using ostk::mathematics::object::Vector3d; | ||
|
||
using ostk::physics::Unit; | ||
using ostk::physics::coordinate::Frame; | ||
using ostk::physics::data::Direction; | ||
using ostk::physics::data::Vector; | ||
|
||
class_<Direction, Vector>(aModule, "Direction") | ||
|
||
.def(init<const Vector3d&, const Shared<const Frame>&>(), arg("value"), arg("frame")) | ||
|
||
.def(self == self) | ||
.def(self != self) | ||
|
||
.def("__str__", &(shiftToString<Direction>)) | ||
.def("__repr__", &(shiftToString<Direction>)) | ||
|
||
.def_static("undefined", &Direction::Undefined) | ||
|
||
; | ||
} |
34 changes: 34 additions & 0 deletions
34
bindings/python/src/OpenSpaceToolkitPhysicsPy/Data/Scalar.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// Apache License 2.0 | ||
|
||
#include <OpenSpaceToolkit/Physics/Data/Scalar.hpp> | ||
|
||
inline void OpenSpaceToolkitPhysicsPy_Data_Scalar(pybind11::module& aModule) | ||
{ | ||
using namespace pybind11; | ||
|
||
using ostk::core::type::Real; | ||
using ostk::core::type::Integer; | ||
|
||
using ostk::physics::Unit; | ||
using ostk::physics::data::Scalar; | ||
|
||
class_<Scalar>(aModule, "Scalar") | ||
|
||
.def(init<const Real&, const Unit&>(), arg("value"), arg("unit")) | ||
|
||
.def(self == self) | ||
.def(self != self) | ||
|
||
.def("__str__", &(shiftToString<Scalar>)) | ||
.def("__repr__", &(shiftToString<Scalar>)) | ||
|
||
.def("is_defined", &Scalar::isDefined) | ||
.def("get_value", &Scalar::getValue) | ||
.def("get_unit", &Scalar::getUnit) | ||
.def("in_unit", &Scalar::inUnit, arg("unit")) | ||
.def("to_string", &Scalar::toString, arg("precision") = Integer::Undefined()) | ||
|
||
.def_static("undefined", &Scalar::Undefined) | ||
|
||
; | ||
} |
38 changes: 38 additions & 0 deletions
38
bindings/python/src/OpenSpaceToolkitPhysicsPy/Data/Vector.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/// Apache License 2.0 | ||
|
||
#include <OpenSpaceToolkit/Physics/Data/Vector.hpp> | ||
|
||
inline void OpenSpaceToolkitPhysicsPy_Data_Vector(pybind11::module& aModule) | ||
{ | ||
using namespace pybind11; | ||
|
||
using ostk::core::type::Shared; | ||
|
||
using ostk::mathematics::object::Vector3d; | ||
|
||
using ostk::physics::Unit; | ||
using ostk::physics::data::Vector; | ||
using ostk::physics::coordinate::Frame; | ||
|
||
class_<Vector>(aModule, "Vector") | ||
|
||
.def(init<const Vector3d&, const Unit&, const Shared<const Frame>&>(), arg("value"), arg("unit"), arg("frame")) | ||
|
||
.def(self == self) | ||
.def(self != self) | ||
|
||
.def("__str__", &(shiftToString<Vector>)) | ||
.def("__repr__", &(shiftToString<Vector>)) | ||
|
||
.def("is_defined", &Vector::isDefined) | ||
.def("get_value", &Vector::getValue) | ||
.def("get_unit", &Vector::getUnit) | ||
.def("get_frame", &Vector::getFrame) | ||
.def("in_unit", &Vector::inUnit, arg("unit")) | ||
.def("in_frame", &Vector::inFrame, arg("frame"), arg("instant")) | ||
.def("to_string", &Vector::toString, arg("precision") = 6) | ||
|
||
.def_static("undefined", &Vector::Undefined) | ||
|
||
; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Apache License 2.0 | ||
|
||
import pytest | ||
|
||
import numpy as np | ||
|
||
from ostk.physics.data import Direction | ||
from ostk.physics.coordinate import Frame | ||
|
||
|
||
@pytest.fixture | ||
def value() -> np.ndarray: | ||
return np.array([1.0, 0.0, 0.0]) | ||
|
||
|
||
@pytest.fixture | ||
def frame() -> Frame: | ||
return Frame.GCRF() | ||
|
||
|
||
@pytest.fixture | ||
def direction(value: float, frame: Frame) -> Direction: | ||
return Direction( | ||
value=value, | ||
frame=frame, | ||
) | ||
|
||
|
||
class TestDirection: | ||
def test_equals(self, direction: Direction): | ||
vishwa2710 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert direction == direction | ||
|
||
def test_not_equals(self, direction: Direction): | ||
assert (direction != direction) is False | ||
|
||
def test_undefined(self): | ||
assert Direction.undefined() is not None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Apache License 2.0 | ||
|
||
import pytest | ||
|
||
from ostk.physics import Unit | ||
from ostk.physics.data import Scalar | ||
from ostk.physics.unit import Length | ||
|
||
|
||
@pytest.fixture | ||
def unit() -> Unit: | ||
return Unit.length(Length.Unit.Meter) | ||
|
||
|
||
@pytest.fixture | ||
def value() -> float: | ||
return 5.0 | ||
|
||
|
||
@pytest.fixture | ||
def scalar(value: float, unit: Unit) -> Scalar: | ||
return Scalar( | ||
value=value, | ||
unit=unit, | ||
) | ||
|
||
|
||
class TestScalar: | ||
def test_equals(self, scalar: Scalar): | ||
vishwa2710 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert scalar == scalar | ||
|
||
def test_not_equals(self, scalar: Scalar): | ||
assert (scalar != scalar) is False | ||
|
||
def test_is_defined(self, scalar: Scalar): | ||
assert scalar.is_defined() | ||
|
||
def test_get_value(self, scalar: Scalar, value: float): | ||
assert scalar.get_value() == value | ||
|
||
def test_get_unit(self, scalar: Scalar): | ||
assert scalar.get_unit().is_defined() | ||
|
||
def test_in_unit(self, scalar: Scalar): | ||
assert scalar.in_unit(Unit.length(Length.Unit.Foot)) is not None | ||
|
||
def test_to_string(self, scalar: Scalar): | ||
assert scalar.to_string() is not None | ||
vishwa2710 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Apache License 2.0 | ||
|
||
import pytest | ||
|
||
import numpy as np | ||
|
||
from ostk.physics import Unit | ||
from ostk.physics.data import Vector | ||
from ostk.physics.unit import Length | ||
from ostk.physics.time import Instant | ||
from ostk.physics.coordinate import Frame | ||
|
||
|
||
@pytest.fixture | ||
def unit() -> Unit: | ||
return Unit.length(Length.Unit.Meter) | ||
|
||
|
||
@pytest.fixture | ||
def value() -> np.ndarray: | ||
return np.array([1.0, 2.0, 3.0]) | ||
|
||
|
||
@pytest.fixture | ||
def frame() -> Frame: | ||
return Frame.GCRF() | ||
|
||
|
||
@pytest.fixture | ||
def vector(value: float, unit: Unit, frame: Frame) -> Vector: | ||
return Vector( | ||
value=value, | ||
unit=unit, | ||
frame=frame, | ||
) | ||
|
||
|
||
class TestVector: | ||
def test_equals(self, vector: Vector): | ||
vishwa2710 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert vector == vector | ||
|
||
def test_not_equals(self, vector: Vector): | ||
assert (vector != vector) is False | ||
|
||
def test_is_defined(self, vector: Vector): | ||
assert vector.is_defined() | ||
|
||
def test_get_value(self, vector: Vector, value: float): | ||
assert np.all(vector.get_value() == value) | ||
|
||
def test_get_unit(self, vector: Vector): | ||
assert vector.get_unit().is_defined() | ||
|
||
def test_get_frame(self, vector: Vector, frame: Frame): | ||
assert vector.get_frame() == frame | ||
|
||
def test_in_unit(self, vector: Vector): | ||
assert vector.in_unit(Unit.length(Length.Unit.Foot)) is not None | ||
|
||
def test_in_frame(self, vector: Vector): | ||
assert vector.in_frame(Frame.ITRF(), Instant.J2000()) is not None | ||
|
||
def test_to_string(self, vector: Vector): | ||
assert vector.to_string() is not None | ||
vishwa2710 marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.