-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pablo Vasconez
committed
Nov 13, 2023
1 parent
fe1f72b
commit aee0588
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains 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,47 @@ | ||
from __future__ import annotations | ||
|
||
from plxcontroller.geometry_3d.point_3d import Point3D | ||
|
||
|
||
class Node3D: | ||
""" | ||
A class with information about a node in a 3D mesh. | ||
""" | ||
|
||
def __init__(self, node_id: int, point: Point3D) -> None: | ||
"""Initializes a Node3D instance. | ||
Parameters | ||
---------- | ||
node_id : int | ||
the id of the node in the mesh. | ||
point: Point3D | ||
the point where the node is located in the 3D space. | ||
Raises | ||
------ | ||
TypeError | ||
if any parameter is not of the expected type. | ||
""" | ||
# Validate types | ||
if not isinstance(node_id, int): | ||
raise TypeError( | ||
f"Unexpected type found for node_id. Expected int, but got {type(node_id)}." | ||
) | ||
if not isinstance(point, Point3D): | ||
raise TypeError( | ||
f"Unexpected type found for point. Expected Point3D, but got {type(point)}." | ||
) | ||
|
||
self._node_id = node_id | ||
self._point = point | ||
|
||
@property | ||
def node_id(self) -> int: | ||
"""Returns the id of the node in the mesh.""" | ||
return self._node_id | ||
|
||
@property | ||
def point(self) -> Point3D: | ||
"""Returns the point where the node is located in the 3D space.""" | ||
return self._point |
Empty file.
This file contains 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,22 @@ | ||
import pytest | ||
|
||
from plxcontroller.geometry_3d.point_3d import Point3D | ||
from plxcontroller.mesh_3d.node_3d import Node3D | ||
|
||
|
||
def test_mesh_3d() -> None: | ||
""" | ||
Tests the methods of the class Mesh3D. | ||
""" | ||
|
||
# Assert invalid input | ||
with pytest.raises(TypeError, match="Expected int"): | ||
Node3D(node_id="invalid input", point=Point3D(x=1.0, y=2.0, z=3.0)) | ||
|
||
with pytest.raises(TypeError, match="Expected Point3D"): | ||
Node3D(node_id=1, point="invalid input") | ||
|
||
# Assert instance is correct with valid input | ||
node = Node3D(node_id=1, point=Point3D(x=1.0, y=2.0, z=3.0)) | ||
assert node.node_id == 1 | ||
assert node.point.coordinates == (1.0, 2.0, 3.0) |