Skip to content

Commit

Permalink
Add real and imag functions in ExprEvaluation.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
jofrevalles committed Apr 23, 2024
1 parent 2550e2f commit c361266
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ExprEvaluation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ function custom_eval(expr, vars, width, height; samplers = Dict(), primitives_wi
return Color(evaluated_args...)
elseif func == :Complex
return Complex.(evaluated_args...)
elseif func == :real
return real.(evaluated_args...)
elseif func == :imag
return imag.(evaluated_args...)
elseif func == :rand_scalar
if length(evaluated_args) == 0
return rand(1) |> first
Expand All @@ -147,12 +151,16 @@ function custom_eval(expr, vars, width, height; samplers = Dict(), primitives_wi
# TODO: maybe check the case with Color in the conditional
return ternary.(evaluated_args[1], evaluated_args[2], evaluated_args[3])
elseif func == :max
return max.(evaluated_args[1], evaluated_args[2])
if isreal(evaluated_args[1]) && isreal(evaluated_args[2])
return max.(evaluated_args[1], evaluated_args[2])
else
return max.(real.(evaluated_args[1]), real.(evaluated_args[2])) + max.(imag.(evaluated_args[1]), imag.(evaluated_args[2])) * im
end
elseif func == :min
if evaluated_args[1] isa Complex || evaluated_args[2] isa Complex
return min.(real.(evaluated_args[1]), real.(evaluated_args[2])) + min.(imag.(evaluated_args[1]), imag.(evaluated_args[2])) * im
else
return min.(evaluated_args[1], evaluated_args[2])
return min.(real.(evaluated_args[1]), real.(evaluated_args[2]))
end
elseif func == :<
return evaluated_args[1] .< evaluated_args[2]
Expand Down

0 comments on commit c361266

Please sign in to comment.