project-euler/utils/point.jl

13 lines
254 B
Julia

import Base: *, +, -
export Point, magnitude, +, -, distance
struct Point{T}
x :: T
y :: T
end
magnitude(p) = p.x * p.x + p.y * p.y
+(a, b) = Point(a.x + b.x, a.y + b.y)
-(a, b) = Point(a.x - b.x, a.y - b.y)
distance(a, b) = sqrt(magnitude(a - b))