Use our own hypot() for older Python support
This commit is contained in:
parent
af9cc4b546
commit
aec057c89c
|
@ -1,7 +1,6 @@
|
|||
import re
|
||||
import time
|
||||
import random
|
||||
from math import hypot
|
||||
from itertools import count
|
||||
from munch import Munch
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import re
|
||||
import time
|
||||
import random
|
||||
from math import hypot
|
||||
from itertools import count
|
||||
from munch import Munch
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
@ -40,7 +40,7 @@ class FillBlocksStates:
|
|||
|
||||
b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
|
||||
box = utils.psub(b2, b1)
|
||||
xz_distance = hypot(box[0]+1, box[2]+1)
|
||||
xz_distance = utils.hypot(box[0]+1, box[2]+1)
|
||||
y_start = f.coord1[1]
|
||||
y_end = f.coord2[1]
|
||||
|
||||
|
@ -84,7 +84,7 @@ class FillBlocksStates:
|
|||
|
||||
b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
|
||||
box = utils.psub(b2, b1)
|
||||
xz_distance = hypot(box[0]+1, box[2]+1)
|
||||
xz_distance = utils.hypot(box[0]+1, box[2]+1)
|
||||
y_start = f.coord1[1]
|
||||
y_end = f.coord2[1]
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import time
|
|||
import importlib
|
||||
import random
|
||||
from itertools import count
|
||||
from math import hypot, floor
|
||||
from math import floor
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import importlib
|
||||
import functools
|
||||
import time
|
||||
from math import hypot, sqrt
|
||||
|
||||
from astar import AStar
|
||||
|
||||
|
@ -306,7 +305,7 @@ class Pathfinder(AStar):
|
|||
def distance_between(self, n1, n2):
|
||||
(x1, y1, z1) = n1
|
||||
(x2, y2, z2) = n2
|
||||
return hypot(x2-x1, y2-y1, z2-z1)
|
||||
return utils.hypot(x2-x1, y2-y1, z2-z1)
|
||||
|
||||
def heuristic_cost_estimate(self, n1, n2):
|
||||
(x1, y1, z1) = n1
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import importlib
|
||||
import collections
|
||||
from math import floor, ceil, sqrt, hypot
|
||||
from math import floor, ceil, sqrt
|
||||
|
||||
from mosfet.info import blocks
|
||||
from mosfet.info import mcdata
|
||||
|
||||
TICK = 0.05
|
||||
|
||||
def hypot(*coordinates):
|
||||
# python's 3D hypot is too new, so we'll use our own
|
||||
return sqrt(sum(x**2 for x in coordinates))
|
||||
|
||||
def padd(p1, p2):
|
||||
return (p1[0] + p2[0], p1[1] + p2[1], p1[2] + p2[2])
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import math
|
||||
from mosfet import utils
|
||||
|
||||
class Vector3D:
|
||||
def __init__(self, vector):
|
||||
|
@ -17,7 +18,7 @@ class Vector3D:
|
|||
return self.tuple()[key]
|
||||
|
||||
def length(self):
|
||||
return math.hypot(self.x, self.y, self.z)
|
||||
return utils.hypot(self.x, self.y, self.z)
|
||||
|
||||
def normalized(self):
|
||||
x = self.x / self.length()
|
||||
|
|
|
@ -2,7 +2,6 @@ import collections
|
|||
import re
|
||||
import time
|
||||
import random
|
||||
from math import hypot
|
||||
from itertools import count
|
||||
from copy import copy
|
||||
|
||||
|
@ -35,7 +34,7 @@ class World:
|
|||
continue
|
||||
if y_limit and abs(cur[1]) > y_limit:
|
||||
continue
|
||||
if distance and hypot(*cur) > distance:
|
||||
if distance and utils.hypot(*cur) > distance:
|
||||
continue
|
||||
|
||||
check = utils.padd(center, cur)
|
||||
|
@ -76,7 +75,7 @@ class World:
|
|||
offset = utils.spiral(n)
|
||||
check = utils.padd(center, offset)
|
||||
if self.block_at(*check) in block_ids:
|
||||
if hypot(*offset) < distance:
|
||||
if utils.hypot(*offset) < distance:
|
||||
result.append(check)
|
||||
if limit and len(result) == limit:
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue
Block a user