~jasper/type_stack_calc

943979ccf88299925deff549b34edd0e63464cbb — Jasper den Ouden 8 months ago 2a96f43
minor
3 files changed, 17 insertions(+), 8 deletions(-)

M examples/intersection.tsc
M type_stack_calc/sets/range.py
M type_stack_calc/sets/stepping.py
M examples/intersection.tsc => examples/intersection.tsc +9 -1
@@ 1,2 1,10 @@

2 1 4 intersection.range.force
2 1 4 intersection.range.force 1 + a.set 

a 8 4 10 intersection.range.convert + b.set

12 0 6 intersection.stepping.convert c.set

c 30 0 15 intersection.stepping.convert + d.set

#b c + d.set  # Ok stuff missing?

M type_stack_calc/sets/range.py => type_stack_calc/sets/range.py +2 -2
@@ 223,12 223,12 @@ def maybe_range(x):
    return x

def param_from_2(name):
    num_name, stepping_name = f"num_{name}", f"range_{name}"
    num_name, range_name = f"num_{name}", f"range_{name}"
    def ret(self, y):
        if isinstance(y, (float, int)):
            return maybe_range(getattr(self, num_name)(y))
        elif isinstance(y, SetRange):
            return maybe_range(getattr(self, stepping_name)(y))
            return maybe_range(getattr(self, range_name)(y))
    return ret

for name in ['add', 'subtract', 'mult', 'divide', 'modulo', 'eq']:

M type_stack_calc/sets/stepping.py => type_stack_calc/sets/stepping.py +6 -5
@@ 199,12 199,13 @@ def param_from_2(name):
            return getattr(self, stepping_name)(y)
    return ret

for k in [('mult', '*'), ('add', '+'), ('divide', '/'), ('subtract', '-'),
          ('modulo', '%')]:
    k, also = (k if isinstance(k, tuple) else (k, None))
from type_stack_calc.util.fun_info import fun_info

for k in ['mult', 'add', 'divide', 'subtract', 'modulo']:
    got = fun_info.get(k)
    setattr(SetStepping, f"param_{k}", param_from_2(k))
    if also is not None:
        setattr(SetStepping, f"param_{k}", param_from_2(k))
    if got is not None and got.alt:
        setattr(SetStepping, f"param_{got.alt}", param_from_2(k))
 
for k in ['union', 'inside']:  # (intersect also deals with range)
    setattr(SetStepping, f"set_{k}", param_from_2(k))