RosettaCodeData/Task/Closest-pair-problem/Groovy/closest-pair-problem-1.groovy
2023-07-01 13:44:08 -04:00

6 lines
235 B
Groovy

class Point {
final Number x, y
Point(Number x = 0, Number y = 0) { this.x = x; this.y = y }
Number distance(Point that) { ((this.x - that.x)**2 + (this.y - that.y)**2)**0.5 }
String toString() { "{x:${x}, y:${y}}" }
}