Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 775556e

Browse files
authored
Remove duplicate code (mesh_masks) (#430)
* Remove duplicate code * Ah, even better
1 parent d45c723 commit 775556e

File tree

4 files changed

+18
-136
lines changed

4 files changed

+18
-136
lines changed

fastplotlib/graphics/_features/_selection_features.py

Lines changed: 5 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -2,131 +2,10 @@
22

33
import numpy as np
44

5+
from ...utils import mesh_masks
56
from ._base import GraphicFeature, FeatureEvent
67

78

8-
"""
9-
positions for indexing the BoxGeometry to set the "width" and "size" of the box
10-
hacky, but I don't think we can morph meshes in pygfx yet: https://github.com/pygfx/pygfx/issues/346
11-
"""
12-
13-
x_right = np.array(
14-
[
15-
True,
16-
True,
17-
True,
18-
True,
19-
False,
20-
False,
21-
False,
22-
False,
23-
False,
24-
True,
25-
False,
26-
True,
27-
True,
28-
False,
29-
True,
30-
False,
31-
False,
32-
True,
33-
False,
34-
True,
35-
True,
36-
False,
37-
True,
38-
False,
39-
]
40-
)
41-
42-
x_left = np.array(
43-
[
44-
False,
45-
False,
46-
False,
47-
False,
48-
True,
49-
True,
50-
True,
51-
True,
52-
True,
53-
False,
54-
True,
55-
False,
56-
False,
57-
True,
58-
False,
59-
True,
60-
True,
61-
False,
62-
True,
63-
False,
64-
False,
65-
True,
66-
False,
67-
True,
68-
]
69-
)
70-
71-
y_top = np.array(
72-
[
73-
False,
74-
True,
75-
False,
76-
True,
77-
False,
78-
True,
79-
False,
80-
True,
81-
True,
82-
True,
83-
True,
84-
True,
85-
False,
86-
False,
87-
False,
88-
False,
89-
False,
90-
False,
91-
True,
92-
True,
93-
False,
94-
False,
95-
True,
96-
True,
97-
]
98-
)
99-
100-
y_bottom = np.array(
101-
[
102-
True,
103-
False,
104-
True,
105-
False,
106-
True,
107-
False,
108-
True,
109-
False,
110-
False,
111-
False,
112-
False,
113-
False,
114-
True,
115-
True,
116-
True,
117-
True,
118-
True,
119-
True,
120-
False,
121-
False,
122-
True,
123-
True,
124-
False,
125-
False,
126-
]
127-
)
128-
129-
1309
class LinearSelectionFeature(GraphicFeature):
13110
# A bit much to have a class for this but this allows it to integrate with the fastplotlib callback system
13211
"""
@@ -253,10 +132,10 @@ def _set(self, value: Tuple[float, float]):
253132

254133
if self.axis == "x":
255134
# change left x position of the fill mesh
256-
self._parent.fill.geometry.positions.data[x_left, 0] = value[0]
135+
self._parent.fill.geometry.positions.data[mesh_masks.x_left] = value[0]
257136

258137
# change right x position of the fill mesh
259-
self._parent.fill.geometry.positions.data[x_right, 0] = value[1]
138+
self._parent.fill.geometry.positions.data[mesh_masks.x_right] = value[1]
260139

261140
# change x position of the left edge line
262141
self._parent.edges[0].geometry.positions.data[:, 0] = value[0]
@@ -266,10 +145,10 @@ def _set(self, value: Tuple[float, float]):
266145

267146
elif self.axis == "y":
268147
# change bottom y position of the fill mesh
269-
self._parent.fill.geometry.positions.data[y_bottom, 1] = value[0]
148+
self._parent.fill.geometry.positions.data[mesh_masks.y_bottom] = value[0]
270149

271150
# change top position of the fill mesh
272-
self._parent.fill.geometry.positions.data[y_top, 1] = value[1]
151+
self._parent.fill.geometry.positions.data[mesh_masks.y_top] = value[1]
273152

274153
# change y position of the bottom edge line
275154
self._parent.edges[0].geometry.positions.data[:, 1] = value[0]

fastplotlib/graphics/_features/_sizes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ def _fix_sizes(self, sizes, parent):
6161
if graphic_type == "ScatterGraphic":
6262
sizes = np.array(sizes)
6363
else:
64-
raise ValueError(f"Sizes must be an array of shape (n,) where n == the number of data points provided.\
65-
Received shape={sizes.shape}.")
64+
raise ValueError(
65+
f"Sizes must be an array of shape (n,) where n == the number of data points provided.\
66+
Received shape={sizes.shape}."
67+
)
6668

6769
return np.array(sizes)
6870

@@ -78,8 +80,10 @@ def __setitem__(self, key, value):
7880
# numpy will throw errors if it can't broadcast
7981

8082
if value.size != self.buffer.data[key].size:
81-
raise ValueError(f"{value.size} is not equal to buffer size {self.buffer.data[key].size}.\
82-
If you want to set size to a non-scalar value, make sure it's the right length!")
83+
raise ValueError(
84+
f"{value.size} is not equal to buffer size {self.buffer.data[key].size}.\
85+
If you want to set size to a non-scalar value, make sure it's the right length!"
86+
)
8387

8488
self.buffer.data[key] = value
8589
self._update_range(key)

fastplotlib/graphics/selectors/_mesh_positions.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

fastplotlib/graphics/selectors/_rectangle_region.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import pygfx
55

6+
from ...utils import mesh_masks
67
from .._base import Graphic
78
from .._features import GraphicFeature
89
from ._base_selector import BaseSelector
9-
from ._mesh_positions import x_right, x_left, y_top, y_bottom
1010

1111

1212
class RectangleBoundsFeature(GraphicFeature):
@@ -58,16 +58,16 @@ def _set(self, value: Tuple[float, float, float, float]):
5858

5959
# change fill mesh
6060
# change left x position of the fill mesh
61-
self._parent.fill.geometry.positions.data[x_left, 0] = xmin
61+
self._parent.fill.geometry.positions.data[mesh_masks.x_left] = xmin
6262

6363
# change right x position of the fill mesh
64-
self._parent.fill.geometry.positions.data[x_right, 0] = xmax
64+
self._parent.fill.geometry.positions.data[mesh_masks.x_right] = xmax
6565

6666
# change bottom y position of the fill mesh
67-
self._parent.fill.geometry.positions.data[y_bottom, 1] = ymin
67+
self._parent.fill.geometry.positions.data[mesh_masks.y_bottom] = ymin
6868

6969
# change top position of the fill mesh
70-
self._parent.fill.geometry.positions.data[y_top, 1] = ymax
70+
self._parent.fill.geometry.positions.data[mesh_masks.y_top] = ymax
7171

7272
# change the edge lines
7373

0 commit comments

Comments
 (0)