• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

APN-Pucky / pyfeyn2 / 14318039396

07 Apr 2025 07:42PM UTC coverage: 67.018% (-1.3%) from 68.287%
14318039396

push

github

web-flow
Update gallery (#317)

* Add coment

* Add wikipedia like examples

Closes: #85

* Add feynmf examples

* Update gallery

* Fix serializer config indent

* No more feynml particle access

* dot2tex fixes

* clean

* add xcolor

* old dot2tex

* more fixes

* Fixed versions

* again

* again...

* uff

* Final

* more

* Timeout mermaid requests

* None on timeout

9 of 16 new or added lines in 4 files covered. (56.25%)

108 existing lines in 6 files now uncovered.

2160 of 3223 relevant lines covered (67.02%)

0.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pyfeyn2/render/pyx/blobs.py
1
"""Various blob shapes to represent generic interactions."""
2

UNCOV
3
import pyx
×
4

UNCOV
5
from pyfeyn2.render.pyx import config
×
UNCOV
6
from pyfeyn2.render.pyx.deco import PointLabel
×
UNCOV
7
from pyfeyn2.render.pyx.diagrams import FeynDiagram
×
UNCOV
8
from pyfeyn2.render.pyx.paint import BLACK, CENTER, WHITE
×
UNCOV
9
from pyfeyn2.render.pyx.points import Point
×
UNCOV
10
from pyfeyn2.render.pyx.utils import Visible
×
11

12

13
## Blob base class
UNCOV
14
class Blob(Point, Visible):
×
15
    "Base class for all blob-like objects in Feynman diagrams"
16

UNCOV
17
    def __init__(
×
18
        self,
19
        x,
20
        y,
21
        trafos=[],
22
        points=[],
23
        fill=[],
24
        stroke=[],
25
        blob=None,
26
        labels=[],
27
        **kwargs
28
    ):
29
        """Constructor."""
30
        Point.__init__(self, x, y, blob, labels)
×
31
        self.trafos = trafos
×
32
        self.points = points
×
33
        self.fillstyles = fill
×
34
        self.strokestyles = stroke
×
35
        self.layeroffset = 1000
×
36

UNCOV
37
    def setStrokeStyle(self, strokestyle):
×
38
        """Set the stroke style."""
39
        self.strokestyles = [strokestyle]
×
40
        return self
×
41

UNCOV
42
    def clearStrokeStyles(self):
×
43
        """Remove all the current stroke styles."""
44
        self.strokestyles = []
×
45
        return self
×
46

UNCOV
47
    def setFillStyle(self, fillstyle):
×
48
        """Set the fill style."""
49
        self.fillstyles = [fillstyle]
×
50
        return self
×
51

UNCOV
52
    def clearFillStyles(self):
×
53
        """Remove all the current fill styles."""
54
        self.fillstyles = []
×
55
        return self
×
56

UNCOV
57
    def addTrafo(self, trafo):
×
58
        """Add a transformation."""
59
        self.trafos.append(trafo)
×
60
        return self
×
61

UNCOV
62
    def clearTrafos(self):
×
63
        """Remove transformations."""
64
        self.trafos = []
×
65
        return self
×
66

UNCOV
67
    def setPoints(self, points):
×
68
        """Set the points to which this blob is attached."""
69
        if points:
×
70
            self.points = points
×
71
            for p in self.points:
×
72
                p.blob = self
×
73
        else:
74
            self.points = []
×
75

UNCOV
76
    def addLabel(
×
77
        self,
78
        text,
79
        displace=-0.15,
80
        angle=0,
81
        size=pyx.text.size.normalsize,
82
        halign=CENTER,
83
        valign=None,
84
    ):
85
        """Add a label."""
86
        if config.getOptions().DEBUG:
×
87
            print("Adding label: " + text)
×
88
        self.labels.append(
×
89
            PointLabel(
90
                text=text,
91
                point=self,
92
                displace=displace,
93
                angle=angle,
94
                size=size,
95
                halign=halign,
96
                valign=valign,
97
            )
98
        )
99
        if config.getOptions().DEBUG:
×
100
            print("Labels = " + str(self.labels))
×
101
        return self
×
102

UNCOV
103
    def clearLabels(self):
×
104
        """Remove all current labels."""
105
        self.labels = []
×
106
        return self
×
107

108

109
## Circle class (a kind of Blob)
UNCOV
110
class Circle(Blob):
×
111
    """A circular blob"""
112

UNCOV
113
    blobshape = "circle"
×
114

UNCOV
115
    def __init__(
×
116
        self,
117
        x=None,
118
        y=None,
119
        center=None,
120
        radius=None,
121
        fill=[WHITE],
122
        stroke=[BLACK],
123
        points=[],
124
        blob=None,
125
        labels=[],
126
        **kwargs
127
    ):
128
        xx = 0
×
129
        yy = 0
×
130
        if x is not None and y is not None:
×
131
            xx = x
×
132
            yy = y
×
133
        elif center is not None:
×
134
            xx = center.getX()
×
135
            yy = center.getY()
×
136
        else:
137
            raise Exception("No center specified for blob.")
×
138

139
        """Constructor."""
×
140
        Blob.__init__(self, xx, yy, [], points, fill, stroke, blob, labels)
×
141

142
        if radius:
×
143
            self.radius = float(radius)
×
144
        else:
145
            raise Exception("No (or zero) radius specified for blob.")
×
146

147
        ## Add this to the current diagram automatically
148
        FeynDiagram.currentDiagram.add(self)
×
149

UNCOV
150
    def getPath(self):
×
151
        """Get the path of this circle blob."""
152
        return pyx.path.circle(self.getX(), self.getY(), self.radius)
×
153

UNCOV
154
    def draw(self, canvas):
×
155
        """Draw this circle blob."""
156
        canvas.fill(self.getPath(), [pyx.color.rgb.white])
×
157
        canvas.fill(self.getPath(), self.fillstyles)
×
158
        canvas.stroke(self.getPath(), self.strokestyles)
×
159
        for l in self.labels:
×
160
            l.draw(canvas)
×
161

162

163
## Ellipse class (a kind of Blob)
UNCOV
164
class Ellipse(Blob):
×
165
    "An elliptical blob"
UNCOV
166
    blobshape = "ellipse"
×
167

UNCOV
168
    def __init__(
×
169
        self,
170
        x=None,
171
        y=None,
172
        center=None,
173
        xradius=None,
174
        yradius=None,
175
        fill=[WHITE],
176
        stroke=[BLACK],
177
        trafos=[],
178
        points=[],
179
        blob=None,
180
        labels=[],
181
        **kwargs
182
    ):
183
        xx = 0
×
184
        yy = 0
×
185
        if x is not None and y is not None:
×
186
            xx = x
×
187
            yy = y
×
188
        elif center is not None:
×
189
            xx = center.getX()
×
190
            yy = center.getY()
×
191
        else:
192
            raise Exception("No center specified for blob.")
×
193

194
        """Constructor."""
×
195
        Blob.__init__(self, xx, yy, trafos, points, fill, stroke, blob, labels)
×
196

197
        self.xrad = None
×
198
        if xradius:
×
199
            self.setXRadius(xradius)
×
200
        elif yradius:
×
201
            self.setXRadius(yradius)
×
202
        else:
203
            raise Exception("No viable candidate for x-radius")
×
204
        self.yrad = None
×
205
        if yradius:
×
206
            self.setYRadius(yradius)
×
207
        elif xradius:
×
208
            self.setYRadius(xradius)
×
209
        else:
210
            raise Exception("No viable candidate for y-radius")
×
211

212
        ## Add this to the current diagram automatically
213
        FeynDiagram.currentDiagram.add(self)
×
214

UNCOV
215
    def getXRadius(self):
×
216
        """Get the component of the radius in the x-direction."""
217
        return self.xrad
×
218

UNCOV
219
    def setXRadius(self, xrad):
×
220
        """Set the component of the radius in the x-direction."""
221
        self.xrad = float(xrad)
×
222
        return self
×
223

UNCOV
224
    def getYRadius(self):
×
225
        """Get the component of the radius in the y-direction."""
226
        return self.yrad
×
227

UNCOV
228
    def setYRadius(self, yrad):
×
229
        """Set the component of the radius in the y-direction."""
230
        self.yrad = float(yrad)
×
231
        return self
×
232

UNCOV
233
    def getXYRadius(self):
×
234
        """Get the components of the radius in the x and y
235
        directions at the same time."""
236
        return self.getXRadius(), self.getYRadius()
×
237

UNCOV
238
    def setXYRadius(self, xrad, yrad):
×
239
        """Get the components of the radius in the x and y
240
        directions at the same time."""
241
        self.setXRadius(xrad)
×
242
        self.setYRadius(yrad)
×
243
        return self
×
244

UNCOV
245
    def getPath(self):
×
246
        """Get the path for this blob."""
247
        ucircle = pyx.path.circle(self.xpos, self.ypos, 1.0)
×
248
        mytrafo = pyx.trafo.scale(self.xrad, self.yrad, self.xpos, self.ypos)
×
249
        epath = ucircle.transformed(mytrafo)
×
250
        return epath
×
251

UNCOV
252
    def draw(self, canvas):
×
253
        """Draw this blob on the given canvas."""
254
        canvas.fill(self.getPath(), [pyx.color.rgb.white])
×
255
        canvas.fill(self.getPath(), self.fillstyles)
×
256
        # canvas.stroke(self.getPath(), [pyx.color.rgb.white])
257
        canvas.stroke(self.getPath(), self.strokestyles)
×
258
        for l in self.labels:
×
259
            l.draw(canvas)
×
260

261

262
## A dictionary to map feynML blob shape choices to blob classes
UNCOV
263
NamedBlob = {"circle": Circle, "ellipse": Ellipse}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc