Skip to content

Fix anchored position rounding #83

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

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,16 @@ def anchored_position(self):
if self._anchor_point is None:
return None
return (
int(self.x + (self._anchor_point[0] * self._boundingbox[2] * self._scale)),
int(
self.y
+ (self._anchor_point[1] * self._boundingbox[3] * self._scale)
- round((self._boundingbox[3] * self._scale) / 2.0)
self.x
+ round(self._anchor_point[0] * self._boundingbox[2] * self._scale)
),
int(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are my proposed changes for the anchored_position y-getter

            int(round(
                self.y
                + (self._anchor_point[1] * self._boundingbox[3] * self._scale)
                - ((self._boundingbox[3] * self._scale) / 2.0)
            )),

round(
self.y
+ (self._anchor_point[1] * self._boundingbox[3] * self._scale)
- ((self._boundingbox[3] * self._scale) / 2.0)
)
),
)

Expand All @@ -399,12 +404,14 @@ def anchored_position(self, new_position):
return # Note: anchor_point must be set before setting anchored_position
new_x = int(
new_position[0]
- self._anchor_point[0] * (self._boundingbox[2] * self._scale)
- round(self._anchor_point[0] * (self._boundingbox[2] * self._scale))
)
new_y = int(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is my proposed update for the anchored_position setter for variable new_y:

        new_y = int(round(
            new_position[1]
            - (self._anchor_point[1] * self._boundingbox[3] * self._scale)
            + ((self._boundingbox[3] * self._scale) / 2.0)
        ))

new_position[1]
- (self._anchor_point[1] * self._boundingbox[3] * self._scale)
+ round((self._boundingbox[3] * self._scale) / 2.0)
round(
new_position[1]
- (self._anchor_point[1] * self._boundingbox[3] * self._scale)
+ ((self._boundingbox[3] * self._scale) / 2.0)
)
)
self.x = new_x
self.y = new_y