I don't understand this behavior. I want to check if a value is in a circle created on a grid (as an array). Defining the two sides of the circle..
val circleLeft = Vector(5,14,23..)
val circleRight = Vector(5,16,27,..)
I'm checking with the below function this condition. With the first one:
def insideCircle(idx: Int): Boolean = {
val l = circleLeft.toIterator
val r = circleRight.toIterator
while (l.hasNext && r.hasNext) {
if(idx < r.next && idx > l.next) return true
}
return false
}
It returns always true. With this second one
def insideCircle(idx: Int): Boolean = {
val l = circleLeft.toIterator
val r = circleRight.toIterator
while (l.hasNext && r.hasNext) {
val x1 = r.next
val x2 = l.next
println(x2,x1)
if(idx < x1 && idx > x2) return true
}
return false
}
It works properly, i.e. insideCircle(15) = true, insideCircle(17) = false
Is there something here different..?