Use our own hypot() for older Python support

This commit is contained in:
Tanner Collin 2021-04-28 07:12:30 +00:00
parent af9cc4b546
commit aec057c89c
23 changed files with 28 additions and 28 deletions

View File

@ -1,7 +1,6 @@
import re import re
import time import time
import random import random
from math import hypot
from itertools import count from itertools import count
from munch import Munch from munch import Munch

View File

@ -1,7 +1,6 @@
import re import re
import time import time
import random import random
from math import hypot
from itertools import count from itertools import count
from munch import Munch from munch import Munch

View File

@ -3,7 +3,6 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace
@ -40,7 +40,7 @@ class FillBlocksStates:
b1, b2 = utils.pboundingbox(f.coord1, f.coord2) b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
box = utils.psub(b2, b1) 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_start = f.coord1[1]
y_end = f.coord2[1] y_end = f.coord2[1]
@ -84,7 +84,7 @@ class FillBlocksStates:
b1, b2 = utils.pboundingbox(f.coord1, f.coord2) b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
box = utils.psub(b2, b1) 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_start = f.coord1[1]
y_end = f.coord2[1] y_end = f.coord2[1]

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -3,7 +3,7 @@ import time
import importlib import importlib
import random import random
from itertools import count from itertools import count
from math import hypot, floor from math import floor
from minecraft.networking.types import BlockFace from minecraft.networking.types import BlockFace

View File

@ -1,7 +1,6 @@
import importlib import importlib
import functools import functools
import time import time
from math import hypot, sqrt
from astar import AStar from astar import AStar
@ -306,7 +305,7 @@ class Pathfinder(AStar):
def distance_between(self, n1, n2): def distance_between(self, n1, n2):
(x1, y1, z1) = n1 (x1, y1, z1) = n1
(x2, y2, z2) = n2 (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): def heuristic_cost_estimate(self, n1, n2):
(x1, y1, z1) = n1 (x1, y1, z1) = n1

View File

@ -1,12 +1,16 @@
import importlib import importlib
import collections import collections
from math import floor, ceil, sqrt, hypot from math import floor, ceil, sqrt
from mosfet.info import blocks from mosfet.info import blocks
from mosfet.info import mcdata from mosfet.info import mcdata
TICK = 0.05 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): def padd(p1, p2):
return (p1[0] + p2[0], p1[1] + p2[1], p1[2] + p2[2]) return (p1[0] + p2[0], p1[1] + p2[1], p1[2] + p2[2])

View File

@ -1,4 +1,5 @@
import math import math
from mosfet import utils
class Vector3D: class Vector3D:
def __init__(self, vector): def __init__(self, vector):
@ -17,7 +18,7 @@ class Vector3D:
return self.tuple()[key] return self.tuple()[key]
def length(self): def length(self):
return math.hypot(self.x, self.y, self.z) return utils.hypot(self.x, self.y, self.z)
def normalized(self): def normalized(self):
x = self.x / self.length() x = self.x / self.length()

View File

@ -2,7 +2,6 @@ import collections
import re import re
import time import time
import random import random
from math import hypot
from itertools import count from itertools import count
from copy import copy from copy import copy
@ -35,7 +34,7 @@ class World:
continue continue
if y_limit and abs(cur[1]) > y_limit: if y_limit and abs(cur[1]) > y_limit:
continue continue
if distance and hypot(*cur) > distance: if distance and utils.hypot(*cur) > distance:
continue continue
check = utils.padd(center, cur) check = utils.padd(center, cur)
@ -76,7 +75,7 @@ class World:
offset = utils.spiral(n) offset = utils.spiral(n)
check = utils.padd(center, offset) check = utils.padd(center, offset)
if self.block_at(*check) in block_ids: if self.block_at(*check) in block_ids:
if hypot(*offset) < distance: if utils.hypot(*offset) < distance:
result.append(check) result.append(check)
if limit and len(result) == limit: if limit and len(result) == limit:
return result return result