From 2fe749bb23dd7873cd85017077e8995703a61f36 Mon Sep 17 00:00:00 2001 From: Star Brilliant Date: Tue, 10 Jun 2014 19:46:48 +0800 Subject: [PATCH] ZeroDivisionError handling in ConvertFlashRotation --- danmaku2ass.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/danmaku2ass.py b/danmaku2ass.py index 6bdc91e..59cbd43 100755 --- a/danmaku2ass.py +++ b/danmaku2ass.py @@ -532,10 +532,14 @@ def ConvertFlashRotation(rotY, rotZ, X, Y, width, height): trY = Y*math.cos(rotZ)-X*math.sin(rotZ)+math.sin(rotZ)*width/2+(1-math.cos(rotZ))*height/2 trZ = (trX-width/2)*math.sin(rotY) FOV = width*math.tan(2*math.pi/9.0)/2 - scaleXY = FOV/(FOV+trZ) - if scaleXY < 0: + try + scaleXY = FOV/(FOV+trZ) + except ZeroDivisionError: + logging.error('Rotation makes object behind the camera: trZ == %.0f' % trZ); scaleXY = 1 - logging.error('Clipped rotation: trZ == %.0f < %.0f' % (trZ, FOV)); + if scaleXY < 0: + scaleXY = -scaleXY + logging.error('Rotation makes object behind the camera: trZ == %.0f < %.0f' % (trZ, FOV)); trX = (trX-width/2)*scaleXY+width/2 trY = (trY-height/2)*scaleXY+height/2 return (round(trX), round(trY), WrapAngle(round(outX)), WrapAngle(round(outY)), WrapAngle(round(outZ)), round(scaleXY*100), round(scaleXY*100))