Advertisement
Guest User

scala1

a guest
Apr 28th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.45 KB | None | 0 0
  1. class Point(
  2.     val x: Double, val y: Double,
  3.     addToGrid: Boolean = false
  4. ) {
  5.   import Point._
  6.  
  7.   if (addToGrid)
  8.     grid.add(this)
  9.  
  10.   def this() = this(0.0, 0.0)
  11.  
  12.   def distanceToPoint(other: Point) =
  13.     distanceBetweenPoints(x, y, other.x, other.y)
  14. }
  15.  
  16. object Point {
  17.   private val grid = new Grid()
  18.  
  19.   def distanceBetweenPoints(x1: Double, y1: Double,
  20.       x2: Double, y2: Double) = {
  21.     math.hypot(x1 - x2, y1 - y2)
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement