Skip to content
Closed
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- fix(Controls) avoid sliding with stroke uniform [#9458](https://github.com/fabricjs/fabric.js/pull/9458)
- feat(util): expose `calcPlaneRotation` [#9419](https://github.com/fabricjs/fabric.js/pull/9419)
- refactor(Canvas): BREAKING remove button from mouse events, delegate to event.button property [#9449](https://github.com/fabricjs/fabric.js/pull/9449)
- patch(Canvas): move event mouse:up:before earlier in the logic for more control [#9434](https://github.com/fabricjs/fabric.js/pull/9434)
Expand Down
47 changes: 47 additions & 0 deletions e2e/tests/controls/polygon-controls/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ test('polygon controls can modify polygon - exact false', async ({ page }) => {
});
});

test('polygon controls can modify polygon - transform and strokeUniform', async ({
page,
}) => {
const canvasUtil = new CanvasUtil(page);
const starUtil = new ObjectUtil(page, 'star');

// notes with skewX is broken
await starUtil.executeInBrowser((object) => {
object.strokeUniform = true;
object.scaleX = 1.2;
object.scaleY = 0.9;
object.flipY = true;
object.setDimensions();
object.setCoords();
object.canvas.renderAll();
});

expect(await canvasUtil.screenshot()).toMatchSnapshot({
name: 'initial_with_transform.png',
});

const p2ControlPoint = await starUtil.getObjectControlPoint('p2');

// drag the p2 control
await page.mouse.move(p2ControlPoint.x, p2ControlPoint.y);
await page.mouse.down();
await page.mouse.move(p2ControlPoint.x + 300, p2ControlPoint.y + 100, {
steps: 40,
});
await page.mouse.up();
expect(await canvasUtil.screenshot()).toMatchSnapshot({
name: 'moved_controls_p2_with_transform.png',
});

// drag control p4 in the opposite direction
const p4ControlPoint = await starUtil.getObjectControlPoint('p4');
await page.mouse.move(p4ControlPoint.x, p4ControlPoint.y);
await page.mouse.down();
await page.mouse.move(p4ControlPoint.x - 300, p4ControlPoint.y - 100, {
steps: 40,
});
await page.mouse.up();
expect(await canvasUtil.screenshot()).toMatchSnapshot({
name: 'moved_controls_p4_with_trasnform.png',
});
});

test('polygon controls can modify polygon - exact true', async ({ page }) => {
const canvasUtil = new CanvasUtil(page);
const starUtil = new ObjectUtil(page, 'star');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions src/controls/polyControl.ts

Choose a reason for hiding this comment

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

If a two points horizontal polyline with strokeWidth = 0, it's height will be 0. Does the divide in below got NaN?
const newPositionNormalized = anchorPoint
.subtract(poly.pathOffset)
.divide(poly._getNonTransformedDimensions())
.multiply(adjustFlip);

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export const factoryPolyActionHandler = (
y: number
) {
const poly = transform.target as Polyline,
anchorPoint = new Point(
strokeWidth = poly.strokeWidth;
// do all calculation without strokeWidth
// to avoid scaling issues between dimensions and scaling factors
// when strokeUniform is set as true
poly.strokeWidth = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

getStrokeWidthVector(strokeWidth = this.strokeWidth) {
  const strokeWidthFactor = new fabric.Point(strokeWidth, strokeWidth);
  return this.strokeUniform
    ? strokeWidthFactor.divide(this.getObjectScaling())
    : strokeWidthFactor;
}

const anchorPoint = new Point(
poly.points[(pointIndex > 0 ? pointIndex : poly.points.length) - 1]
),
anchorPointInParentPlane = anchorPoint
Expand All @@ -99,7 +104,7 @@ export const factoryPolyActionHandler = (
newPositionNormalized.x + 0.5,
newPositionNormalized.y + 0.5
);

poly.strokeWidth = strokeWidth;
return actionPerformed;
};
};
Expand Down