| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -24,7 +24,7 @@ | |
| except ImportError: | ||
| import dummy_threading as threading | ||
| from contextlib import nullcontext | ||
| from math import radians, cos, sin | ||
| from math import radians, cos, sin, sqrt | ||
|
|
||
| import numpy as np | ||
| from PIL import Image | ||
| Expand Down Expand Up | @@ -208,10 +208,13 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): | |
| xo, yo = font.get_bitmap_offset() | ||
| xo /= 64.0 | ||
| yo /= 64.0 | ||
| h = sqrt(xo**2 + yo**2) | ||
| xd = d * sin(radians(angle)) | ||
| yd = d * cos(radians(angle)) | ||
| xo = h * cos(radians(angle)) | ||
| yo = h * sin(radians(angle)) | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIf we are going to calculate radians(angle) four times, might as well just do it once and store it in a variable.
Sorry, something went wrong.
safdarzareef reacted with thumbs up emoji
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAlso, these four lines here would greatly benefit from a comment explaining the trigonometry. Usually, cos() goes with x, and y goes with sin(). Seeing it two different ways here for the offset and the descent is confusing.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI can explain the offset trigonometry, but I just left the code for the descent as it was before. The descent seems wrong - but I am unaware of the reason why it was like that before so I left it there. Basic trigonometry suggests that x components should be calculated by multiplying a number by the cosine of its angle and y components should be calculated by multiplying a number by the sine of its angle - so that is why I used that for the offset but I do think the descent should be in the same form too.
Sorry, something went wrong.
All reactions
|
||
| x = round(x + xo + xd) | ||
| y = round(y + yo + yd) | ||
| y = round(y + yo - yd) | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitymuch like the trig above, I think this will also need a quick proof in the comments.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI don't think I have a proof for this at the moment except that in the draw_mathtext function the y is calculated in a similar manner and by subtracting the y offset we get a satisfactory result.
Sorry, something went wrong.
All reactions
|
||
| self._renderer.draw_text_image(font, x, y + 1, angle, gc) | ||
|
|
||
| def get_text_width_height_descent(self, s, prop, ismath): | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityPersonally, I prefer using hypot() instead, but I don't know if it really matters in the context of bounding box calculations.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI don't know if it will matter, but we could still change it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.