Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
- Eric Gozzi <<eric.gozzi@arch.ethz.ch>> [@ericgozzi](https://github.com/ericgozzi)
- Daniel Nunes Locatelli <<nuneslocatelli@arch.ethz.ch>> [@daniel-locatelli](https://github.com/daniel-locatelli)
- Mengxi He <<m.he@lekolabs.com>> [@mengxihex](https://github.com/mengxihex)
- Arian Moeini [@ArianMoeini](https://github.com/ArianMoeini)
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added optional origin points to `Frame.worldXY()`, `Frame.worldYZ()`, and `Frame.worldZX()`.
* Added `TOL.update()` method for explicit global state modification.
* Added `TOL.temporary()` context manager for scoped changes.
* Added missing implementation of `Brep.to_polygons()` in `compas_rhino.geometry.RhinoBrep`.
Expand Down
33 changes: 27 additions & 6 deletions src/compas/geometry/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,14 @@ def axis_angle_vector(self):
# ==========================================================================

@classmethod
def worldXY(cls): # type: () -> Frame
def worldXY(cls, point=None): # type: (...) -> Frame
"""Construct the world XY frame.

Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`, optional
The origin of the frame. Defaults to the world origin.

Returns
-------
:class:`compas.geometry.Frame`
Expand All @@ -233,14 +238,21 @@ def worldXY(cls): # type: () -> Frame
Vector(x=1.000, y=0.000, z=0.000)
>>> print(frame.yaxis)
Vector(x=0.000, y=1.000, z=0.000)
>>> Frame.worldXY([1, 2, 3]).point
Point(x=1.000, y=2.000, z=3.000)

"""
return cls([0, 0, 0], [1, 0, 0], [0, 1, 0])
return cls(point if point is not None else [0, 0, 0], [1, 0, 0], [0, 1, 0])

@classmethod
def worldZX(cls): # type: () -> Frame
def worldZX(cls, point=None): # type: (...) -> Frame
"""Construct the world ZX frame.

Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`, optional
The origin of the frame. Defaults to the world origin.

Returns
-------
:class:`compas.geometry.Frame`
Expand All @@ -255,14 +267,21 @@ def worldZX(cls): # type: () -> Frame
Vector(x=0.000, y=0.000, z=1.000)
>>> print(frame.yaxis)
Vector(x=1.000, y=0.000, z=0.000)
>>> Frame.worldZX([1, 2, 3]).point
Point(x=1.000, y=2.000, z=3.000)

"""
return cls([0, 0, 0], [0, 0, 1], [1, 0, 0])
return cls(point if point is not None else [0, 0, 0], [0, 0, 1], [1, 0, 0])

@classmethod
def worldYZ(cls): # type: () -> Frame
def worldYZ(cls, point=None): # type: (...) -> Frame
"""Construct the world YZ frame.

Parameters
----------
point : [float, float, float] | :class:`compas.geometry.Point`, optional
The origin of the frame. Defaults to the world origin.

Returns
-------
:class:`compas.geometry.Frame`
Expand All @@ -277,9 +296,11 @@ def worldYZ(cls): # type: () -> Frame
Vector(x=0.000, y=1.000, z=0.000)
>>> print(frame.yaxis)
Vector(x=0.000, y=0.000, z=1.000)
>>> Frame.worldYZ([1, 2, 3]).point
Point(x=1.000, y=2.000, z=3.000)

"""
return cls([0, 0, 0], [0, 1, 0], [0, 0, 1])
return cls(point if point is not None else [0, 0, 0], [0, 1, 0], [0, 0, 1])

@classmethod
def from_points(cls, point, point_xaxis, point_xyplane): # type: (...) -> Frame
Expand Down
16 changes: 16 additions & 0 deletions tests/compas/geometry/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ def test_frame_predefined():
assert frame.yaxis == Vector(1, 0, 0)


@pytest.mark.parametrize("point", [[0.33, -1.66, 0.444], Point(0.33, -1.66, 0.444)])
@pytest.mark.parametrize(
"constructor,xaxis,yaxis",
[
(Frame.worldXY, Vector(1, 0, 0), Vector(0, 1, 0)),
(Frame.worldYZ, Vector(0, 1, 0), Vector(0, 0, 1)),
(Frame.worldZX, Vector(0, 0, 1), Vector(1, 0, 0)),
],
)
def test_frame_predefined_at_point(constructor, xaxis, yaxis, point):
frame = constructor(point)
assert frame.point == Point(0.33, -1.66, 0.444)
assert frame.xaxis == xaxis
assert frame.yaxis == yaxis


def test_interpolate_frame_start_end():
frame1 = Frame(Point(0, 0, 0), Vector(1, 0, 0), Vector(0, 1, 0))
frame2 = Frame(Point(1, 1, 1), Vector(0, 0, 1), Vector(0, 1, 0))
Expand Down
Loading