Skip to content

Creating ansys.geometry.core.misc.units submodule #71

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 24 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b1b4fe7
Change accuracy module of location to misc
RobPasMue Sep 8, 2022
4f33034
Rename test_accuracy module to test_misc_accuracy
RobPasMue Sep 8, 2022
5e31620
Changing basic units location and intiating units module
RobPasMue Sep 8, 2022
76c3883
Pre-commit formatting
RobPasMue Sep 8, 2022
0382bbe
Basic PhysicalQuantity class implementation
RobPasMue Sep 8, 2022
30f41df
Pre-commit checks
RobPasMue Sep 8, 2022
d30b089
Pre-commit checks
RobPasMue Sep 8, 2022
ee8e07a
Docstrings update
RobPasMue Sep 8, 2022
208d2c4
Common inheritance scheme for Point from PhysicalQuantity (WIP)
RobPasMue Sep 8, 2022
ba78df8
Merge branch 'main' into feat/refactor-units-code
RobPasMue Sep 9, 2022
11c4819
Refactoring PointXD classes to Point class
RobPasMue Sep 9, 2022
745acfd
Pre-commit checks
RobPasMue Sep 9, 2022
3e53404
Emphasize which class __init__ method is called
RobPasMue Sep 9, 2022
b06afee
Revert attempt
RobPasMue Sep 9, 2022
d4adcab
Adapting *VectorXD to *Vector classes
RobPasMue Sep 9, 2022
5bfa2fc
Test imports (apart from test_math)
RobPasMue Sep 9, 2022
75d464c
Adapting test_math (WIP - tests are failing)
RobPasMue Sep 9, 2022
c3079d9
Pre-commit checks
RobPasMue Sep 9, 2022
f90fdb6
Merge branch 'main' into feat/refactor-units-code
RobPasMue Sep 9, 2022
5081f5b
Solving bugs and adapting tests
RobPasMue Sep 9, 2022
b0db417
Update src/ansys/geometry/core/misc/units.py
RobPasMue Sep 10, 2022
9f0e20b
Change default point values from np.Inf to np.nan
RobPasMue Sep 10, 2022
2ad5d3f
Update src/ansys/geometry/core/math/constants.py
RobPasMue Sep 10, 2022
323762c
Update src/ansys/geometry/core/math/vector.py
RobPasMue Sep 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/ansys/geometry/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,3 @@

__version__ = importlib_metadata.version(__name__.replace(".", "-"))
"""The installed version of PyGeometry."""


# Units
# ------------------------------------------------------------------------------

from pint import UnitRegistry

UNITS = UnitRegistry()
"""Unit manager."""

UNIT_LENGTH = UNITS.meter
"""Default length unit for PyGeometry."""

UNIT_ANGLE = UNITS.radian
"""Default angle unit for PyGeometry."""
49 changes: 20 additions & 29 deletions src/ansys/geometry/core/math/__init__.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
"""PyGeometry math subpackage."""
import numpy as np

from ansys.geometry.core.math.constants import (
DEFAULT_POINT,
UNIT_VECTOR_X,
UNIT_VECTOR_Y,
UNIT_VECTOR_Z,
ZERO_VECTOR3D,
)
from ansys.geometry.core.math.frame import Frame
from ansys.geometry.core.math.matrix import Matrix, Matrix33, Matrix44
from ansys.geometry.core.math.plane import Plane
from ansys.geometry.core.math.point import Point2D, Point3D
from ansys.geometry.core.math.vector import (
QuantityVector2D,
QuantityVector3D,
UnitVector2D,
UnitVector3D,
Vector2D,
Vector3D,
)
from ansys.geometry.core.math.point import Point
from ansys.geometry.core.math.vector import QuantityVector, UnitVector, Vector

__all__ = [
"DEFAULT_POINT",
"UNIT_VECTOR_X",
"UNIT_VECTOR_Y",
"UNIT_VECTOR_Z",
"ZERO_VECTOR3D",
"Frame",
"Matrix",
"Matrix33",
"Matrix44",
"Plane",
"Point2D",
"Point3D",
"QuantityVector2D",
"QuantityVector3D",
"UnitVector2D",
"UnitVector3D",
"Vector2D",
"Vector3D",
"Point",
"QuantityVector",
"UnitVector",
"Vector",
]

UNIT_VECTOR_X = UnitVector3D([1, 0, 0])
"""Unit vector in the cartesian traditional X direction."""

UNIT_VECTOR_Y = UnitVector3D([0, 1, 0])
"""Unit vector in the cartesian traditional Y direction."""

UNIT_VECTOR_Z = UnitVector3D([0, 0, 1])
"""Unit vector in the cartesian traditional Z direction."""

ZERO_VECTOR3D = Vector3D([0, 0, 0])
"""Zero-valued Vector3D object."""
26 changes: 26 additions & 0 deletions src/ansys/geometry/core/math/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Mathematical constants for PyGeometry."""

from ansys.geometry.core.math.point import DEFAULT_POINT_VALUES, Point
from ansys.geometry.core.math.vector import UnitVector, Vector

DEFAULT_POINT = Point(DEFAULT_POINT_VALUES)
"""Default value for a 3D ``Point``."""

UNIT_VECTOR_X = UnitVector([1, 0, 0])
"""Unit vector in the cartesian traditional X direction."""

UNIT_VECTOR_Y = UnitVector([0, 1, 0])
"""Unit vector in the cartesian traditional Y direction."""

UNIT_VECTOR_Z = UnitVector([0, 0, 1])
"""Unit vector in the cartesian traditional Z direction."""

ZERO_VECTOR3D = Vector([0, 0, 0])
"""Zero-valued Vector object."""

# Define the numpy.ndarrays as read-only - just for the sake of being "safe"
DEFAULT_POINT.setflags(write=False)
UNIT_VECTOR_X.setflags(write=False)
UNIT_VECTOR_Y.setflags(write=False)
UNIT_VECTOR_Z.setflags(write=False)
ZERO_VECTOR3D.setflags(write=False)
38 changes: 19 additions & 19 deletions src/ansys/geometry/core/math/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import numpy as np

from ansys.geometry.core.math.point import Point3D
from ansys.geometry.core.math.vector import UnitVector3D, Vector3D
from ansys.geometry.core.math.point import Point
from ansys.geometry.core.math.vector import UnitVector, Vector
from ansys.geometry.core.misc.checks import check_type, check_type_equivalence
from ansys.geometry.core.typing import RealSequence

Expand All @@ -16,32 +16,32 @@ class Frame:

Parameters
----------
origin : Optional[Union[~numpy.ndarray, RealSequence, Point3D]]
origin : Optional[Union[~numpy.ndarray, RealSequence, Point]]
Centered origin of the ``Frame``. By default, cartesian origin.
direction_x: Optional[Union[~numpy.ndarray, RealSequence, UnitVector3D, Vector3D]]
direction_x: Optional[Union[~numpy.ndarray, RealSequence, UnitVector, Vector]]
X-axis direction. By default, ``UNIT_VECTOR_X``
direction_y: Optional[Union[~numpy.ndarray, RealSequence, UnitVector3D, Vector3D]]
direction_y: Optional[Union[~numpy.ndarray, RealSequence, UnitVector, Vector]]
Y-axis direction. By default, ``UNIT_VECTOR_Y``
"""

def __init__(
self,
origin: Union[np.ndarray, RealSequence, Point3D] = [0, 0, 0],
direction_x: Union[np.ndarray, RealSequence, UnitVector3D, Vector3D] = [1, 0, 0],
direction_y: Union[np.ndarray, RealSequence, UnitVector3D, Vector3D] = [0, 1, 0],
origin: Union[np.ndarray, RealSequence, Point] = [0, 0, 0],
direction_x: Union[np.ndarray, RealSequence, UnitVector, Vector] = [1, 0, 0],
direction_y: Union[np.ndarray, RealSequence, UnitVector, Vector] = [0, 1, 0],
):
"""Constructor method for ``Frame``."""

