Skip to content

[MNT]: Hatch density being int or float? #26645

Open
@oscargus

Description

@oscargus

Summary

The typing makes it clear that both are used.

density of Path.hatch is typed as float. This is then passed to hatch.get_path, where it is typed as int and then does:

density = int(density)
patterns = [hatch_type(hatchpattern, density)
for hatch_type in _hatch_types]

hatch_type is one of the hatch methods and typically has a line like:

self.num_lines = int((hatch.count('-') + hatch.count('+')) * density)

As seen it is possible to pass a float until here.

Proposed fix

I see two solutions:

  1. Type density of Path.hatch as int. This makes it consistent and there are no consequences.
  2. Type density elsewhere as float and remove the int(density) in get_path. This will work properly from a typing pespective, but change the appearance. For example, using Path.hatch("/xX/xX", 1.9) will change num_lines of NorthEastHatch from 6*int(1.9) = 6 to int(6*1.9) = 11. However, it will also allow a more detailed control of the density in a more natural way.

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