Skip to content
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

Simplify line _internal_build_extend #1294

Merged
merged 1 commit into from
Oct 19, 2023
Merged
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
93 changes: 37 additions & 56 deletions datashader/glyphs/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ def _build_extend(self, x_mapper, y_mapper, info, append, antialias_stage_2, ant
x_mapper, y_mapper, info, append, self._line_width, antialias_stage_2, antialias_stage_2_funcs)


def _line_internal_build_extend(
x_mapper, y_mapper, append, line_width, antialias_stage_2, antialias_stage_2_funcs,
expand_aggs_and_cols,
):
antialias = line_width > 0
map_onto_pixel = _build_map_onto_pixel_for_line(x_mapper, y_mapper, antialias)
overwrite, use_2_stage_agg = two_stage_agg(antialias_stage_2)
if not use_2_stage_agg:
antialias_stage_2_funcs = None
draw_segment = _build_draw_segment(
append, map_onto_pixel, expand_aggs_and_cols, line_width, overwrite,
)
return draw_segment, antialias_stage_2_funcs


class LineAxis0(_PointLike, _AntiAliasedLine):
"""A line, with vertices defined by ``x`` and ``y``.

Expand All @@ -49,19 +64,15 @@ class LineAxis0(_PointLike, _AntiAliasedLine):
@memoize
def _internal_build_extend(
self, x_mapper, y_mapper, info, append, line_width, antialias_stage_2, antialias_stage_2_funcs):
antialias = line_width > 0
expand_aggs_and_cols = self.expand_aggs_and_cols(append)
map_onto_pixel = _build_map_onto_pixel_for_line(
x_mapper, y_mapper, antialias)
overwrite, use_2_stage_agg = two_stage_agg(antialias_stage_2)
if not use_2_stage_agg:
antialias_stage_2_funcs = None
draw_segment = _build_draw_segment(
append, map_onto_pixel, expand_aggs_and_cols, line_width, overwrite
draw_segment, antialias_stage_2_funcs = _line_internal_build_extend(
x_mapper, y_mapper, append, line_width, antialias_stage_2, antialias_stage_2_funcs,
expand_aggs_and_cols,
)
extend_cpu, extend_cuda = _build_extend_line_axis0(
draw_segment, expand_aggs_and_cols, antialias_stage_2_funcs,
)

x_name = self.x
y_name = self.y

Expand Down Expand Up @@ -144,15 +155,10 @@ def compute_bounds_dask(self, ddf):
@memoize
def _internal_build_extend(
self, x_mapper, y_mapper, info, append, line_width, antialias_stage_2, antialias_stage_2_funcs):
antialias = line_width > 0
expand_aggs_and_cols = self.expand_aggs_and_cols(append)
map_onto_pixel = _build_map_onto_pixel_for_line(
x_mapper, y_mapper, antialias)
overwrite, use_2_stage_agg = two_stage_agg(antialias_stage_2)
if not use_2_stage_agg:
antialias_stage_2_funcs = None
draw_segment = _build_draw_segment(
append, map_onto_pixel, expand_aggs_and_cols, line_width, overwrite
draw_segment, antialias_stage_2_funcs = _line_internal_build_extend(
x_mapper, y_mapper, append, line_width, antialias_stage_2, antialias_stage_2_funcs,
expand_aggs_and_cols,
)
extend_cpu, extend_cuda = _build_extend_line_axis0_multi(
draw_segment, expand_aggs_and_cols, antialias_stage_2_funcs,
Expand Down Expand Up @@ -262,15 +268,10 @@ def compute_bounds_dask(self, ddf):
@memoize
def _internal_build_extend(
self, x_mapper, y_mapper, info, append, line_width, antialias_stage_2, antialias_stage_2_funcs):
antialias = line_width > 0
expand_aggs_and_cols = self.expand_aggs_and_cols(append)
map_onto_pixel = _build_map_onto_pixel_for_line(
x_mapper, y_mapper, antialias)
overwrite, use_2_stage_agg = two_stage_agg(antialias_stage_2)
if not use_2_stage_agg:
antialias_stage_2_funcs = None
draw_segment = _build_draw_segment(
append, map_onto_pixel, expand_aggs_and_cols, line_width, overwrite
draw_segment, antialias_stage_2_funcs = _line_internal_build_extend(
x_mapper, y_mapper, append, line_width, antialias_stage_2, antialias_stage_2_funcs,
expand_aggs_and_cols,
)
extend_cpu, extend_cuda = _build_extend_line_axis1_none_constant(
draw_segment, expand_aggs_and_cols, antialias_stage_2_funcs,
Expand Down Expand Up @@ -339,15 +340,10 @@ def compute_bounds_dask(self, ddf):
@memoize
def _internal_build_extend(
self, x_mapper, y_mapper, info, append, line_width, antialias_stage_2, antialias_stage_2_funcs):
antialias = line_width > 0
expand_aggs_and_cols = self.expand_aggs_and_cols(append)
map_onto_pixel = _build_map_onto_pixel_for_line(
x_mapper, y_mapper, antialias)
overwrite, use_2_stage_agg = two_stage_agg(antialias_stage_2)
if not use_2_stage_agg:
antialias_stage_2_funcs = None
draw_segment = _build_draw_segment(
append, map_onto_pixel, expand_aggs_and_cols, line_width, overwrite
draw_segment, antialias_stage_2_funcs = _line_internal_build_extend(
x_mapper, y_mapper, append, line_width, antialias_stage_2, antialias_stage_2_funcs,
expand_aggs_and_cols,
)
extend_cpu, extend_cuda = _build_extend_line_axis1_x_constant(
draw_segment, expand_aggs_and_cols, antialias_stage_2_funcs,
Expand Down Expand Up @@ -417,15 +413,10 @@ def compute_bounds_dask(self, ddf):
@memoize
def _internal_build_extend(
self, x_mapper, y_mapper, info, append, line_width, antialias_stage_2, antialias_stage_2_funcs):
antialias = line_width > 0
expand_aggs_and_cols = self.expand_aggs_and_cols(append)
map_onto_pixel = _build_map_onto_pixel_for_line(
x_mapper, y_mapper, antialias)
overwrite, use_2_stage_agg = two_stage_agg(antialias_stage_2)
if not use_2_stage_agg:
antialias_stage_2_funcs = None
draw_segment = _build_draw_segment(
append, map_onto_pixel, expand_aggs_and_cols, line_width, overwrite
draw_segment, antialias_stage_2_funcs = _line_internal_build_extend(
x_mapper, y_mapper, append, line_width, antialias_stage_2, antialias_stage_2_funcs,
expand_aggs_and_cols,
)
extend_cpu, extend_cuda = _build_extend_line_axis1_y_constant(
draw_segment, expand_aggs_and_cols, antialias_stage_2_funcs,
Expand Down Expand Up @@ -497,15 +488,10 @@ def compute_bounds_dask(self, ddf):
@memoize
def _internal_build_extend(
self, x_mapper, y_mapper, info, append, line_width, antialias_stage_2, antialias_stage_2_funcs):
antialias = line_width > 0
expand_aggs_and_cols = self.expand_aggs_and_cols(append)
map_onto_pixel = _build_map_onto_pixel_for_line(
x_mapper, y_mapper, antialias)
overwrite, use_2_stage_agg = two_stage_agg(antialias_stage_2)
if not use_2_stage_agg:
antialias_stage_2_funcs = None
draw_segment = _build_draw_segment(
append, map_onto_pixel, expand_aggs_and_cols, line_width, overwrite
draw_segment, antialias_stage_2_funcs = _line_internal_build_extend(
x_mapper, y_mapper, append, line_width, antialias_stage_2, antialias_stage_2_funcs,
expand_aggs_and_cols,
)
extend_cpu = _build_extend_line_axis1_ragged(
draw_segment, expand_aggs_and_cols, antialias_stage_2_funcs,
Expand Down Expand Up @@ -546,15 +532,10 @@ def _internal_build_extend(
from spatialpandas.geometry import (
PolygonArray, MultiPolygonArray, RingArray
)
antialias = line_width > 0
expand_aggs_and_cols = self.expand_aggs_and_cols(append)
map_onto_pixel = _build_map_onto_pixel_for_line(
x_mapper, y_mapper, antialias)
overwrite, use_2_stage_agg = two_stage_agg(antialias_stage_2)
if not use_2_stage_agg:
antialias_stage_2_funcs = None
draw_segment = _build_draw_segment(
append, map_onto_pixel, expand_aggs_and_cols, line_width, overwrite
draw_segment, antialias_stage_2_funcs = _line_internal_build_extend(
x_mapper, y_mapper, append, line_width, antialias_stage_2, antialias_stage_2_funcs,
expand_aggs_and_cols,
)
perform_extend_cpu = _build_extend_line_axis1_geometry(
draw_segment, expand_aggs_and_cols, antialias_stage_2_funcs,
Expand Down