From e1415cb3a85bec883b6952c859fea8e30de00178 Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Fri, 23 Apr 2021 10:55:37 -0700 Subject: [PATCH] Use np.pi or math.pi instead of just pi --- examples/optics/pyoptic.py | 8 ++++---- pyqtgraph/graphicsItems/ROI.py | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/optics/pyoptic.py b/examples/optics/pyoptic.py index 442a4f5d..99221bd7 100644 --- a/examples/optics/pyoptic.py +++ b/examples/optics/pyoptic.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from math import atan2, asin, sin, cos, sqrt, pi, hypot +from math import atan2, asin, sin, cos, degrees, sqrt, hypot import pyqtgraph as pg from pyqtgraph.Qt import QtGui, QtCore import numpy as np @@ -285,7 +285,7 @@ class Mirror(Optic): p1 = surface.mapToItem(ray, p1) rd = ray['dir'] a1 = atan2(rd[1], rd[0]) - ar = a1 + pi - 2*ai + ar = a1 + np.pi - 2 * ai ray.setEnd(p1) dp = Point(cos(ar), sin(ar)) ray = Ray(parent=ray, dir=dp) @@ -379,7 +379,7 @@ class CircleSurface(pg.GraphicsObject): ## half-height of surface can't be larger than radius h2 = min(h2, abs(r)) arc = QtCore.QRectF(0, -r, r*2, r*2) - a1 = asin(h2/r) * 180. / pi + a1 = degrees(asin(h2/r)) a2 = -2*a1 a1 += 180. self.path.arcMoveTo(arc, a1) @@ -443,7 +443,7 @@ class CircleSurface(pg.GraphicsObject): norm = atan2(pt[1], pt[0]) if r < 0: - norm += pi + norm += np.pi dp = p - pt ang = atan2(dp[1], dp[0]) return pt + Point(r, 0), ang-norm diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index fa63295d..7121947d 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -17,7 +17,7 @@ import numpy as np #from numpy.linalg import norm from ..Point import * from ..SRTTransform import SRTTransform -from math import atan2, cos, sin, pi, sqrt, hypot, radians, degrees +from math import atan2, cos, sin, hypot, radians, degrees from .. import functions as fn from .GraphicsObject import GraphicsObject from .UIGraphicsItem import UIGraphicsItem @@ -1332,8 +1332,8 @@ class Handle(UIGraphicsItem): properties of the ROI they are attached to. """ types = { ## defines number of sides, start angle for each handle type - 't': (4, pi/4), - 'f': (4, pi/4), + 't': (4, np.pi/4), + 'f': (4, np.pi/4), 's': (4, 0), 'r': (12, 0), 'sr': (12, 0), @@ -1481,7 +1481,7 @@ class Handle(UIGraphicsItem): size = self.radius self.path = QtGui.QPainterPath() ang = self.startAng - dt = 2 * pi / self.sides + dt = 2 * np.pi / self.sides for i in range(0, self.sides+1): x = size * cos(ang) y = size * sin(ang) @@ -1911,7 +1911,7 @@ class EllipseROI(ROI): center = br.center() r1 = br.width() / 2. r2 = br.height() / 2. - theta = np.linspace(0, 2 * pi, 24) + theta = np.linspace(0, 2 * np.pi, 24) x = center.x() + r1 * np.cos(theta) y = center.y() + r2 * np.sin(theta) path.moveTo(x[0], y[0]) @@ -2394,6 +2394,8 @@ class TriangleROI(ROI): ROI.__init__(self, pos, [size, size], **args) self.aspectLocked = True angles = np.linspace(0, pi * 4 / 3, 3) + ROI.__init__(self, pos, [size, size], aspectLocked=True, **args) + angles = np.linspace(0, np.pi * 4 / 3, 3) verticies = (np.array((np.sin(angles), np.cos(angles))).T + 1.0) / 2.0 self.poly = QtGui.QPolygonF() for pt in verticies: