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

Redo coords #8767

Closed
wants to merge 220 commits into from
Closed
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
220 commits
Select commit Hold shift + click to select a range
7e65dad
fix(): render connection line in context
ShaMan123 Feb 27, 2023
bb2f8e6
Update Control.ts
ShaMan123 Feb 27, 2023
d3863fd
rendering
ShaMan123 Feb 27, 2023
29d08e9
fix
ShaMan123 Feb 27, 2023
10900c8
cleanup
ShaMan123 Feb 27, 2023
68f0008
restore
ShaMan123 Feb 27, 2023
ca00a3c
restore
ShaMan123 Feb 27, 2023
073b50f
Update CHANGELOG.md
ShaMan123 Feb 27, 2023
76691b0
restore
ShaMan123 Feb 27, 2023
ce2ef9e
fix `isContainedWithinObject` under group
ShaMan123 Feb 28, 2023
c9e7772
fix finally
ShaMan123 Feb 28, 2023
fa501da
Update ObjectGeometry.ts
ShaMan123 Feb 28, 2023
b2da410
Update object_geometry.js
ShaMan123 Feb 28, 2023
e1f6edd
cleanup
ShaMan123 Feb 28, 2023
c670ca7
Update SelectableCanvas.ts
ShaMan123 Feb 28, 2023
e862589
lint
ShaMan123 Feb 28, 2023
8e27a40
Update CHANGELOG.md
ShaMan123 Feb 28, 2023
dd7c1b9
refactor coords
ShaMan123 Feb 28, 2023
eea85fe
Revert "refactor coords"
ShaMan123 Mar 1, 2023
4f0fd27
Update util.js
ShaMan123 Mar 1, 2023
30c989d
go
ShaMan123 Mar 1, 2023
7e21549
Update util.js
ShaMan123 Mar 1, 2023
b781913
make the test meaning ful
ShaMan123 Mar 1, 2023
b980b5b
Update InteractiveObject.ts
ShaMan123 Mar 1, 2023
c399332
refctor planeChange
ShaMan123 Mar 1, 2023
560d603
mapValues
ShaMan123 Mar 1, 2023
ec142a3
`sendPointToPlane` test
ShaMan123 Mar 1, 2023
830e68a
fix!
ShaMan123 Mar 1, 2023
0e58b91
done todo
ShaMan123 Mar 1, 2023
043a9af
debugging
ShaMan123 Mar 1, 2023
9fa50e1
Update ObjectGeometry.ts
ShaMan123 Mar 1, 2023
32a5528
major progress
ShaMan123 Mar 1, 2023
08feb27
Update ObjectGeometry.ts
ShaMan123 Mar 1, 2023
63968d5
ppp
ShaMan123 Mar 1, 2023
9338a8d
WOW!
ShaMan123 Mar 1, 2023
434c6fc
WooOOW
ShaMan123 Mar 1, 2023
def498a
CRAZY & not BREAKING!~@@#$#%
ShaMan123 Mar 1, 2023
33233da
Merge branch 'master' into control-connection-rendering
asturur Mar 4, 2023
750c5c4
fix(): flipping!!
ShaMan123 Mar 5, 2023
00a2050
imports
ShaMan123 Mar 5, 2023
6890c20
make non breaking
ShaMan123 Mar 5, 2023
63f4206
Merge branch 'master' into control-connection-rendering
ShaMan123 Mar 5, 2023
c3201c0
exec todo: remove backward compat
ShaMan123 Mar 5, 2023
fd46e5d
Update Control.ts
ShaMan123 Mar 5, 2023
e7aac03
Update polyControl.ts
ShaMan123 Mar 6, 2023
bd96b2d
WORKING!
ShaMan123 Mar 6, 2023
eb20a9b
Update ObjectGeometry.ts
ShaMan123 Mar 6, 2023
6e15280
Update matrix.ts
ShaMan123 Mar 6, 2023
9960f10
fix stroke calc
ShaMan123 Mar 6, 2023
a0da905
shearing
ShaMan123 Mar 7, 2023
4a3f04c
calcBaseChangeMatrix
ShaMan123 Mar 7, 2023
c6788c9
Update planeChange.ts
ShaMan123 Mar 7, 2023
978a5f0
progress
ShaMan123 Mar 7, 2023
ce057b2
progress
ShaMan123 Mar 7, 2023
47f2e85
Update InteractiveObject.ts
ShaMan123 Mar 7, 2023
29b7196
Merge branch 'master' into redo-coords
ShaMan123 Mar 7, 2023
79398c2
,
ShaMan123 Mar 8, 2023
374784d
BBox!
ShaMan123 Mar 8, 2023
d40de93
drawing
ShaMan123 Mar 8, 2023
928fff9
rename
ShaMan123 Mar 8, 2023
dd9d011
Update BBox.ts
ShaMan123 Mar 8, 2023
22636ac
Update InteractiveObject.ts
ShaMan123 Mar 8, 2023
8e2bbad
great
ShaMan123 Mar 8, 2023
74ef4a4
Update Object.ts
ShaMan123 Mar 8, 2023
659e2bf
contains point
ShaMan123 Mar 8, 2023
e149470
fixes
ShaMan123 Mar 8, 2023
6936575
Update ObjectGeometry.ts
ShaMan123 Mar 8, 2023
5e86d38
isOnScreen
ShaMan123 Mar 8, 2023
2a0c9e0
disable tests
ShaMan123 Mar 8, 2023
739fe72
calcViewportBoundaries => getViewportBBox
ShaMan123 Mar 8, 2023
66bf21d
Update CHANGELOG.md
ShaMan123 Mar 8, 2023
69611b8
checkout
ShaMan123 Mar 8, 2023
89b823c
calcCornerCoords
ShaMan123 Mar 8, 2023
14c184a
refactor oCoords
ShaMan123 Mar 8, 2023
4129b4f
Update Control.ts
ShaMan123 Mar 8, 2023
73a72e8
getDimensionsVectorForPositioning
ShaMan123 Mar 10, 2023
aab1d77
patch caching dimensions
ShaMan123 Mar 10, 2023
33b1b5e
cleanup
ShaMan123 Mar 10, 2023
994e283
Update Control.ts
ShaMan123 Mar 10, 2023
792faae
Update planeChange.ts
ShaMan123 Mar 10, 2023
486ec34
fix bbox
ShaMan123 Mar 10, 2023
a5366b1
fabulous!
ShaMan123 Mar 10, 2023
f2e4b9a
remove old bbox logic
ShaMan123 Mar 10, 2023
6ae9ef2
disable tests
ShaMan123 Mar 10, 2023
df00dd6
adapt controls - skew yet to be worked on
ShaMan123 Mar 10, 2023
bea3c22
skew initial
ShaMan123 Mar 10, 2023
3ceb00c
skew fix to legacy
ShaMan123 Mar 10, 2023
da0a18a
cleanup
ShaMan123 Mar 10, 2023
6d10560
Update BBox.ts
ShaMan123 Mar 10, 2023
185d061
origin
ShaMan123 Mar 10, 2023
e193066
Update ObjectGeometry.ts
ShaMan123 Mar 11, 2023
a1be589
fixes
ShaMan123 Mar 11, 2023
bad9093
major adapt dangerous
ShaMan123 Mar 11, 2023
de72da3
canvas bbox + geometry
ShaMan123 Mar 12, 2023
17de633
refactor into folder
ShaMan123 Mar 12, 2023
a41991d
getCoordsMap => getCoords
ShaMan123 Mar 12, 2023
87aba0c
rename
ShaMan123 Mar 12, 2023
5de865f
docs
ShaMan123 Mar 12, 2023
f1b2971
more origin
ShaMan123 Mar 12, 2023
bedbb74
getXY progress
ShaMan123 Mar 13, 2023
51c16a1
Update rotate.ts
ShaMan123 Mar 13, 2023
2bf1702
Update SelectableCanvas.ts
ShaMan123 Mar 13, 2023
815d849
fix
ShaMan123 Mar 13, 2023
9327fc3
ObjectPosition
ShaMan123 Mar 13, 2023
94a6b2c
ObjectTransformations
ShaMan123 Mar 13, 2023
04fafdb
ObjectBBox
ShaMan123 Mar 13, 2023
b581979
Merge branch 'master' into redo-coords
ShaMan123 Mar 13, 2023
a61374f
Merge branch 'master' into redo-coords
ShaMan123 Mar 14, 2023
61faa84
rm CanvasBBox => rect BBox
ShaMan123 Mar 14, 2023
e280737
imports
ShaMan123 Mar 14, 2023
12db471
rotateBy
ShaMan123 Mar 14, 2023
01a93e2
centerTransform props
ShaMan123 Mar 14, 2023
a7daa86
change resolveOriginPoint signature
ShaMan123 Mar 14, 2023
f1416fa
Update PlaneBBox.ts
ShaMan123 Mar 14, 2023
659101d
fix object transforms!!
ShaMan123 Mar 14, 2023
1237515
Update rotate.ts
ShaMan123 Mar 14, 2023
7376986
cleanup + fix `needsViewportCoords`
ShaMan123 Mar 14, 2023
521fcee
Update BBox.ts
ShaMan123 Mar 14, 2023
5193109
transformObjectInPlane
ShaMan123 Mar 14, 2023
7976c70
Update ObjectTransformations.ts
ShaMan123 Mar 14, 2023
5465e65
t
ShaMan123 Mar 14, 2023
ea6b886
shearing success
ShaMan123 Mar 15, 2023
b61d876
m
ShaMan123 Mar 15, 2023
0259b2e
shear x stable ish
ShaMan123 Mar 15, 2023
2ec47c2
shear y stable ish - scaling after?
ShaMan123 Mar 15, 2023
ed83774
shearby: still buggy
ShaMan123 Mar 15, 2023
9e4a279
shearBy progress
ShaMan123 Mar 15, 2023
0d2c172
Update planeChange.ts
ShaMan123 Mar 15, 2023
9a924a9
shearBy!!
ShaMan123 Mar 15, 2023
0490e27
shearing!
ShaMan123 Mar 15, 2023
a7ba741
ObjectTransfomations is stable
ShaMan123 Mar 15, 2023
0abfb94
Update Canvas.ts
ShaMan123 Mar 15, 2023
a38994a
Update ObjectBBox.ts
ShaMan123 Mar 15, 2023
f96cf52
Update StackedObject.ts
ShaMan123 Mar 15, 2023
659fdcf
shearSidesBy
ShaMan123 Mar 15, 2023
53ed0e0
make less or more confusing
ShaMan123 Mar 15, 2023
893161f
fix transformations in vpt
ShaMan123 Mar 16, 2023
17554cb
getTotalAngle => TRadian
ShaMan123 Mar 17, 2023
91c7b51
disable drawing
ShaMan123 Mar 17, 2023
0a4bac7
fix getXY
ShaMan123 Mar 17, 2023
2f48488
cleanup
ShaMan123 Mar 17, 2023
697d999
Update rotate.ts
ShaMan123 Mar 17, 2023
a48b458
cleanup
ShaMan123 Mar 17, 2023
a1df1e6
Merge branch 'master' into redo-coords
ShaMan123 Mar 17, 2023
4668242
skew progress
ShaMan123 Mar 17, 2023
366dbc9
Update skew.ts
ShaMan123 Mar 17, 2023
35dcc11
rotate3D 🤯
ShaMan123 Mar 17, 2023
1efdeca
Update vectors.ts
ShaMan123 Mar 17, 2023
3816fff
Update ObjectTransformations.ts
ShaMan123 Mar 17, 2023
76819c0
types
ShaMan123 Mar 18, 2023
60797cc
fix
ShaMan123 Mar 18, 2023
47a6809
transform origin
ShaMan123 Mar 18, 2023
57b4843
Update util.ts
ShaMan123 Mar 18, 2023
e75989e
remove ObjectPosition
ShaMan123 Mar 18, 2023
edee097
strokeBordersLegacy
ShaMan123 Mar 18, 2023
2d84ab2
rename getDimensionsVector => getBBoxVector
ShaMan123 Mar 18, 2023
904f379
rm(): scale to size methods
ShaMan123 Mar 18, 2023
7804378
Update BBox.ts
ShaMan123 Mar 18, 2023
93534a9
scaling control working!
ShaMan123 Mar 18, 2023
e64387a
cleanup
ShaMan123 Mar 18, 2023
d50a203
Merge branch 'master' into redo-coords
ShaMan123 Mar 18, 2023
e8b4d50
cleanup
ShaMan123 Mar 19, 2023
102428a
disable
ShaMan123 Mar 19, 2023
c30af2b
Update Text.ts
ShaMan123 Mar 19, 2023
410486d
Update EventTypeDefs.ts
ShaMan123 Mar 19, 2023
5a73f99
Merge branch 'master' into control-connection-rendering
ShaMan123 Mar 19, 2023
e7faf79
Merge branch 'control-connection-rendering' into redo-coords
ShaMan123 Mar 19, 2023
3e5188e
fix merge conflicts
ShaMan123 Mar 19, 2023
5465462
fix scale/scaleBy
ShaMan123 Mar 19, 2023
95bb5eb
Update vectors.ts
ShaMan123 Mar 19, 2023
b8775a6
scaling isn't there yet
ShaMan123 Mar 19, 2023
6c36773
stablizing
ShaMan123 Mar 19, 2023
37d76d6
scale is stable
ShaMan123 Mar 19, 2023
c07ab92
Merge branch 'master' into redo-coords
ShaMan123 Mar 19, 2023
b367d21
flipY connection line
ShaMan123 Mar 19, 2023
b1b06fc
skew progress
ShaMan123 Mar 20, 2023
4ae4f14
skewing major progress
ShaMan123 Mar 20, 2023
d378092
more progress
ShaMan123 Mar 20, 2023
8fb484b
cleanup
ShaMan123 Mar 20, 2023
8f6108d
resize controls
ShaMan123 Mar 23, 2023
f42a197
cleanup
ShaMan123 Mar 23, 2023
3b02db0
cleanup
ShaMan123 Mar 23, 2023
a8e6df7
disable
ShaMan123 Mar 23, 2023
688d78a
Update Group.ts
ShaMan123 Mar 23, 2023
cee0b24
Update ObjectBBox.ts
ShaMan123 Mar 23, 2023
207f29d
fix resize from behind
ShaMan123 Mar 23, 2023
4449f8a
Update polyControl.ts
ShaMan123 Mar 23, 2023
b3bbe7a
cleanup
ShaMan123 Mar 23, 2023
34a0471
rm `_normalizePointer`
ShaMan123 Mar 23, 2023
b79bda8
rm `restorePointerVpt`
ShaMan123 Mar 23, 2023
8a965da
oCoords => controlCoords
ShaMan123 Mar 23, 2023
a5e6879
imports
ShaMan123 Mar 23, 2023
fa945b9
fix with skewing
ShaMan123 Mar 23, 2023
5e32e52
Update SelectableCanvas.ts
ShaMan123 Mar 23, 2023
f13ae49
move groupSelector logic to viewport
ShaMan123 Mar 23, 2023
5a0ed64
Update src/brushes/PatternBrush.ts
ShaMan123 Mar 23, 2023
cab736b
stop using `calcTransformMatrix(skipGroup)`
ShaMan123 Mar 25, 2023
89ed92c
cleanup
ShaMan123 Mar 25, 2023
03ce915
fix: transform caching issue
ShaMan123 Mar 25, 2023
7b9fe7e
Update ObjectLayout.ts
ShaMan123 Mar 25, 2023
8d0765c
type group
ShaMan123 Mar 25, 2023
811b6da
Update SelectableCanvas.ts
ShaMan123 Mar 25, 2023
62ffbdf
Update Group.ts
ShaMan123 Mar 25, 2023
857e8e1
perf
ShaMan123 Mar 25, 2023
9f47084
fix(): keep watching selected children
ShaMan123 Mar 25, 2023
5bb9feb
fix: transform caching issue
ShaMan123 Mar 25, 2023
6dded07
disable matrix cache
ShaMan123 Mar 25, 2023
548932a
scale signature
ShaMan123 Mar 25, 2023
14c30f8
rename
ShaMan123 Mar 25, 2023
b2ceee9
Update controls_handlers.js
ShaMan123 Mar 25, 2023
0c95269
fix tests
ShaMan123 Mar 25, 2023
59e3546
fix(): padding
ShaMan123 Mar 25, 2023
bb3983d
cleanup
ShaMan123 Mar 26, 2023
cb74ad2
Squashed commit of the following:
ShaMan123 Mar 26, 2023
e4847c7
remove `fromSVG`
ShaMan123 Apr 29, 2023
a4c0f62
patch(): `Control#shouldActivate`
ShaMan123 May 19, 2023
bd8fca0
Merge branch 'master' into redo-coords
ShaMan123 Sep 19, 2023
ada6bd9
merge artifacts
ShaMan123 Sep 19, 2023
704c307
lint + fix more merge artifacts
ShaMan123 Sep 19, 2023
a759265
more merge fixes
ShaMan123 Sep 19, 2023
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(): redo object geometry [#8767](https://github.com/fabricjs/fabric.js/pull/8767)
- ci(): disallow circular deps [#8759](https://github.com/fabricjs/fabric.js/pull/8759)
- fix(): env WebGL import cycle [#8758](https://github.com/fabricjs/fabric.js/pull/8758)
- chore(TS): remove controls from prototype. BREAKING: controls aren't shared anymore [#8753](https://github.com/fabricjs/fabric.js/pull/8753)
Expand Down
8 changes: 4 additions & 4 deletions src/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ export function createCollectionMixin<TBase extends Constructor>(Base: TBase) {
if (
object.selectable &&
object.visible &&
((includeIntersecting && object.intersectsWithRect(tl, br, true)) ||
object.isContainedWithinRect(tl, br, true) ||
(object.isContainedWithinRect(tl, br, true) ||
(includeIntersecting &&
object.containsPoint(tl, undefined, true)) ||
(includeIntersecting && object.containsPoint(br, undefined, true)))
(object.intersectsWithRect(tl, br, true) ||
object.containsPoint(tl, true) ||
object.containsPoint(br, true))))
Copy link
Member

Choose a reason for hiding this comment

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

this seems a change that is unrelated. is it?

) {
objects.push(object);
}
Expand Down
22 changes: 9 additions & 13 deletions src/canvas/SelectableCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,24 +1001,23 @@ export class SelectableCanvas<

/**
* Checks point is inside the object.
* @param {Object} [pointer] x,y object of point coordinates we want to check.
* @param {FabricObject} obj Object to test against
* @param {Object} [globalPointer] x,y object of point coordinates relative to canvas used to search per pixel target.
* @param {Object} [globalPointer] x,y object of point coordinates relative to canvas top left physical viewport corner
* (used to measure the position of the mouse pointer on canvas) used to search per pixel target.
* @return {Boolean} true if point is contained within an area of given object
* @private
*/
_checkTarget(
pointer: Point,
obj: FabricObject,
globalPointer: Point
): boolean {
_checkTarget(obj: FabricObject, globalPointer: Point): boolean {
if (
obj &&
obj.visible &&
obj.evented &&
// http://www.geog.ubc.ca/courses/klink/gis.notes/ncgia/u32.html
// http://idav.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html
obj.containsPoint(pointer)
obj.containsPoint(
sendPointToPlane(globalPointer, undefined, this.viewportTransform),
true
)
) {
if (
(this.perPixelTargetFind || obj.perPixelTargetFind) &&
Expand Down Expand Up @@ -1052,11 +1051,8 @@ export class SelectableCanvas<
// until we call this function specifically to search inside the activeGroup
while (i--) {
const objToCheck = objects[i];
const pointerToUse = objToCheck.group
? this._normalizePointer(objToCheck.group, pointer)
: pointer;
if (this._checkTarget(pointerToUse, objToCheck, pointer)) {
target = objects[i];
if (this._checkTarget(objToCheck, pointer)) {
target = objToCheck;
ShaMan123 marked this conversation as resolved.
Show resolved Hide resolved
if (isCollection(target) && target.subTargetCheck) {
const subTarget = this._searchPossibleTargets(
target._objects as FabricObject[],
Expand Down
54 changes: 18 additions & 36 deletions src/canvas/StaticCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type { Rect } from '../shapes/Rect';
import {
Constructor,
ImageFormat,
TCornerPoint,
TDataUrlOptions,
TFiller,
TMat2D,
Expand Down Expand Up @@ -210,18 +209,7 @@ export class StaticCanvas<
declare enableRetinaScaling: boolean;

/**
* Describe canvas element extension over design
* properties are tl,tr,bl,br.
* if canvas is not zoomed/panned those points are the four corner of canvas
* if canvas is viewportTransformed you those points indicate the extension
* of canvas element in plain untrasformed coordinates
* The coordinates get updated with @method calcViewportBoundaries.
*/
declare vptCoords: TCornerPoint;

/**
* Based on vptCoords and object.aCoords, skip rendering of objects that
* are not included in current viewport.
* Skip rendering of objects that are not included in current viewport.
* May greatly help in applications with crowded canvas and use of zoom/pan
* If One of the corner of the bounding box of the object is on the canvas
* the objects get rendered.
Expand Down Expand Up @@ -312,7 +300,6 @@ export class StaticCanvas<
height: this.height || this.lowerCanvasEl.height || 0,
});
this.viewportTransform = [...this.viewportTransform];
this.calcViewportBoundaries();
}

protected initElements(el: string | HTMLCanvasElement) {
Expand Down Expand Up @@ -580,7 +567,6 @@ export class StaticCanvas<
if (overlayObject) {
overlayObject.setCoords();
}
this.calcViewportBoundaries();
this.renderOnAddRemove && this.requestRenderAll();
}

Expand Down Expand Up @@ -711,28 +697,25 @@ export class StaticCanvas<
}

/**
* Calculate the position of the 4 corner of canvas with current viewportTransform.
* helps to determinate when an object is in the current rendering viewport using
* object absolute coordinates ( aCoords )
* @return {Object} points.tl
* @chainable
* Describe the visible bounding box of the canvas
* if canvas is **NOT** transformed the points are equal to the four corners of the `HTMLCanvasElement`
* if canvas is transformed the points describe the distance from canvas origin,
* `tl` being the viewport origin which is the `tl` corner of the `HTMLCanvasElement`.
*/
calcViewportBoundaries(): TCornerPoint {
const width = this.width,
height = this.height,
iVpt = invertTransform(this.viewportTransform),
a = transformPoint({ x: 0, y: 0 }, iVpt),
b = transformPoint({ x: width, y: height }, iVpt),
// we don't support vpt flipping
// but the code is robust enough to mostly work with flipping
getViewportBBox() {
// we don't support vpt flipping
// but the code is robust enough to mostly work with flipping
const iVpt = invertTransform(this.viewportTransform),
a = new Point().transform(iVpt),
b = new Point(this.width, this.height).transform(iVpt),
min = a.min(b),
max = a.max(b);
return (this.vptCoords = {
return {
tl: min,
tr: new Point(max.x, min.y),
bl: new Point(min.x, max.y),
br: max,
});
};
}

cancelRequestedRender() {
Expand All @@ -758,7 +741,6 @@ export class StaticCanvas<

const v = this.viewportTransform,
path = this.clipPath;
this.calcViewportBoundaries();
this.clearContext(ctx);
ctx.imageSmoothingEnabled = this.imageSmoothingEnabled;
// @ts-ignore node-canvas stuff
Expand Down Expand Up @@ -824,9 +806,11 @@ export class StaticCanvas<
* @param {Array} objects to render
*/
_renderObjects(ctx: CanvasRenderingContext2D, objects: FabricObject[]) {
for (let i = 0, len = objects.length; i < len; ++i) {
objects[i] && objects[i].render(ctx);
}
objects.forEach((object) => {
object &&
(!this.skipOffscreen || !object.skipOffscreen || object.isOnScreen()) &&
object.render(ctx);
});
}

/**
Expand Down Expand Up @@ -1629,12 +1613,10 @@ export class StaticCanvas<
this.viewportTransform = newVp;
this.width = scaledWidth;
this.height = scaledHeight;
this.calcViewportBoundaries();
this.renderCanvas(canvasEl.getContext('2d')!, objectsToRender);
this.viewportTransform = vp;
this.width = originalWidth;
this.height = originalHeight;
this.calcViewportBoundaries();
this.enableRetinaScaling = originalRetina;
return canvasEl;
}
Expand Down
70 changes: 31 additions & 39 deletions src/controls/Control.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { halfPI } from '../constants';
import {
ControlActionHandler,
TPointerEvent,
Expand All @@ -8,9 +7,8 @@ import {
import { Point } from '../Point';
import type { FabricObject } from '../shapes/Object/Object';
import { TDegree, TMat2D } from '../typedefs';
import { cos } from '../util/misc/cos';
import { mapValues } from '../util/internals';
import { degreesToRadians } from '../util/misc/radiansDegreesConversion';
import { sin } from '../util/misc/sin';
import {
ControlRenderingStyleOverride,
renderCircleControl,
Expand Down Expand Up @@ -276,10 +274,16 @@ export class Control {
fabricObject: FabricObject,
currentControl: Control
) {
return new Point(
this.x * dim.x + this.offsetX,
this.y * dim.y + this.offsetY
).transform(finalMatrix);
// // legacy
// return new Point(
// this.x * dim.x + this.offsetX,
// this.y * dim.y + this.offsetY
// ).transform(finalMatrix);

const bbox = fabricObject.bbox;
return new Point(this.x, this.y)
.transform(bbox.getTransformation())
.add(new Point(this.offsetX, this.offsetY).rotate(bbox.rotation));
}

/**
Expand All @@ -298,38 +302,26 @@ export class Control {
centerY: number,
isTouch: boolean
) {
let cosHalfOffset, sinHalfOffset, cosHalfOffsetComp, sinHalfOffsetComp;
const xSize = isTouch ? this.touchSizeX : this.sizeX,
ySize = isTouch ? this.touchSizeY : this.sizeY;
if (xSize && ySize && xSize !== ySize) {
// handle rectangular corners
const controlTriangleAngle = Math.atan2(ySize, xSize);
const cornerHypotenuse = Math.sqrt(xSize * xSize + ySize * ySize) / 2;
const newTheta = controlTriangleAngle - degreesToRadians(objectAngle);
const newThetaComp =
halfPI - controlTriangleAngle - degreesToRadians(objectAngle);
cosHalfOffset = cornerHypotenuse * cos(newTheta);
sinHalfOffset = cornerHypotenuse * sin(newTheta);
// use complementary angle for two corners
cosHalfOffsetComp = cornerHypotenuse * cos(newThetaComp);
sinHalfOffsetComp = cornerHypotenuse * sin(newThetaComp);
} else {
// handle square corners
// use default object corner size unless size is defined
const cornerSize = xSize && ySize ? xSize : objectCornerSize;
const cornerHypotenuse = cornerSize * Math.SQRT1_2;
// complementary angles are equal since they're both 45 degrees
const newTheta = degreesToRadians(45 - objectAngle);
cosHalfOffset = cosHalfOffsetComp = cornerHypotenuse * cos(newTheta);
sinHalfOffset = sinHalfOffsetComp = cornerHypotenuse * sin(newTheta);
}

return {
tl: new Point(centerX - sinHalfOffsetComp, centerY - cosHalfOffsetComp),
tr: new Point(centerX + cosHalfOffset, centerY - sinHalfOffset),
bl: new Point(centerX - cosHalfOffset, centerY + sinHalfOffset),
br: new Point(centerX + sinHalfOffsetComp, centerY + cosHalfOffsetComp),
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bye bye sad ugly logic

const size = isTouch
? new Point(
this.touchSizeX || objectCornerSize,
this.touchSizeY || objectCornerSize
)
: new Point(
this.sizeX || objectCornerSize,
this.sizeY || objectCornerSize
);
const rotation = degreesToRadians(objectAngle);
const center = new Point(centerX, centerY);
return mapValues(
{
tl: new Point(-0.5, -0.5),
tr: new Point(0.5, -0.5),
bl: new Point(-0.5, 0.5),
br: new Point(0.5, 0.5),
},
(origin) => origin.multiply(size).rotate(rotation).add(center)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controls/polyControl.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will need more work with Poly in a follow up probably that will include stroke projection

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const polyActionHandler = (
pointIndex = transform.pointIndex,
mouseLocalPosition = getLocalPoint(transform, 'center', 'center', x, y),
polygonBaseSize = getSize(poly),
size = poly._getTransformedDimensions(),
size = poly.bbox.sendToParent().getDimensionsVector(),
sizeFactor = polygonBaseSize.divide(size),
adjustFlip = new Point(poly.flipX ? -1 : 1, poly.flipY ? -1 : 1);

Expand Down
5 changes: 3 additions & 2 deletions src/controls/scale.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

scale isn't done yet

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from './util';
import { wrapWithFireEvent } from './wrapWithFireEvent';
import { wrapWithFixedAnchor } from './wrapWithFixedAnchor';
import { BBox } from '../shapes/Object/BBox';

type ScaleTransform = Transform & {
gestureScale?: number;
Expand Down Expand Up @@ -160,8 +161,8 @@ function scaleObject(
) {
return false;
}

dim = target._getTransformedDimensions();
// TODO: use setCoords instead?
dim = BBox.rotated(target).sendToParent().getDimensionsVector();
// missing detection of flip and logic to switch the origin
if (scaleProportionally && !by) {
// uniform scaling
Expand Down
38 changes: 18 additions & 20 deletions src/controls/skew.ts
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so is skew, horrible stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

skew is different than before
I can try to make it as it was

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from './util';
import { wrapWithFireEvent } from './wrapWithFireEvent';
import { wrapWithFixedAnchor } from './wrapWithFixedAnchor';
import { sizeAfterTransform } from '../util/misc/objectTransforms';

export type SkewTransform = Transform & { skewingSide: -1 | 1 };

Expand Down Expand Up @@ -84,10 +85,11 @@ function skewObject(
{ target, ex, ey, skewingSide, ...transform }: SkewTransform,
pointer: Point
) {
const { skew: skewKey } = AXIS_KEYS[axis],
const { skew: skewKey, counterAxis } = AXIS_KEYS[axis],
{ scaleX, scaleY, skewX, skewY, width, height } = target,
offset = pointer
.subtract(new Point(ex, ey))
.divide(new Point(target.scaleX, target.scaleY))[axis],
.divide(new Point(scaleX, scaleY))[axis],
skewingBefore = target[skewKey],
skewingStart = transform[skewKey],
shearingStart = Math.tan(degreesToRadians(skewingStart)),
Expand All @@ -96,18 +98,11 @@ function skewObject(
// then:
// a' = a + b * skewA => skewA = (a' - a) / b
// the value b is tricky since skewY is applied before skewX
b =
axis === 'y'
? target._getTransformedDimensions({
scaleX: 1,
scaleY: 1,
// since skewY is applied before skewX, b (=width) is not affected by skewX
skewX: 0,
}).x
: target._getTransformedDimensions({
scaleX: 1,
scaleY: 1,
}).y;
b = sizeAfterTransform(width, height, {
skewY,
// since skewY is applied before skewX, b (=width) is not affected by skewX
skewX: axis === 'y' ? 0 : skewX,
})[counterAxis];

const shearing =
(2 * offset * skewingSide) /
Expand All @@ -117,19 +112,22 @@ function skewObject(
shearingStart;

const skewing = radiansToDegrees(Math.atan(shearing));

target.set(skewKey, skewing);
const changed = skewingBefore !== target[skewKey];

if (changed && axis === 'y') {
// we don't want skewing to affect scaleX
// so we factor it by the inverse skewing diff to make it seem unchanged to the viewer
const { skewX, scaleX } = target,
dimBefore = target._getTransformedDimensions({ skewY: skewingBefore }),
dimAfter = target._getTransformedDimensions(),
compensationFactor = skewX !== 0 ? dimBefore.x / dimAfter.x : 1;
const dimBefore = sizeAfterTransform(target.width, target.height, {
scaleX,
scaleY,
skewX,
skewY,
}),
dimAfter = sizeAfterTransform(target.width, target.height, target),
compensationFactor = target.skewX !== 0 ? dimBefore.x / dimAfter.x : 1;
compensationFactor !== 1 &&
target.set('scaleX', compensationFactor * scaleX);
target.set('scaleX', compensationFactor * target.scaleX);
}

return changed;
Expand Down
Loading