1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
# -*- coding: utf-8 -*-
#
# Licensed under the terms of the Qwt License
# Copyright (c) 2002 Uwe Rathmann, for the original C++ code
# Copyright (c) 2015 Pierre Raybaut, for the Python translation/optimization
# (see LICENSE file for more details)
import math
from qtpy.QtCore import qFuzzyCompare
def qwtFuzzyCompare(value1, value2, intervalSize):
eps = abs(1.0e-6 * intervalSize)
if value2 - value1 > eps:
return -1
elif value1 - value2 > eps:
return 1
else:
return 0
def qwtFuzzyGreaterOrEqual(d1, d2):
return (d1 >= d2) or qFuzzyCompare(d1, d2)
def qwtFuzzyLessOrEqual(d1, d2):
return (d1 <= d2) or qFuzzyCompare(d1, d2)
def qwtSign(x):
if x > 0.0:
return 1
elif x < 0.0:
return -1
else:
return 0
def qwtSqr(x):
return x**2
def qwtFastAtan(x):
if x < -1.0:
return -0.5 * math.pi - x / (x**2 + 0.28)
elif x > 1.0:
return 0.5 * math.pi - x / (x**2 + 0.28)
else:
return x / (1.0 + x**2 * 0.28)
def qwtFastAtan2(y, x):
if x > 0:
return qwtFastAtan(y / x)
elif x < 0:
d = qwtFastAtan(y / x)
if y >= 0:
return d + math.pi
else:
return d - math.pi
elif y < 0.0:
return -0.5 * math.pi
elif y > 0.0:
return 0.5 * math.pi
else:
return 0.0
def qwtRadians(degrees):
return degrees * math.pi / 180.0
def qwtDegrees(radians):
return radians * 180.0 / math.pi
|