Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

set maxStep to avoid "infinite" loop

  • Loading branch information...
commit f978e436aa9a4176a91101bcfb6eea8c0dfcd9b1 1 parent d0f9dc1
@maettu authored
Showing with 24 additions and 3 deletions.
  1. +24 −3 ala/CartesianCoordinateSystemElements/FunctionPlotter.py
View
27 ala/CartesianCoordinateSystemElements/FunctionPlotter.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.