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

fix(editor): brush xywh do not behave predictably when changing lineWidth of the rotated brush element #9058

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/CLA.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ Example:
- satoren, @satoren, 2024/08/09
- Nikita Minaev, @majula2111, 2024/09/26
- Oleg, @OlegDev1, 2024/12/03
- Egor Titov, @EGRoBBeRTiT, 2025/01/22
10 changes: 4 additions & 6 deletions packages/affine/model/src/elements/brush/brush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,19 @@ export class BrushElementModel extends GfxPrimitiveElementModel<BrushProps> {
instance['_local'].delete('commands');
})
@derive((lineWidth: number, instance: Instance) => {
const oldBound = instance.elementBound;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch! This change effectively addresses the issue mentioned, but it could be even better by fixing it with just one line of code.

    const oldBound = Bound.fromXYWH(instance.deserializedXYWH);


if (
lineWidth === instance.lineWidth ||
oldBound.w === 0 ||
oldBound.h === 0
instance.w === 0 ||
instance.h === 0
)
return {};

const points = instance.points;
const transformed = transformPointsToNewBound(
points.map(([x, y]) => ({ x, y })),
oldBound,
instance,
instance.lineWidth / 2,
inflateBound(oldBound, lineWidth - instance.lineWidth),
inflateBound(instance, lineWidth - instance.lineWidth),
lineWidth / 2
);

Expand Down