Skip to content

[MNT]: Refactor autoscaling in 3D #28444

Open

Description

@timhoffm

Summary

From #28403 (review):

Current logic

Extract all data coordinates xyz from the artist and feed them into auto_scale_xyz().

This updates the xy_dataLim, zz_dataLim BBoxes via .Bbox.update_from_data_xy/x/y(), which in turn creates a Path and calls .Bbox.update_from_path().

This is quite a lot data pushing (and maybe copying) just to update dataLim bboxes.

Proposed logic

Separation of concerns: The Artists should have a function to get their data lims. These limits should be used to update the Bbox. Basically some Bbox.update_from_box, a kind of an in-place Bbox.union, which we don't seem to have.

Essentially, we have should implement a 3D variant of Collection.get_datalim` for 3D.

Proposed fix

Rough outline: We may start minimal with rolling a small

class _Bbox3d:
    def __init__(self, points):
        ((self.xmin, self.xmax),
         (self.ymin, self.ymax),
         (self.zmin, self.zmax)) = points

    def to_bbox_xy(self):
        return Bbox(((self.xmin, self.xmax), (self.ymin, self.ymax)))

    def to_bbox_zz(self):
        # first component contains z, second is unused
        return Bbox(((self.zmin, self.zmax), (0, 0)))

and implement _get_datalim3d() -> _Bbox3d on the 3d collections.

Then

def add_collection(col, autolim=True):
    ...
    if autolim:
        self.auto_scale_lim(col.get_datalim3d())

and

def auto_scale_lim(bbox3d):
     ...
     self.dataLim_xy.update_from_box(bbox3d.to_bbox_xy())
     self.dataLim_zz.update_from_box(bbox3d.to_bbox_zz())

Activity

  1. Thierno88 commented on Oct 20, 2024

    @Thierno88

    Can I suggest a solution on this issue?

  2. rcomer commented on Oct 20, 2024

    @rcomer
    Member

    Hi @Thierno88, anyone is welcome to work on anything, so if you think you see a way forward, please go for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions