I’d looking for some input on the best way to tackle this.
Right now I have a struct that looks something like this:
mutable struct Line
win::Window
startPoint::Vector{Int64}
endPoint::Vector{Int64}
lineColor::Vector{Int64}
#----------
function Line( win::Window,
startPoint::Vector{Int64} = [0,0],
endPoint::Vector{Int64} = [10,10];
width::Int64 = 1,
lineColor::Vector{Int64} = fill(128, (4)),
)
new(win,
startPoint,
endPoint,
width,
lineColor
)
end
end
There is more to it than that: I pulled out superfluous code to make it easier to read.
Right now lineColor is a vector of RGBA values from 0-255 (I’m using SDL). I’d like to make it more flexible, so that it can take vectors of floating point numbers from 0.0 to 1.0, or even the word “red”, and automatically translate the value passed to it into an RGBA Int vector based on its type (maybe _lineColor as an ‘hidden’ variable used internally for setting the final color).
I’m not sure of the right way, or best way, to tackle this. Should I replace lineColor::Vector{Int64}
with lineColor::{Any}
? Is there a way to do multiple dispatch or overload the inner constructor, so that I have one for lineColor::Vector{Int64}
, one for lineColor::Vector{Float64}
, and one for lineColor::String
?
How would you tackle this?