Files
2026-04-05 20:32:56 +02:00

45 lines
1.5 KiB
Python

# ======================================================================
# Node Pack: artyclaw-comfy
# Author: artyclaw
# Version: 1.0.0
# Description: A power-user toolkit for prompt logic, IO, and RNG.
# ======================================================================
# NearestDivisibleInt — rounds an integer to the nearest value divisible by X
# Inputs:
# value (INT): number to adjust
# divisor (INT): value to round to multiples of (default 16)
# Output:
# result (INT): nearest integer divisible by divisor
import math
class NearestDivisibleInt:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"value": ("INT", {"default": 512, "min": 0, "max": 999999}),
"divisor": ("INT", {"default": 16, "min": 1, "max": 1024}),
}
}
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("result",)
FUNCTION = "compute"
CATEGORY = "math/utils"
def compute(self, value=512, divisor=16):
if divisor <= 0:
return (value,)
remainder = value % divisor
lower = value - remainder
upper = lower + divisor
# pick whichever is closer; ties go upward
result = upper if (value - lower) >= (divisor / 2) else lower
return (int(result),)
NODE_CLASS_MAPPINGS = {"NearestDivisibleInt": NearestDivisibleInt}
NODE_DISPLAY_NAME_MAPPINGS = {"NearestDivisibleInt": "Nearest Divisible Int"}