Skip to content

Commit

Permalink
chore: Refactored int and float nodes, added number nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
evanspearman committed Jul 20, 2023
1 parent 31ed629 commit f8026c8
Show file tree
Hide file tree
Showing 5 changed files with 573 additions and 663 deletions.
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .src.comfymath.convert import NODE_CLASS_MAPPINGS as convert_NCM
from .src.comfymath.int import NODE_CLASS_MAPPINGS as int_NCM
from .src.comfymath.float import NODE_CLASS_MAPPINGS as float_NCM
from .src.comfymath.number import NODE_CLASS_MAPPINGS as number_NCM
from .src.comfymath.vec2 import NODE_CLASS_MAPPINGS as vec2_NCM
from .src.comfymath.vec3 import NODE_CLASS_MAPPINGS as vec3_NCM
from .src.comfymath.vec4 import NODE_CLASS_MAPPINGS as vec4_NCM
Expand All @@ -11,6 +12,7 @@
**convert_NCM,
**int_NCM,
**float_NCM,
**number_NCM,
**vec2_NCM,
**vec3_NCM,
**vec4_NCM,
Expand Down
79 changes: 55 additions & 24 deletions src/comfymath/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from .vec2 import Vec2, VEC2_ZERO
from .vec3 import Vec3, VEC3_ZERO
from .vec4 import Vec4, VEC4_ZERO
from .number import number


class FloatToInt:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("FLOAT", {"default": 0.0})}}
Expand All @@ -22,9 +20,6 @@ def op(self, a: float) -> tuple[int]:


class IntToFloat:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("INT", {"default": 0})}}
Expand All @@ -37,10 +32,57 @@ def op(self, a: int) -> tuple[float]:
return (float(a),)


class ComposeVec2:
def __init__(self):
pass
class IntToNumber:
@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("INT", {"default": 0})}}

RETURN_TYPES = ("NUMBER",)
FUNCTION = "op"
CATEGORY = "math/conversion"

def op(self, a: int) -> tuple[number]:
return (a,)

class NumberToInt:
@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("NUMBER", {"default": 0.0})}}

RETURN_TYPES = ("INT",)
FUNCTION = "op"
CATEGORY = "math/conversion"

def op(self, a: number) -> tuple[int]:
return (int(a),)


class FloatToNumber:
@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("FLOAT", {"default": 0.0})}}

RETURN_TYPES = ("NUMBER",)
FUNCTION = "op"
CATEGORY = "math/conversion"

def op(self, a: float) -> tuple[number]:
return (a,)

class NumberToFloat:
@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("NUMBER", {"default": 0.0})}}

RETURN_TYPES = ("FLOAT",)
FUNCTION = "op"
CATEGORY = "math/conversion"

def op(self, a: number) -> tuple[float]:
return (float(a),)


class ComposeVec2:
@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {
Expand All @@ -59,9 +101,6 @@ def op(self, x: float, y: float) -> tuple[Vec2]:


class BreakoutVec2:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("VEC2", {"default": VEC2_ZERO})}}
Expand All @@ -75,9 +114,6 @@ def op(self, a: Vec2) -> tuple[float, float]:


class ComposeVec3:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {
Expand All @@ -97,9 +133,6 @@ def op(self, x: float, y: float, z: float) -> tuple[Vec3]:


class BreakoutVec3:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("VEC3", {"default": VEC3_ZERO})}}
Expand All @@ -113,9 +146,6 @@ def op(self, a: Vec3) -> tuple[float, float, float]:


class ComposeVec4:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {
Expand All @@ -136,9 +166,6 @@ def op(self, x: float, y: float, z: float, w: float) -> tuple[Vec4]:


class BreakoutVec4:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls) -> Mapping[str, Any]:
return {"required": {"a": ("VEC4", {"default": VEC4_ZERO})}}
Expand All @@ -154,6 +181,10 @@ def op(self, a: Vec4) -> tuple[float, float, float, float]:
NODE_CLASS_MAPPINGS = {
"FloatToInt": FloatToInt,
"IntToFloat": IntToFloat,
"IntToNumber": IntToNumber,
"NumberToInt": NumberToInt,
"FloatToNumber": FloatToNumber,
"NumberToFloat": NumberToFloat,
"ComposeVec2": ComposeVec2,
"ComposeVec3": ComposeVec3,
"ComposeVec4": ComposeVec4,
Expand Down
Loading

0 comments on commit f8026c8

Please sign in to comment.