Skip to content
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

Various fixes #40

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions src/rod/sdf/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def serialize_float(data: float) -> str:
@staticmethod
def serialize_list(data: list[float]) -> str:
assert isinstance(data, list)
return " ".join(np.array(data, dtype=str))
return " ".join(np.array(data, dtype=float).astype(str))
diegoferigo marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def deserialize_list(data: str, length: int | None = None) -> list[float]:
Expand All @@ -57,4 +57,4 @@ def deserialize_list(data: str, length: int | None = None) -> list[float]:
if length is not None:
assert array.size == length

return list(array)
return array.tolist()
31 changes: 28 additions & 3 deletions src/rod/sdf/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,34 @@ class Sphere(Element):
class Geometry(Element):
box: Box | None = dataclasses.field(default=None)
capsule: Capsule | None = dataclasses.field(default=None)
cylinder: Capsule | None = dataclasses.field(default=None)
ellipsoid: Capsule | None = dataclasses.field(default=None)
cylinder: Cylinder | None = dataclasses.field(default=None)
ellipsoid: Ellipsoid | None = dataclasses.field(default=None)
heightmap: Heightmap | None = dataclasses.field(default=None)
mesh: Mesh | None = dataclasses.field(default=None)
plane: Mesh | None = dataclasses.field(default=None)
plane: Plane | None = dataclasses.field(default=None)
sphere: Sphere | None = dataclasses.field(default=None)

def geometries(
self,
) -> list[Box | Capsule | Cylinder | Ellipsoid | Heightmap | Mesh | Plane | Sphere]:
diegoferigo marked this conversation as resolved.
Show resolved Hide resolved

return [
self.__getattribute__(field.name)
for field in dataclasses.fields(self)
if self.__getattribute__(field.name) is not None
]

def geometry(
self,
) -> (
Box | Capsule | Cylinder | Ellipsoid | Heightmap | Mesh | Plane | Sphere | None
):
"""Return the actual shape of the geometry object"""

geometries = self.geometries()

if len(geometries) > 1:
msg = "More than one geometry found, returning the first one"
logging.warning(msg)

return geometries[0] if len(geometries) > 0 else None
11 changes: 7 additions & 4 deletions src/rod/sdf/joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

@dataclasses.dataclass
class Limit(Element):
lower: float = dataclasses.field(
metadata=mashumaro.field_options(serialize=Element.serialize_float)

lower: Optional[float] = dataclasses.field(
diegoferigo marked this conversation as resolved.
Show resolved Hide resolved
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

upper: float = dataclasses.field(
metadata=mashumaro.field_options(serialize=Element.serialize_float)
upper: Optional[float] = dataclasses.field(
diegoferigo marked this conversation as resolved.
Show resolved Hide resolved
default=None,
metadata=mashumaro.field_options(serialize=Element.serialize_float),
)

effort: Optional[float] = dataclasses.field(
Expand Down
Loading