Point equality always true

OS: Windows 11
Simulator: 2.0.3
SDK: 2.0.3

I expected points with different coordinates to be inequal, however they're equal.

local a, b <const> = 10, 20
local points = {
	a = point.new(a, a),
	b = point.new(a, a),
	c = point.new(a, b)
}

printTable("=== Points ===", points)
print("=== Point Equality ===")
print(string.format("%s == %s: ", points.a, points.b), points.a == points.b)
print(string.format("%s == %s: ", points.b, points.c), points.b == points.c)
print(string.format("%s == %s: ", points.c, points.a), points.c == points.a)
print(string.format("%s == %s: ", points.b, points.a), points.b == points.a)
print(string.format("%s == %s: ", points.c, points.b), points.c == points.b)
print(string.format("%s == %s: ", points.a, points.c), points.a == points.c)
=== Points ===	{
	[a] = (10.0, 10.0),
	[b] = (10.0, 10.0),
	[c] = (10.0, 20.0),
}
=== Point Equality ===
(10.0, 10.0) == (10.0, 10.0)	true
(10.0, 10.0) == (10.0, 20.0)	true
(10.0, 20.0) == (10.0, 10.0)	true
(10.0, 10.0) == (10.0, 10.0)	true
(10.0, 20.0) == (10.0, 10.0)	true
(10.0, 10.0) == (10.0, 20.0)	true

I tested this (had to add import 'CoreLibs/object.lua' and point = playdate.geometry.point to get it to build) and it works as expected for me:

(10.0, 10.0) == (10.0, 10.0): 	true
(10.0, 10.0) == (10.0, 20.0): 	false
(10.0, 20.0) == (10.0, 10.0): 	false
(10.0, 10.0) == (10.0, 10.0): 	true
(10.0, 20.0) == (10.0, 10.0): 	false
(10.0, 10.0) == (10.0, 20.0): 	false

The Lua code is the same on Windows and Mac so that wouldn't make a difference.. Is there something strange in the code you didn't post?

Yes, there is, and it's the culprit:

local point <const> = geo.point
local point <const> = geo.vector2D

I'm redefining point to be a vector2D (which I didn't mean to do).

I keep pressing Shift+Ctrl+L to delete a line, but in VS Code that fires up multi cursor and I keep making random changes to parts of the file that aren't even on the screen.

Thanks for running the code Dan. With the double definition removed I can the expected behaviour.

1 Like

But you did find the bug in vector2D! The equality test has a typo:

    return (v1.dx == v2.dx && v1.dy == v1.dy);

And I found a similar one in the affine transform equality check. Thanks for catching that, even if by accident! :smiley:

5 Likes

Awesome. I'll take the reprieve. It also means I didn't waste your time.

2 Likes

Actually, I think you could remove the point class completely. Mathematically, a point is a vector.