Skip to content

Remove duplicate code (mesh_masks) #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 5 additions & 126 deletions fastplotlib/graphics/_features/_selection_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,131 +2,10 @@

import numpy as np

from ...utils import mesh_masks
from ._base import GraphicFeature, FeatureEvent


"""
positions for indexing the BoxGeometry to set the "width" and "size" of the box
hacky, but I don't think we can morph meshes in pygfx yet: https://github.com/pygfx/pygfx/issues/346
"""

x_right = np.array(
[
True,
True,
True,
True,
False,
False,
False,
False,
False,
True,
False,
True,
True,
False,
True,
False,
False,
True,
False,
True,
True,
False,
True,
False,
]
)

x_left = np.array(
[
False,
False,
False,
False,
True,
True,
True,
True,
True,
False,
True,
False,
False,
True,
False,
True,
True,
False,
True,
False,
False,
True,
False,
True,
]
)

y_top = np.array(
[
False,
True,
False,
True,
False,
True,
False,
True,
True,
True,
True,
True,
False,
False,
False,
False,
False,
False,
True,
True,
False,
False,
True,
True,
]
)

y_bottom = np.array(
[
True,
False,
True,
False,
True,
False,
True,
False,
False,
False,
False,
False,
True,
True,
True,
True,
True,
True,
False,
False,
True,
True,
False,
False,
]
)


class LinearSelectionFeature(GraphicFeature):
# A bit much to have a class for this but this allows it to integrate with the fastplotlib callback system
"""
Expand Down Expand Up @@ -253,10 +132,10 @@ def _set(self, value: Tuple[float, float]):

if self.axis == "x":
# change left x position of the fill mesh
self._parent.fill.geometry.positions.data[x_left, 0] = value[0]
self._parent.fill.geometry.positions.data[mesh_masks.x_left] = value[0]

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

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

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

# change top position of the fill mesh
self._parent.fill.geometry.positions.data[y_top, 1] = value[1]
self._parent.fill.geometry.positions.data[mesh_masks.y_top] = value[1]

# change y position of the bottom edge line
self._parent.edges[0].geometry.positions.data[:, 1] = value[0]
Expand Down
12 changes: 8 additions & 4 deletions fastplotlib/graphics/_features/_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def _fix_sizes(self, sizes, parent):
if graphic_type == "ScatterGraphic":
sizes = np.array(sizes)
else:
raise ValueError(f"Sizes must be an array of shape (n,) where n == the number of data points provided.\
Received shape={sizes.shape}.")
raise ValueError(
f"Sizes must be an array of shape (n,) where n == the number of data points provided.\
Received shape={sizes.shape}."
)

return np.array(sizes)

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

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

self.buffer.data[key] = value
self._update_range(key)
Expand Down
1 change: 0 additions & 1 deletion fastplotlib/graphics/selectors/_mesh_positions.py

This file was deleted.

10 changes: 5 additions & 5 deletions fastplotlib/graphics/selectors/_rectangle_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import pygfx

from ...utils import mesh_masks
from .._base import Graphic
from .._features import GraphicFeature
from ._base_selector import BaseSelector
from ._mesh_positions import x_right, x_left, y_top, y_bottom


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

# change fill mesh
# change left x position of the fill mesh
self._parent.fill.geometry.positions.data[x_left, 0] = xmin
self._parent.fill.geometry.positions.data[mesh_masks.x_left] = xmin

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

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

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

# change the edge lines

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy