rectangle collision: Removed redundant point comparisons
authorLukas Krickl <lukas@krickl.dev>
Wed, 1 Oct 2025 20:18:42 +0000 (22:18 +0200)
committerLukas Krickl <lukas@krickl.dev>
Wed, 1 Oct 2025 20:18:42 +0000 (22:18 +0200)
src/rectangle.s

index 99d3a10e81a4f52685a0a38c38139b1d29c30bb6..6bedb4edcbf7968aac6c27f7af0708f99144cfe5 100644 (file)
@@ -165,8 +165,6 @@ rect_point_test:
 
        ; load bottom left point
        ld a, [hl+]
-       ; TODO: remove use of d2
-       ld [d2], a ; save y in d2
        ld d, a ; d = y
        ld a, [hl+] 
        ld e, a ; e = x
@@ -191,13 +189,11 @@ rect_point_test:
        ld d, a ; d = top left y
        pop hl
 
+       ; x was already tested in bottom left
+
        ld a, b ; compare y points
        cp a, d
        jr c, @no_collision REL
-       ld a, c ; compare x position
-       cp a, e
-       jr c, @no_collision REL
-
 
        
        ; top right
@@ -208,6 +204,8 @@ rect_point_test:
        capoverflow
        ld e, a
 
+       ; top right has unique x and y positions
+
        ld a, b ; compare y
        cp a, d
        jr c, @no_collision REL
@@ -218,17 +216,12 @@ rect_point_test:
 
        ; bottom right 
 
-       ; remove height from y
-       ; to get bottom right point
-       ld a, [d2] ; d2 = original y point
-       ld d, a
+       ; original y position was already tested in bottom left
+       ; x positions was already tested in top right
 
-       ld a, b ; compare y
-       cp a, d
-       jr nc, @no_collision REL
-       ld a, c ; compare x
-       cp a, e
-       jr nc, @no_collision REL
+       ; all other missing x/y checks have 
+       ; already been performed in previous points
+       ; e.g. original y is tested in bottom left
 
 @collision:
        ld a, 1