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

Form/Editable label failing with glScissor #57

Closed
wants to merge 1 commit into from

Conversation

Rahuum
Copy link

@Rahuum Rahuum commented Jan 6, 2022

Fixes #55

@kalekundert
Copy link
Contributor

Thanks for figuring this out. I think you need to keep the aligned_rect.round() call, though, because it actually rounds to the nearest integer, while int() just truncates the fractional component of the number. In other words:

>>> int(1.9)
1
>>> round(1.9)
2

Alternatively, it might be better to fix the vecrec.Rect.round() method to just return ints in the first place. This relates to an obscure behavior of the round() function that I didn't know about until just now:

>>> help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.
    
    The return value is an integer if ndigits is omitted or None.  Otherwise
    the return value has the same type as the number.  ndigits may be negative.

So the reason Rect.round() is returning floats is that we're explicitly passing 0 as the number of digits. If we rewrite Rect.round() as show below, it will behave exactly like round() and return ints when no digits are specified:

def round(self, *args, **kwargs):
        """ Round the dimensions of the given rectangle to the given number of digits. """
        self._left = round(self._left, *args, **kwargs)
        self._bottom = round(self._bottom, *args, **kwargs)
        self._width = round(self._width, *args, **kwargs)
        self._height = round(self._height, *args, **kwargs)

I think that would be a more robust solution.

@kalekundert
Copy link
Contributor

In fact, I'll just make that change to Rect.round(). It'll just take me a few minutes...

@kalekundert
Copy link
Contributor

Ok, I made the aforementioned changes to Rect.round(). I think that also fixes #55 without the need for these changes. Let me know if that isn't the case.

@Rahuum
Copy link
Author

Rahuum commented Jan 7, 2022

So that did fix it, though it does have the long-term issue of making it less self-documenting.

It may be worth it to investigate something like

def round(self, digits=None):
        """ Round the dimensions of the given rectangle to the given number of digits. """
        self._left = round(self._left, digits)
        self._bottom = round(self._bottom, digits)
        self._width = round(self._width, digits)
        self._height = round(self._height, digits)

or something.
But I'll close this out since my own issue is actually closed, that's more a doco suggestion than anything.

@Rahuum Rahuum closed this Jan 7, 2022
@kalekundert
Copy link
Contributor

Yeah, that occurred to me right after I finished making the change. I might go back and fix it when I get some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error while running the code from text input tutorial
2 participants