Source code for picogl.core.mixin.vec4

from __future__ import annotations

from typing import Tuple

import numpy as np


[docs] def clamp01(x: float) -> float: return max(0.0, min(1.0, float(x)))
[docs] class Vec4Mixin: """Vec3 Mixin"""
[docs] def to_tuple(self) -> Tuple[float, float, float, float]: raise NotImplementedError
@property
[docs] def tuple(self) -> Tuple[float, float, float, float]: return self.to_tuple()
@property
[docs] def xyz(self) -> Tuple[float, float, float, float]: return self.to_tuple()
@classmethod
[docs] def from_rgb_tuple(cls, t: Tuple[float, float, float]): raise NotImplementedError
[docs] def clamp(self) -> None: """Clamp components in-place if the class is mutable.""" for name in self._component_names(): setattr(self, name, clamp01(getattr(self, name)))
@classmethod
[docs] def _component_names(cls): # helper for subclasses to declare their component names return ["r", "g", "b"]