RecursionError при вызове math.dist()Python

Программы на Python
Anonymous
RecursionError при вызове math.dist()

Сообщение Anonymous »

При вызове math.dist() для определения расстояния между двумя точками я получаю ошибку RecursionError.
Это ошибка:

Код: Выделить всё

Traceback (most recent call last):
File "/Users/myName/Desktop/2D Renderer.py", line 76, in 
mainLoop()
File "/Users/myName/Desktop/2D Renderer.py", line 74, in mainLoop
canvas.after(10,mainLoop())
File "/Users/myName/Desktop/2D Renderer.py", line 74, in mainLoop
canvas.after(10,mainLoop())
File "/Users/myName/Desktop/2D Renderer.py", line 74, in mainLoop
canvas.after(10,mainLoop())
[Previous line repeated 1018 more times]
File "/Users/myName/Desktop/2D Renderer.py", line 71, in mainLoop
result, color, x = checkRay([0,5],100)
File "/Users/myName/Desktop/2D Renderer.py", line 48, in checkRay
result, color = checkPoint(position)
File "/Users/myName/Desktop/2D Renderer.py", line 56, in checkPoint
result = sdCircle(position,shape.radius,shape.position)
File "/Users/myName/Desktop/2D Renderer.py", line 66, in sdCircle
return math.dist(position,circlePosition) - circleRadius;
RecursionError: maximum recursion depth exceeded while calling a Python object
Я попытался изменить свой код для запуска Canvas.after(10,mainLoop()) в бесконечном цикле while, но это привело к зависанию. Вот мой код:

Код: Выделить всё

from tkinter import *
from tkinter import ttk
from enum import Enum
import math
root = Tk()
root.title("2D Renderer")
canvas = Canvas(root, width=500, height=50, background='gray75')
canvas.grid(column=0,row=0)

class Player:
def __init__(self,position,rotation):
self.position = position
self.rotation = rotation

player = Player([0,0],[0,1])

def setPixel(x,y,color):
canvas.create_rectangle(x+3, y+3, x+3, y+3, outline="",fill=color)

def setPixel1D(x,color):
canvas.create_line(x+3, 0, x+3, 50,fill='red')

class Shapes(Enum):
CIRCLE = 1
SQUARE = 2

class Shape:
def __init__(self,shape: Shapes,position,radius,color):
self.shape = shape
self.position = position
self.radius = radius
self.color = color

shapes = [Shape(Shapes.CIRCLE,[0,100],50,'ff0000')]

def normalizeVector(vector):
length = math.sqrt(vector[0] * vector[0] + vector[1] * vector[1])
vector[0] /= length
vector[1] /= length
return vector

def checkRay(vector,max_steps):
vector = normalizeVector(vector)
position = player.position
for i in range(max_steps):
position[0] += vector[0]
position[1] += vector[1]
result, color = checkPoint(position)
if result:
return True, color, position[0] / position[1] - player.position[1]
return False, None, None

def checkPoint(position):
for shape in shapes:
if shape.shape == Shapes.CIRCLE:
result = sdCircle(position,shape.radius,shape.position)
if result 

Подробнее здесь: [url]https://stackoverflow.com/questions/78704989/recursionerror-when-calling-math-dist[/url]

Вернуться в «Python»