Skip to content

Commit

Permalink
set maxStep to avoid "infinite" loop
Browse files Browse the repository at this point in the history
  • Loading branch information
maettu committed Oct 30, 2011
1 parent d0f9dc1 commit f978e43
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions ala/CartesianCoordinateSystemElements/FunctionPlotter.py
Expand Up @@ -60,39 +60,60 @@ def paint(self, painter, option, widget=None):

sp = ep

def getYMin( self, xMin, xMax, xStep):
def getYMin( self, xMin, xMax, xStep, maxStep = 1000):
### return minimal y value in range xMin, xMax. xStep defines exactness. ###
if xStep == 0:
raise Exception( "xStep must not be 0" )

if xMin > xMax:
xMin, xMax = xMax, xMin
if xStep < 0:
xStep = xStep * -1

x = xMin
yMin = self._y( x )

i = 0
while x < xMax:
y = self._y( x )

if y < yMin:
yMin = y

#~ print "x:", x, "yMin:", yMin
# avoid "infinite" loop
if i == maxStep:
return yMin
i+= 1

x = x + xStep

return yMin

def getYMax( self, xMin, xMax, xStep):
def getYMax( self, xMin, xMax, xStep, maxStep = 1000):
### return maximal x value in range xMin, xMax. xStep defines exactness. ###
if xStep == 0:
raise Exception( "xStep must not be 0" )

if xMin > xMax:
xMin, xMax = xMax, xMin
if xStep < 0:
xStep = xStep * -1

x = xMin
yMax = self._y( x )

i = 0
while x < xMax:
y = self._y( x )

if y > yMax:
yMax = y

# avoid "infinite" loop
if i == maxStep:
return yMax
i+=1

x = x + xStep

return yMax
Expand Down

0 comments on commit f978e43

Please sign in to comment.