Posts: 6
Threads: 1
Joined: Mar 2023
(Mar-17-2023, 07:37 PM)Gribouillis Wrote: (Mar-17-2023, 07:06 PM)JazonKuer Wrote: For a scale of 5000 it will either end on 0000, 2500, 5000, or 7500. Only replace 100 by 500 in the interval() function. However what are the valid values when the scale is 4000 ?
73874 (71500, 76500)
919227 (916500, 921500)
448634 (446000, 451000)
196040 (193500, 198500)
767177 (764500, 769500)
972937 (970500, 975500)
146383 (144000, 149000)
345814 (343500, 348500)
685618 (683000, 688000)
578875 (576500, 581500)
No that doesn't cut it either, e.g.: 269361 (267000, 272000). I would have expected that coordinate to return (267500,272500). For a scale of 4000, here are some valid intervals: (260000,264000), (262000,266000), (264000,268000).
Posts: 4,785
Threads: 76
Joined: Jan 2018
(Mar-17-2023, 07:42 PM)JazonKuer Wrote: No that doesn't cut it either I think you could simply take the rounding precision equal to scale.
def interval(coord, scale):
u = rounding(scale, coord)
m = u + scale // 2
return (2 * u - m, m) Output: 753440 (752500, 757500)
438123 (437500, 442500)
912444 (907500, 912500)
780151 (777500, 782500)
173878 (172500, 177500)
398415 (397500, 402500)
4882 (2500, 7500)
177479 (172500, 177500)
714674 (712500, 717500)
885073 (882500, 887500)
And with a scale of 4000
Output: 844886 (842000, 846000)
946284 (946000, 950000)
413177 (410000, 414000)
69355 (66000, 70000)
172377 (170000, 174000)
328100 (326000, 330000)
871511 (870000, 874000)
428165 (426000, 430000)
649193 (646000, 650000)
496116 (494000, 498000)
Posts: 4,785
Threads: 76
Joined: Jan 2018
Here is my last word
__version__ = '2023.03.17.2'
def rounding(precision, value):
y = 0.5 if value >= 0 else -0.5
return precision * int(y + value / precision)
def interval(coord, scale):
s = scale // 2
u = rounding(s, coord)
return (u - s, u + s)
if __name__ == '__main__':
from random import randint
for i in range(10):
x = randint(0, 1000000)
print(x, interval(x, 5000)) Output: 589802 (587500, 592500)
886897 (885000, 890000)
775585 (772500, 777500)
17445 (15000, 20000)
794528 (792500, 797500)
57525 (55000, 60000)
466087 (462500, 467500)
501046 (497500, 502500)
906234 (902500, 907500)
744038 (742500, 747500)
|