Skip to content

Commit

Permalink
Simplify line _internal_build_extend (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 authored Oct 19, 2023
1 parent cb0ca17 commit 606f7bf
Showing 1 changed file with 37 additions and 56 deletions.
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

0 comments on commit 606f7bf

Please sign in to comment.