Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #161 from poliastro/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
Stoops-ML authored Dec 1, 2024
2 parents 225114d + 993f614 commit 598fb9d
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 390 deletions.
2 changes: 1 addition & 1 deletion src/czml3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .core import CZML_VERSION, Document, Packet, Preamble

__version__ = "2.0.0"
__version__ = "2.0.1"

__all__ = ["Document", "Preamble", "Packet", "CZML_VERSION"]
2 changes: 1 addition & 1 deletion src/czml3/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Packet(BaseCZMLObject):
for further information.
"""

id: str = Field(default=str(uuid4()))
id: str = Field(default_factory=lambda _: str(uuid4()))
delete: None | bool = Field(default=None)
name: None | str = Field(default=None)
parent: None | str = Field(default=None)
Expand Down
212 changes: 84 additions & 128 deletions src/czml3/properties.py

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions src/czml3/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@
TYPE_MAPPING = {bool: "boolean"}


def get_color(color):
def get_color(color) -> list[float] | None:
"""Determines if the input is a valid color"""
if color is None or (
isinstance(color, list)
and all(issubclass(type(v), int | float) for v in color)
and all(issubclass(type(v), float) for v in color)
and len(color) == 4
and (all(0 <= v <= 255 for v in color) or all(0 <= v <= 1 for v in color))
):
return color
elif (
isinstance(color, list)
and all(issubclass(type(v), int | float) for v in color)
and all(issubclass(type(v), float) for v in color)
and len(color) == 3
and all(0 <= v <= 255 for v in color)
):
return color + [255]
return color + [255.0]
# rgbf or rgbaf
# if (
# isinstance(color, list)
# and all(issubclass(type(v), int | float) for v in color)
# and all(issubclass(type(v), float) for v in color)
# and (3 <= len(color) <= 4)
# and not all(0 <= v <= 1 for v in color)
# ):
# raise TypeError("RGBF or RGBAF values must be between 0 and 1")
elif (
isinstance(color, list)
and all(issubclass(type(v), int | float) for v in color)
and all(issubclass(type(v), float) for v in color)
and len(color) == 3
and all(0 <= v <= 1 for v in color)
):
Expand Down Expand Up @@ -143,7 +143,7 @@ class RgbafValue(BaseCZMLObject):
"""

values: list[float] | list[int]
values: list[float]

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand Down Expand Up @@ -183,7 +183,7 @@ class RgbaValue(BaseCZMLObject):
"""

values: list[float] | list[int]
values: list[float]

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand All @@ -197,15 +197,15 @@ def _check_values(self) -> Self:
)

if len(self.values) == num_coords and not all(
isinstance(val, int) and 0 <= val <= 255 for val in self.values
isinstance(val, float) and 0 <= val <= 255 for val in self.values
):
raise TypeError("Color values must be integers in the range 0-255.")

else:
for i in range(0, len(self.values), num_coords + 1):
v = self.values[i + 1 : i + num_coords + 1]

if not all(isinstance(val, int) and 0 <= val <= 255 for val in v):
if not all(isinstance(val, float) and 0 <= val <= 255 for val in v):
raise TypeError("Color values must be integers in the range 0-255.")
return self

Expand Down Expand Up @@ -246,7 +246,7 @@ class Cartesian3Value(BaseCZMLObject):
"""

values: None | list[Any] = Field(default=None)
values: None | list[float] = Field(default=None)

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand All @@ -263,7 +263,7 @@ def _check_values(self) -> Self:
return self

@model_serializer
def custom_serializer(self) -> list[Any]:
def custom_serializer(self) -> list[float]:
if self.values is None:
return []
return list(self.values)
Expand All @@ -279,7 +279,7 @@ class Cartesian2Value(BaseCZMLObject):
"""

values: None | list[Any] = Field(default=None)
values: None | list[float] = Field(default=None)

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand Down Expand Up @@ -313,7 +313,7 @@ class CartographicRadiansValue(BaseCZMLObject):
"""

values: None | list[Any] = Field(default=None)
values: None | list[float] = Field(default=None)

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand Down Expand Up @@ -347,7 +347,7 @@ class CartographicDegreesValue(BaseCZMLObject):
"""

values: None | list[Any] = Field(default=None)
values: None | list[float] = Field(default=None)

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand All @@ -364,7 +364,7 @@ def _check_values(self) -> Self:
return self

@model_serializer
def custom_serializer(self) -> list[Any]:
def custom_serializer(self) -> list[float]:
if self.values is None:
return []
return self.values
Expand All @@ -387,7 +387,7 @@ class CartographicRadiansListValue(BaseCZMLObject):
"""A list of geodetic, WGS84 positions specified as [Longitude, Latitude, Height, Longitude, Latitude, Height, ...],
where Longitude and Latitude are in radians and Height is in meters."""

values: list[float] | list[int]
values: list[float]

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand All @@ -407,7 +407,7 @@ class CartographicDegreesListValue(BaseCZMLObject):
"""A list of geodetic, WGS84 positions specified as [Longitude, Latitude, Height, Longitude, Latitude, Height, ...],
where Longitude and Latitude are in degrees and Height is in meters."""

values: list[float] | list[int]
values: list[float]

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand All @@ -430,7 +430,7 @@ class DistanceDisplayConditionValue(BaseCZMLObject):
where Time is an ISO 8601 date and time string or seconds since epoch.
"""

values: list[float] | list[int]
values: list[float]

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand All @@ -454,7 +454,7 @@ class NearFarScalarValue(BaseCZMLObject):
FarDistance, FarValue, ...], where Time is an ISO 8601 date and time string or seconds since epoch.
"""

values: list[float] | list[int]
values: list[float]

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand Down Expand Up @@ -538,7 +538,7 @@ class UnitQuaternionValue(BaseCZMLObject):
"""

values: list[float] | list[int]
values: list[float]

@model_validator(mode="after")
def _check_values(self) -> Self:
Expand Down Expand Up @@ -567,7 +567,7 @@ def custom_serializer(self):
class NumberValue(BaseCZMLObject):
"""A single number, or a list of number pairs signifying the time and representative value."""

values: int | float | list[float] | list[int]
values: int | float | list[float] | int | list[int]

@model_serializer
def custom_serializer(self):
Expand Down
Loading

0 comments on commit 598fb9d

Please sign in to comment.