evaluate_egg Function

private pure elemental function evaluate_egg(this, pos) result(res)

Evaluation function for Egg SDF. ref

Type Bound

egg

Arguments

Type IntentOptional Attributes Name
class(egg), intent(in) :: this
type(vector), intent(in) :: pos

vector position to evaluate SDF at

Return Value real(kind=wp)


Source Code

    pure elemental function evaluate_egg(this, pos) result(res)
        !! Evaluation function for Egg SDF.
        !! [ref](https://www.shadertoy.com/view/WsjfRt)

        class(egg),   intent(in) :: this
        !> vector position to evaluate SDF at
        type(vector), intent(IN) :: pos
        real(kind=wp) :: res

        real(kind=wp) :: r, l, h_in
        type(vector) :: p_in, p

        p = pos .dot. this%transform

        p_in = p

        p_in%x = abs(p%x)
        r = this%r1 - this%r2
        h_in = this%h + r
        l = (h_in**2 - r**2) / (2._wp * r)

        if(p_in%y <= 0._wp)then
            res = length(p_in) - this%r1
        else
            if((p_in%y - h_in) * l > p_in%x*h_in)then
                res = length(p_in - vector(0._wp, h_in, 0._wp)) - ((this%r1+l) - length(vector(h_in,l, 0._wp)))
            else
                res = length(p_in + vector(l, 0._wp, 0._wp)) - (this%r1+l)
            end if
        end if
    end function evaluate_egg