File tree Expand file tree Collapse file tree 6 files changed +90
-60
lines changed
bundle/hooks/usePaint/helpers Expand file tree Collapse file tree 6 files changed +90
-60
lines changed Original file line number Diff line number Diff line change @@ -25,10 +25,9 @@ export const extractDependencies = (content: string) => {
2525 }
2626
2727 const localMatches = Array . from (
28- content . matchAll ( / (?: i m p o r t \s + t y p e | i m p o r t | e x p o r t ) \s * \{ ( [ ^ } ] + ) \} \s * f r o m \s * [ ' " ] \. \/ h e l p e r s / g)
28+ content . matchAll ( / (?: i m p o r t | e x p o r t ) \s * \{ ( [ ^ } ] + ) \} \s * f r o m \s * [ ' " ] \. \/ h e l p e r s / g)
2929 ) ;
3030 for ( const match of localMatches ) {
31- console . log ( match ) ;
3231 const imports = match [ 1 ] . split ( ',' ) . map ( ( item ) => item . trim ( ) ) ;
3332 for ( const item of imports ) {
3433 if ( item ) locals . add ( item ) ;
Original file line number Diff line number Diff line change 1- import { Pointer } from './Pointer' ;
1+ export class Pointer {
2+ x ;
3+ y ;
4+ constructor ( x , y ) {
5+ this . x = x ;
6+ this . y = y ;
7+ }
8+ update ( point ) {
9+ this . x = point . x ;
10+ this . y = point . y ;
11+ }
12+ getDifferenceTo ( point ) {
13+ return new Pointer ( this . x - point . x , this . y - point . y ) ;
14+ }
15+ getDistanceTo ( point ) {
16+ const diff = this . getDifferenceTo ( point ) ;
17+ return Math . sqrt ( diff . x ** 2 + diff . y ** 2 ) ;
18+ }
19+ getAngleTo ( point ) {
20+ const diff = this . getDifferenceTo ( point ) ;
21+ return Math . atan2 ( diff . y , diff . x ) ;
22+ }
23+ equalsTo ( point ) {
24+ return this . x === point . x && this . y === point . y ;
25+ }
26+ moveByAngle (
27+ // The angle in radians
28+ angle ,
29+ // How much the point should be moved
30+ distance ) {
31+ // Rotate the angle based on the browser coordinate system ([0,0] in the top left)
32+ const angleRotated = angle + Math . PI / 2 ;
33+ this . x += Math . sin ( angleRotated ) * distance ;
34+ this . y -= Math . cos ( angleRotated ) * distance ;
35+ return this ;
36+ }
37+ }
238export class Paint {
339 pointer ;
440 brush ;
Original file line number Diff line number Diff line change 11export * from './Paint' ;
2- export * from './Pointer' ;
Original file line number Diff line number Diff line change 1- import type { Point } from './Pointer' ;
1+ export interface Point {
2+ x : number ;
3+ y : number ;
4+ }
5+
6+ export class Pointer implements Point {
7+ x : number ;
8+
9+ y : number ;
10+
11+ constructor ( x : number , y : number ) {
12+ this . x = x ;
13+ this . y = y ;
14+ }
15+
16+ update ( point : Point ) {
17+ this . x = point . x ;
18+ this . y = point . y ;
19+ }
20+
21+ getDifferenceTo ( point : Point ) {
22+ return new Pointer ( this . x - point . x , this . y - point . y ) ;
23+ }
224
3- import { Pointer } from './Pointer' ;
25+ getDistanceTo ( point : Point ) {
26+ const diff = this . getDifferenceTo ( point ) ;
27+ return Math . sqrt ( diff . x ** 2 + diff . y ** 2 ) ;
28+ }
29+
30+ getAngleTo ( point : Point ) {
31+ const diff = this . getDifferenceTo ( point ) ;
32+ return Math . atan2 ( diff . y , diff . x ) ;
33+ }
34+
35+ equalsTo ( point : Point ) {
36+ return this . x === point . x && this . y === point . y ;
37+ }
38+
39+ moveByAngle (
40+ // The angle in radians
41+ angle : number ,
42+ // How much the point should be moved
43+ distance : number
44+ ) {
45+ // Rotate the angle based on the browser coordinate system ([0,0] in the top left)
46+ const angleRotated = angle + Math . PI / 2 ;
47+
48+ this . x += Math . sin ( angleRotated ) * distance ;
49+ this . y -= Math . cos ( angleRotated ) * distance ;
50+
51+ return this ;
52+ }
53+ }
454
555export class Paint {
656 pointer : Pointer ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11export * from './Paint' ;
2- export * from './Pointer' ;
You canβt perform that action at this time.
0 commit comments