Skip to content

Commit 1adb337

Browse files
committed
Renamed qwt.math to qwt._math (+ some simplifications)
1 parent 233b507 commit 1adb337

File tree

7 files changed

+98
-99
lines changed

7 files changed

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

qwt/plot_curve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from .text import QwtText
1717
from .plot import QwtPlotItem, QwtPlotItem_PrivateData
18-
from .math import qwtSqr
18+
from ._math import qwtSqr
1919
from .graphic import QwtGraphic
2020
from .plot_series import (QwtPlotSeriesItem, QwtSeriesStore, QwtSeriesData,
2121
QwtPointArrayData)

qwt/plot_grid.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
from .scale_div import QwtScaleDiv
1717
from .plot import QwtPlotItem
1818
from .text import QwtText
19-
from .painter import QwtPainter
20-
from .math import qwtFuzzyGreaterOrEqual, qwtFuzzyLessOrEqual
19+
from ._math import qwtFuzzyGreaterOrEqual, qwtFuzzyLessOrEqual
2120

2221
from .qt.QtGui import QPen
2322
from .qt.QtCore import Qt

qwt/scale_draw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .scale_div import QwtScaleDiv
2323
from .scale_map import QwtScaleMap
2424
from .text import QwtText
25-
from .math import qwtRadians
25+
from ._math import qwtRadians
2626

2727
from .qt.QtGui import QPalette, QFontMetrics, QTransform
2828
from .qt.QtCore import (Qt, qFuzzyCompare, QLocale, QRectF, QPointF, QRect,

qwt/scale_engine.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,34 @@
3030
from .interval import QwtInterval
3131
from .scale_div import QwtScaleDiv
3232
from .transform import QwtLogTransform
33-
from .math import qwtFuzzyCompare
33+
from ._math import qwtFuzzyCompare
3434
from .transform import QwtTransform
3535

3636
from .qt.QtCore import qFuzzyCompare
3737

38+
import sys
39+
import math
3840
import numpy as np
3941

40-
DBL_MAX = np.finfo(float).max
42+
DBL_MAX = sys.float_info.max
4143
LOG_MIN = 1.0e-100
4244
LOG_MAX = 1.0e100
4345

4446

45-
def qwtLog(base, value):
46-
return np.log(value)/np.log(base)
47-
4847
def qwtLogInterval(base, interval):
49-
return QwtInterval(qwtLog(base, interval.minValue()),
50-
qwtLog(base, interval.maxValue()))
48+
return QwtInterval(math.log(interval.minValue(), base),
49+
math.log(interval.maxValue(), base))
5150

5251
def qwtPowInterval(base, interval):
53-
return QwtInterval(np.power(base, interval.minValue()),
54-
np.power(base, interval.maxValue()))
52+
return QwtInterval(math.pow(base, interval.minValue()),
53+
math.pow(base, interval.maxValue()))
5554

5655
def qwtStepSize(intervalSize, maxSteps, base):
5756
"""this version often doesn't find the best ticks: f.e for 15: 5, 10"""
5857
minStep = divideInterval(intervalSize, maxSteps, base)
5958
if minStep != 0.:
6059
# # ticks per interval
61-
numTicks = np.ceil(abs(intervalSize/minStep))-1
60+
numTicks = math.ceil(abs(intervalSize/minStep))-1
6261
# Do the minor steps fit into the interval?
6362
if qwtFuzzyCompare((numTicks+1)*abs(minStep),
6463
abs(intervalSize), intervalSize) > 0:
@@ -82,7 +81,7 @@ def ceilEps(value, intervalSize):
8281
"""
8382
eps = EPS*intervalSize
8483
value = (value-eps)/intervalSize
85-
return np.ceil(value)*intervalSize
84+
return math.ceil(value)*intervalSize
8685

8786
def floorEps(value, intervalSize):
8887
"""
@@ -98,7 +97,7 @@ def floorEps(value, intervalSize):
9897
"""
9998
eps = EPS*intervalSize
10099
value = (value+eps)/intervalSize
101-
return np.floor(value)*intervalSize
100+
return math.floor(value)*intervalSize
102101

103102
def divideEps(intervalSize, numSteps):
104103
"""
@@ -129,14 +128,15 @@ def divideInterval(intervalSize, numSteps, base):
129128
if v == 0.:
130129
return 0.
131130

132-
lx = qwtLog(base, abs(v))
133-
p = np.floor(lx)
134-
fraction = np.power(base, lx-p)
131+
lx = math.log(abs(v), base)
132+
p = math.floor(lx)
133+
print("p:", p)
134+
fraction = math.pow(base, lx-p)
135135
n = base
136136
while n > 1 and fraction <= n/2:
137137
n /= 2
138138

139-
stepSize = n*np.power(base, p)
139+
stepSize = n*math.pow(base, p)
140140
if v < 0:
141141
stepSize = -stepSize
142142

@@ -580,7 +580,7 @@ def buildMinorTicks(self, ticks, maxMinorSteps, stepSize):
580580
minStep = qwtStepSize(stepSize, maxMinorSteps, self.base())
581581
if minStep == 0.:
582582
return
583-
numTicks = int(np.ceil(abs(stepSize/minStep))-1)
583+
numTicks = int(math.ceil(abs(stepSize/minStep))-1)
584584
medIndex = -1
585585
if numTicks % 2:
586586
medIndex = numTicks/2
@@ -653,8 +653,8 @@ def autoScale(self, maxNumSteps, x1, x2, stepSize):
653653
if x1 > x2:
654654
x1, x2 = x2, x1
655655
logBase = self.base()
656-
interval = QwtInterval(x1/np.power(logBase, self.lowerMargin()),
657-
x2*np.power(logBase, self.upperMargin()))
656+
interval = QwtInterval(x1/math.pow(logBase, self.lowerMargin()),
657+
x2*math.pow(logBase, self.upperMargin()))
658658
interval = interval.limited(LOG_MIN, LOG_MAX)
659659
if interval.maxValue()/interval.minValue() < logBase:
660660
linearScaler = QwtLinearScaleEngine()
@@ -670,9 +670,9 @@ def autoScale(self, maxNumSteps, x1, x2, stepSize):
670670

671671
if linearInterval.maxValue()/linearInterval.minValue() < logBase:
672672
if stepSize < 0.:
673-
stepSize = -qwtLog(logBase, abs(stepSize))
673+
stepSize = -math.log(abs(stepSize), logBase)
674674
else:
675-
stepSize = qwtLog(logBase, stepSize)
675+
stepSize = math.log(stepSize, logBase)
676676
return x1, x2, stepSize
677677

678678
logRef = 1.
@@ -785,13 +785,13 @@ def buildMajorTicks(self, interval, stepSize):
785785
width = qwtLogInterval(self.base(), interval).width()
786786
numTicks = min([int(round(width/stepSize))+1, 10000])
787787

788-
lxmin = np.log(interval.minValue())
789-
lxmax = np.log(interval.maxValue())
788+
lxmin = math.log(interval.minValue())
789+
lxmax = math.log(interval.maxValue())
790790
lstep = (lxmax-lxmin)/float(numTicks-1)
791791

792792
ticks = [interval.minValue()]
793793
for i in range(1, numTicks-1):
794-
ticks += [np.exp(lxmin+float(i)*lstep)]
794+
ticks += [math.exp(lxmin+float(i)*lstep)]
795795
ticks += [interval.maxValue()]
796796
return ticks
797797

@@ -851,7 +851,7 @@ def buildMinorTicks(self, ticks, maxMinorSteps, stepSize):
851851
if numTicks > 2 and numTicks % 2:
852852
mediumTickIndex = numTicks/2
853853

854-
minFactor = max([np.power(logBase, minStep), float(logBase)])
854+
minFactor = max([math.pow(logBase, minStep), float(logBase)])
855855

856856
for tick in ticks[QwtScaleDiv.MajorTick]:
857857
for j in range(numTicks):

qwt/scale_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
:members:
1414
"""
1515

16-
from .math import qwtFuzzyCompare
16+
from ._math import qwtFuzzyCompare
1717

1818
from .qt.QtCore import QRectF, QPointF
1919

qwt/tests/no_margin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ def show_layout_details(self):
100100
if __name__ == '__main__':
101101
app = QApplication([])
102102
plot = TestPlot()
103-
plot.resize(300, 1000)
103+
plot.resize(300, 650)
104104
plot.show()
105105
app.exec_()

0 commit comments

Comments
 (0)