mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-13 07:10:57 +00:00
(svn r22302) -Codechange: Replace a linear search with a binary search.
This commit is contained in:
parent
1e64012e9f
commit
ecb3701210
@ -50,8 +50,19 @@ void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_wid
|
||||
|
||||
int frac_diff = width * max(dx, dy);
|
||||
if (width > 1) {
|
||||
/* compute frac_diff = width * sqrt(dx*dx + dy*dy)
|
||||
* Start interval:
|
||||
* max(dx, dy) <= sqrt(dx*dx + dy*dy) <= sqrt(2) * max(dx, dy) <= 3/2 * max(dx, dy) */
|
||||
int frac_sq = width * width * (dx * dx + dy * dy);
|
||||
while (frac_diff * frac_diff < frac_sq) frac_diff++;
|
||||
int frac_max = 3 * frac_diff / 2;
|
||||
while (frac_diff < frac_max) {
|
||||
int frac_test = (frac_diff + frac_max) / 2;
|
||||
if (frac_test * frac_test < frac_sq) {
|
||||
frac_diff = frac_test + 1;
|
||||
} else {
|
||||
frac_max = frac_test - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dx > dy) {
|
||||
|
Loading…
Reference in New Issue
Block a user