Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import List, NamedTuple, Optional
- type OptFloatSlice = slice[Optional[float], float, Optional[float]]
- def float_range(slc: OptFloatSlice) -> List[float]:
- start = slc.start or 0.0
- step = slc.step or 1.0
- return [i * step + start for i in range(int(slc.stop - start / step))]
- class Spatial[T](NamedTuple):
- x: T
- y: T
- z: T
- class Vector3(Spatial[float]):
- pass
- class Bounds(Spatial[float | OptFloatSlice]):
- pass
- class Ranges(Spatial[List[float]]):
- @staticmethod
- def from_bounds(bounds: Bounds) -> Ranges:
- return Ranges(
- float_range(bounds.x) if isinstance(bounds.x, slice) else [bounds.x],
- float_range(bounds.y) if isinstance(bounds.y, slice) else [bounds.y],
- float_range(bounds.z) if isinstance(bounds.z, slice) else [bounds.z],
- )
- def to_path(self) -> List[Vector3]:
- return [
- Vector3(x, y, z)
- for x in self.x
- for y in self.y
- for z in self.z
- ]
- bounds = Bounds(10.0, slice(7.0), 15.0)
- ranges = Ranges.from_bounds(bounds)
- print(ranges.to_path())
Advertisement
Add Comment
Please, Sign In to add comment