File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -18,22 +18,22 @@ extension (x: Int) inline def ±(y: Int) = x - y to x + y
18
18
extension (x : Inclusive )
19
19
inline def & (y : Inclusive ) = (x.start max y.start) to (x.end min y.end)
20
20
21
- opaque type Pos = ( Int , Int )
21
+ opaque type Pos = Int
22
22
23
23
object Pos :
24
- val up : Pos = (0 , - 1 )
25
- val down : Pos = (0 , 1 )
26
- val left : Pos = (- 1 , 0 )
27
- val right : Pos = (1 , 0 )
28
- val zero : Pos = (0 , 0 )
29
- def apply (x : Int , y : Int ): Pos = (x, y)
24
+ val up = Pos (0 , - 1 )
25
+ val down = Pos (0 , 1 )
26
+ val left = Pos (- 1 , 0 )
27
+ val right = Pos (1 , 0 )
28
+ val zero = Pos (0 , 0 )
29
+ inline def apply (x : Int , y : Int ): Pos = y << 16 | x
30
30
31
31
extension (p : Pos )
32
- inline def x = p._1
33
- inline def y = p._2
32
+ inline def x = p & 0xffff
33
+ inline def y = p >> 16
34
34
inline def neighbors : List [Pos ] =
35
35
List (p + up, p + right, p + down, p + left)
36
- inline def + (q : Pos ): Pos = (p.x + q.x, p.y + q.y)
36
+ inline def + (q : Pos ): Pos = Pos (p.x + q.x, p.y + q.y)
37
37
inline infix def taxiDist (q : Pos ) = (p.x - q.x).abs + (p.y - q.y).abs
38
38
39
39
case class Rect (x : Inclusive , y : Inclusive ):
You can’t perform that action at this time.
0 commit comments