Point2D(x::Real, y::Real)
Creates a Point2D object with dimensions x and y
Can take either two Numbers or a string similat to “(1, 2)”
Example
julia-repl
julia> Point2D(1,2)
(1, 2)
strng = “(1, -2.4)”
Point2D(strng)
(1.0, -2.4)
Point2D((“1, 2”))
(1, 2)
mutable struct Point2D
x::Real
y::Rea
l
str::String
Point2D(x::Real, y::Real) = new(x, y)
function Point2D(str::String)
idk = match(r"^\(([+-]?\d*\.?\d+?),\s?([+-]?\d*\.?\d+?)\)$", str )
x = parse(Float64, idk[1])
y = parse(Float64, idk[2])
new(x,y)
end
end
Base.show(io::IO,p::Point2D) = print(io, string((p.x,p.y))) #Base.==(p1::Point2D, p2::Point2D) = p1.x == p2.x && p1.y == p2.y Base.==(p1::Point2D, p2::Point2D) = isapprox(p1.x, p2.x) && isapprox(p1.y, p2.y)
My ‘Base.==’ is giving me an issue :syntax: invalid argument destructuring syntax “(p1::Point2D, p2::Point2D)” around In[9]:9
trying to use it for test such : @test Point2D(1, 2) == Point2D(1, 2)
Help!!