This commit is contained in:
Miloslav Ciz 2024-08-31 14:44:45 +02:00
parent 124b9d1e7c
commit 3f374a4713
85 changed files with 2281 additions and 2272 deletions

View file

@ -23,7 +23,7 @@ int distTaxi(int x0, int y0, int x1, int y1)
{
x0 = x1 > x0 ? x1 - x0 : x0 - x1; // dx
y0 = y1 > y0 ? y1 - y0 : y0 - y1; // dy
return x0 + y0;
}
@ -31,7 +31,7 @@ int distCheb(int x0, int y0, int x1, int y1)
{
x0 = x1 > x0 ? x1 - x0 : x0 - x1; // dx
y0 = y1 > y0 ? y1 - y0 : y0 - y1; // dy
return x0 > y0 ? x0 : y0;
}
```
@ -45,7 +45,7 @@ int dist8(int x0, int y0, int x1, int y1)
{
x0 = x1 > x0 ? x1 - x0 : x0 - x1; // dx
y0 = y1 > y0 ? y1 - y0 : y0 - y1; // dy
return (x0 + y0 + (x0 > y0 ? x0 : y0)) / 2;
}
```
@ -89,7 +89,7 @@ int32_t dist48(
if (x0 < z0)
{ // y0 < x0 < z0
int32_t t = y0; y0 = z0; z0 = t;
t = x0; x0 = y0; y0 = t;
t = x0; x0 = y0; y0 = t;
}
else
{ // y0 < z0 < x0
@ -97,7 +97,7 @@ int32_t dist48(
}
}
}
return (893 * x0 + 446 * y0 + 223 * z0) / 1024;
}
```
@ -109,16 +109,16 @@ int dist2DApprox(int x0, int y0, int x1, int y1)
{
x0 = x0 > x1 ? (x0 - x1) : (x1 - x0);
y0 = y0 > y1 ? (y0 - y1) : (y1 - y0);
if (x0 < y0)
{
x1 = x0; // swap
x0 = y0;
y0 = x1;
}
return (123 * x0 + 51 * y0) / 128; // max error = ~4%
//return x0 + y0 / 2; // faster, less accurate
//return x0 + y0 / 2; // faster, less accurate
}
```
@ -126,4 +126,4 @@ TODO: this https://www.flipcode.com/archives/Fast_Approximate_Distance_Functions
## See Also
- [freedom distance](freedom_distance.md)
- [freedom distance](freedom_distance.md)