check_type(origin, (np.ndarray, List, Point3D))
check_type(direction_x, (np.ndarray, List, UnitVector3D, Vector3D))
check_type(direction_y, (np.ndarray, List, UnitVector3D, Vector3D))
check_type(origin, (np.ndarray, List, Point))
check_type(direction_x, (np.ndarray, List, UnitVector, Vector))
check_type(direction_y, (np.ndarray, List, UnitVector, Vector))

self._origin = Point3D(origin) if not isinstance(origin, Point3D) else origin
self._origin = Point(origin) if not isinstance(origin, Point) else origin
self._direction_x = (
UnitVector3D(direction_x) if not isinstance(direction_x, UnitVector3D) else direction_x
UnitVector(direction_x) if not isinstance(direction_x, UnitVector) else direction_x
)
self._direction_y = (
UnitVector3D(direction_y) if not isinstance(direction_y, UnitVector3D) else direction_y
UnitVector(direction_y) if not isinstance(direction_y, UnitVector) else direction_y
)

# origin is fixed once the frame is built
Expand All @@ -50,25 +50,25 @@ def __init__(
if not self._direction_x.is_perpendicular_to(self._direction_y):
raise ValueError("Direction x and direction y must be perpendicular")

self._direction_z = UnitVector3D(self._direction_x % self._direction_y)
self._direction_z = UnitVector(self._direction_x % self._direction_y)

@property
def origin(self) -> Point3D:
def origin(self) -> Point:
"""Return the origin of the ``Frame``."""
return self._origin

@property
def direction_x(self) -> UnitVector3D:
def direction_x(self) -> UnitVector:
"""Return the X-axis direction of the ``Frame``."""
return self._direction_x

@property
def direction_y(self) -> UnitVector3D:
def direction_y(self) -> UnitVector:
"""Return the Y-axis direction of the ``Frame``."""
return self._direction_y

@property
def direction_z(self) -> UnitVector3D:
def direction_z(self) -> UnitVector:
"""Return the Z-axis direction of the ``Frame``."""
return self._direction_z

Expand Down
16 changes: 8 additions & 8 deletions src/ansys/geometry/core/math/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import numpy as np

from ansys.geometry.core.math.frame import Frame
from ansys.geometry.core.math.point import Point3D
from ansys.geometry.core.math.vector import UnitVector3D, Vector3D
from ansys.geometry.core.math.point import Point
from ansys.geometry.core.math.vector import UnitVector, Vector
from ansys.geometry.core.typing import RealSequence


Expand All @@ -16,19 +16,19 @@ class Plane(Frame):

Parameters
----------
origin : Optional[Union[~numpy.ndarray, RealSequence, Point3D]]
origin : Optional[Union[~numpy.ndarray, RealSequence, Point]]
Centered origin of the ``Frame``. By default, cartesian origin.
direction_x: Optional[Union[~numpy.ndarray, RealSequence, UnitVector3D, Vector3D]]
direction_x: Optional[Union[~numpy.ndarray, RealSequence, UnitVector, Vector]]
X-axis direction. By default, ``UNIT_VECTOR_X``
direction_y: Optional[Union[~numpy.ndarray, RealSequence, UnitVector3D, Vector3D]]
direction_y: Optional[Union[~numpy.ndarray, RealSequence, UnitVector, Vector]]
Y-axis direction. By default, ``UNIT_VECTOR_Y``
"""

def __init__(
self,
origin: Union[np.ndarray, RealSequence, Point3D] = [0, 0, 0],
direction_x: Union[np.ndarray, RealSequence, UnitVector3D, Vector3D] = [1, 0, 0],
direction_y: Union[np.ndarray, RealSequence, UnitVector3D, Vector3D] = [0, 1, 0],
origin: Union[np.ndarray, RealSequence, Point] = [0, 0, 0],
direction_x: Union[np.ndarray, RealSequence, UnitVector, Vector] = [1, 0, 0],
direction_y: Union[np.ndarray, RealSequence, UnitVector, Vector] = [0, 1, 0],
):
"""Constructor method for ``Plane``."""
super().__init__(origin, direction_x, direction_y)
Loading