Skip to content

Commit

Permalink
feat(#25): add class Node3D.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Vasconez committed Nov 13, 2023
1 parent fe1f72b commit aee0588
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Empty file.
47 changes: 47 additions & 0 deletions src/plxcontroller/mesh_3d/node_3d.py
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 added tests/test_mesh_3d/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions tests/test_mesh_3d/test_node_3d.py
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)

0 comments on commit aee0588

Please sign in to comment.