ResolveMath resolves a Math transform.
(t *v1beta1.MathTransform, input any)
| 101 | |
| 102 | // ResolveMath resolves a Math transform. |
| 103 | func ResolveMath(t *v1beta1.MathTransform, input any) (any, error) { |
| 104 | if err := ValidateMathTransform(t); err != nil { |
| 105 | return nil, err |
| 106 | } |
| 107 | switch input.(type) { |
| 108 | case int, int64, float64: |
| 109 | default: |
| 110 | return nil, errors.Errorf(errFmtMathInputNonNumber, input) |
| 111 | } |
| 112 | switch t.Type { |
| 113 | case v1beta1.MathTransformTypeMultiply: |
| 114 | return resolveMathMultiply(t, input) |
| 115 | case v1beta1.MathTransformTypeClampMin, v1beta1.MathTransformTypeClampMax: |
| 116 | return resolveMathClamp(t, input) |
| 117 | default: |
| 118 | return nil, errors.Errorf(errMathTransformTypeFailed, string(t.Type)) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // resolveMathMultiply resolves a multiply transform, returning an error if the |
| 123 | // input is not a number. If the input is a float, the result will be a float64, otherwise |