The `..<` operator constructs an open range: it includes the lower endpoint and excludes the upper endpoint. For example, `10..<20` contains `10` through `19`, whereas the closed range `10..20` also contains `20`. Use `..<` when an ending coordinate or boundary must remain outside the range. section 9.3.2
Checking points inside a rectangle
A rectangle can exclude its bottom and right edges by testing each coordinate against an open range: ```kotlin operator fun Rectangle.contains(p: Point): Boolean { return p.x in upperLeft.x..<lowerRight.x && p.y in upperLeft.y..<lowerRight.y } ``` Here `p.x` must be at least `upperLeft.x` but less than `lowerRight.x`; the same rule applies to `p.y`. A point on the right or bottom boundary is therefore outside the rectangle. section 9.3.2
This boundary rule works naturally with `in`: each coordinate is checked for membership in the range. It avoids treating the ending coordinate as part of a rectangle whose bottom and right coordinates are defined as exclusive. section 9.3.2
Listing 9.11 Implementing the in convention
data class Rectangle(val upperLeft: Point, val lowerRight: Point)
operator fun Rectangle.contains(p: Point): Boolean {
return p.x in upperLeft.x..<lowerRight.x && #1
p.y in upperLeft.y..<lowerRight.y #2
}
fun main() {
val rect = Rectangle(Point(10, 20), Point(50, 50))
println(Point(20, 30) in rect)
// true
println(Point(5, 5) in rect)
// false
}
Inspect the complete `Rectangle.contains` implementation and its inside/outside point checks. section 9.3.2






