# [r163] Expression distance wrong

Bugs will be moved here once resolved.

### » Thu Feb 27, 2014 6:10 pm

Problem Description
Unless the distance expression shouldn't give back the distance between two points, I think this expressions result ist wrong.

Code: Select all
`round(distance(Pos1.X, Pos2.X, Pos1.Y,Pos2.Y))`

compared to

Code: Select all
`round(sqrt(abs(Pos1.X - Pos2.X)^2 + abs(Pos1.Y - Pos2.Y)^2))`

This - IMHO correct way to calculate the distance - gives a very different result using the distance expression.

Operating System and Service Pack
Win7 SVP3

Construct 2 Version ID
163
B
11
S
1
G
1
Posts: 81
Reputation: 892

### » Thu Feb 27, 2014 6:24 pm

Not a bug.
The correct way to use the distance function is:
Code: Select all
`distance(Pos1.X, Pos1.Y, Pos2.X, Pos2.Y)`

Notice the x,y pairs are next to each other.

It's exactly the same as:
Code: Select all
`sqrt((Pos2.X - Pos1.X)^2 + (Pos2.Y - Pos1.Y)^2)`

or
Code: Select all
`sqrt((Pos1.X - Pos2.X)^2 + (Pos1.Y - Pos2.Y)^2)`

The abs() isn't needed since any number squared is always positive.
B
98
S
36
G
131
Posts: 5,521
Reputation: 83,505

### » Thu Feb 27, 2014 6:52 pm

Ahh, my bad, sorry, sorry, sorry -> ashamed in the leftmost corner.... (the eyes, old eyes, small screen, high resolution )

Thanks R0J0hound. I'll try to delete or let this thread delete.
B
11
S
1
G
1
Posts: 81
Reputation: 892