project-euler/utils/point.jl

13 lines
254 B
Julia
Raw Normal View History

2020-12-08 03:53:32 +00:00
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))