Skip to content

errors when adding polygons with 4 points  #1651

Closed

Description

@joamatab

When adding polygons with 4 points we get an error

poly1 = kdb.Polygon(
    [
        [-8, -6],
        [6, 8],
        [7, 17],
        [9, 5],
    ]
)
TypeError: Ambiguous overload variants - multiple method declarations match arguments in Polygon.__init__

@amccaugh
@sebastian-goeldi

Activity

  1. sebastian-goeldi commented on Mar 10, 2024

    @sebastian-goeldi
    Contributor

    This works, but it seems the .pyi didn't pick up the new function overload.

    >>> import klayout.db as kdb
    >>> kdb.Polygon([[0,0],[10,0],[10.5,10]])
    (0,0;10,10;10,0)
    >>> kdb.DPolygon([[0,0],[10,0],[10.,10]])
    (0,0;10,10;10,0)
  2. sebastian-goeldi commented on Mar 10, 2024

    @sebastian-goeldi
    Contributor

    The issue seems to be if the list has exactly 4 points, then the creation fails

    >>> poly1=kf.kdb.DPolygon([(0,0),[-10,0],[10.,10],[10,0]])
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: Ambiguous overload variants - multiple method declarations match arguments in DPolygon.__init__

    @klayoutmatthias could it be that klayout tries to cast to a Box first here?

  3. changed the title [-]create Polygons from lists[/-] [+]errors when adding polygons with 4 points [/+] on Mar 10, 2024
  4. klayoutmatthias commented on Mar 10, 2024

    @klayoutmatthias
    Collaborator

    Grml ... I knew too much smartness would finally create some trouble ... :(

    Basically, the whole scheme why this is works is the inference logic KLayout uses: if an argument expects an object, but is passed an array, KLayout tries to call the object constructor from the arguments of the array. This also works for array elements.

    This is way (0,0) can create a DPoint in the DPolygon([DPoint, DPoint, ... ]) constructor. In the same fashion a four-element array can be matched to the arguments of DBox in the DPolygon(DBox) constructor. This is what happens here and creates that ambiguity.

    I can fix this by giving precedence of array matching array (I think).

    The best workaround is to use "assign_hull" which does not have a Box overload:

    poly = kf.kdb.DPolygon()
    poly.assign_hull([(0,0),[-10,0],[10.,10],[10,0]])
    

    Matthias

  5. joamatab commented on Mar 10, 2024

    @joamatab
    ContributorAuthor

    awesome! that worked, thank you Matthias!

    feel free to close this

  6. klayoutmatthias commented on Mar 10, 2024

    @klayoutmatthias
    Collaborator

    Very good, thanks for the feedback.

    I'll keep that ticket open to remind me of this stupid ambiguity. I shall be less permissive on the inference paths.

    Matthias

  7. added this to the 0.29 milestone on Mar 21, 2024
  8. added a commit that references this issue on Mar 23, 2024
  9. added a commit that references this issue on Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions