@@ -593,11 +593,12 @@ export class Path implements IPath {
593
593
return CGPathIsRect ( this . getCGPath ( ) , new interop . Reference ( rect . cgRect ) ) ;
594
594
}
595
595
getCurrentPoint ( ) {
596
- const path = this . getCGPath ( ) ;
596
+ let path = this . getCGPath ( ) ;
597
597
if ( CGPathIsEmpty ( path ) ) {
598
598
this . moveTo ( 0 , 0 ) ;
599
+ path = this . mPath ;
599
600
}
600
- return CGPathGetCurrentPoint ( this . getCGPath ( ) ) ;
601
+ return CGPathGetCurrentPoint ( path ) ;
601
602
}
602
603
rMoveTo ( dx : number , dy : number ) : void {
603
604
const currentPoint = this . getCurrentPoint ( ) ;
@@ -709,44 +710,62 @@ export class Path implements IPath {
709
710
const path = params [ 0 ] as Path ;
710
711
if ( length === 1 ) {
711
712
if ( this . mBPath ) {
712
- this . mBPath . appendPath ( path . getBPath ( ) ) ;
713
+ this . mBPath . appendPath ( path . getOrCreateBPath ( ) ) ;
713
714
} else {
714
- CGPathAddPath ( this . mPath , null , path . mPath ) ;
715
+ CGPathAddPath ( this . getCGPath ( ) , null , path . getCGPath ( ) ) ;
715
716
}
716
717
// param0: IPath, param1: number, param2: number
717
718
} else if ( length === 2 ) {
718
719
const mat = params [ 1 ] as Matrix ;
719
720
if ( this . mBPath ) {
720
- this . mBPath . appendPath ( path . getBPath ( ) ) ;
721
+ this . mBPath . appendPath ( path . getOrCreateBPath ( ) ) ;
721
722
} else {
722
- CGPathAddPath ( this . mPath , new interop . Reference ( mat . mTransform ) , path . mPath ) ;
723
+ CGPathAddPath ( this . getCGPath ( ) , new interop . Reference ( mat . mTransform ) , path . getCGPath ( ) ) ;
723
724
}
724
725
// param0: IPath, param1: number, param2: number
725
726
} else if ( length === 3 ) {
726
727
if ( this . mBPath ) {
728
+ const t = CGAffineTransformMakeTranslation ( params [ 1 ] , params [ 2 ] ) ;
729
+ const newPath = CGPathCreateCopyByTransformingPath ( path . getCGPath ( ) , new interop . Reference ( t ) ) ;
730
+ this . mBPath . appendPath ( newPath ) ;
727
731
} else {
728
732
const t = CGAffineTransformMakeTranslation ( params [ 1 ] , params [ 2 ] ) ;
729
- CGPathAddPath ( this . mPath , new interop . Reference ( t ) , path . mPath ) ;
733
+ CGPathAddPath ( this . getCGPath ( ) , new interop . Reference ( t ) , path . getCGPath ( ) ) ;
730
734
}
731
735
// param0: IPath, param1: Matrix
732
736
}
733
737
}
734
- rLineTo ( param0 : number , param1 : number ) : void {
735
- console . error ( 'Method not implemented:' , 'rLineTo' ) ;
738
+ rLineTo ( x : number , y : number ) : void {
739
+ const currentPoint = this . getCurrentPoint ( ) ;
740
+ const dx = currentPoint . x ;
741
+ const dy = currentPoint . y ;
742
+ this . lineTo ( x + dx , y + dy ) ;
736
743
}
737
744
lineTo ( x : number , y : number ) : void {
738
- CGPathAddLineToPoint ( this . mPath , null , x , y ) ;
745
+ if ( this . mBPath ) {
746
+ this . mBPath . addLineToPoint ( CGPointMake ( x , y ) ) ;
747
+ } else {
748
+ CGPathAddLineToPoint ( this . mPath , null , x , y ) ;
749
+ }
739
750
}
740
751
quadTo ( cpx : number , cpy : number , x : number , y : number ) : void {
741
- CGPathAddQuadCurveToPoint ( this . mPath , null , cpx , cpy , x , y ) ;
752
+ if ( this . mBPath ) {
753
+ this . mBPath . addQuadCurveToPointControlPoint ( CGPointMake ( x , y ) , CGPointMake ( cpx , cpy ) ) ;
754
+ } else {
755
+ CGPathAddQuadCurveToPoint ( this . mPath , null , cpx , cpy , x , y ) ;
756
+ }
742
757
}
743
758
//@ts -ignore
744
759
transform ( mat : Matrix , output ?: Path ) {
745
- const path = CGPathCreateCopyByTransformingPath ( this . mPath , new interop . Reference ( mat . mTransform ) ) ;
746
- if ( output ) {
747
- output . mPath = path ;
760
+ if ( this . mBPath && ! output ) {
761
+ this . mBPath . applyTransform ( mat . mTransform ) ;
748
762
} else {
749
- this . mPath = path ;
763
+ const path = CGPathCreateCopyByTransformingPath ( this . getCGPath ( ) , new interop . Reference ( mat . mTransform ) ) ;
764
+ if ( output ) {
765
+ output . mPath = path ;
766
+ } else {
767
+ this . mPath = path ;
768
+ }
750
769
}
751
770
}
752
771
reset ( ) : void {
@@ -776,20 +795,33 @@ export class Path implements IPath {
776
795
const cy = rect . origin . y + h * 0.5 ;
777
796
const r = rect . size . width * 0.5 ;
778
797
// const center = CGPointMake(rect.centerX(), rect.centerY());
779
- let t = CGAffineTransformMakeTranslation ( cx , cy ) ;
780
- t = CGAffineTransformConcat ( CGAffineTransformMakeScale ( 1.0 , h / w ) , t ) ;
781
- CGPathAddArc ( this . mPath , new interop . Reference ( t ) , 0 , 0 , r , ( startAngle * Math . PI ) / 180 , ( ( startAngle + sweepAngle ) * Math . PI ) / 180 , false ) ;
798
+ if ( this . mBPath ) {
799
+ this . mBPath . addArcWithCenterRadiusStartAngleEndAngleClockwise ( CGPointMake ( cx , cy ) , r , ( startAngle * Math . PI ) / 180 , ( ( startAngle + sweepAngle ) * Math . PI ) / 180 , false ) ;
800
+ } else {
801
+ let t = CGAffineTransformMakeTranslation ( cx , cy ) ;
802
+ t = CGAffineTransformConcat ( CGAffineTransformMakeScale ( 1.0 , h / w ) , t ) ;
803
+ CGPathAddArc ( this . mPath , new interop . Reference ( t ) , 0 , 0 , r , ( startAngle * Math . PI ) / 180 , ( ( startAngle + sweepAngle ) * Math . PI ) / 180 , false ) ;
804
+ }
782
805
// CGPathMoveToPoint(this._path, null, center.x, center.y);
783
806
}
784
807
close ( ) : void {
808
+ if ( this . mBPath ) {
809
+ this . mBPath . closePath ( ) ;
810
+ } else {
811
+ CGPathCloseSubpath ( this . mPath ) ;
812
+ }
785
813
// CGPathCloseSubpath(this._path);
786
814
}
787
815
addCircle ( x : number , y : number , r : number , d : Direction ) : void {
788
- if ( d === Direction . CW ) {
789
- CGPathAddEllipseInRect ( this . mPath , null , CGRectMake ( x - r , y - r , 2 * r , 2 * r ) ) ;
816
+ if ( this . mBPath ) {
817
+ this . mBPath . addArcWithCenterRadiusStartAngleEndAngleClockwise ( CGPointMake ( x , y ) , r , 0 , 2 * Math . PI , false ) ;
790
818
} else {
791
- const t = CGAffineTransformMakeScale ( - 1 , 1 ) ;
792
- CGPathAddEllipseInRect ( this . mPath , new interop . Reference ( t ) , CGRectMake ( x - r , y - r , 2 * r , 2 * r ) ) ;
819
+ if ( d === Direction . CW ) {
820
+ CGPathAddEllipseInRect ( this . mPath , null , CGRectMake ( x - r , y - r , 2 * r , 2 * r ) ) ;
821
+ } else {
822
+ const t = CGAffineTransformMakeScale ( - 1 , 1 ) ;
823
+ CGPathAddEllipseInRect ( this . mPath , new interop . Reference ( t ) , CGRectMake ( x - r , y - r , 2 * r , 2 * r ) ) ;
824
+ }
793
825
}
794
826
}
795
827
rewind ( ) : void {
@@ -815,7 +847,11 @@ export class Path implements IPath {
815
847
}
816
848
}
817
849
moveTo ( x : number , y : number ) : void {
818
- CGPathMoveToPoint ( this . mPath , null , x , y ) ;
850
+ if ( this . mBPath ) {
851
+ this . mBPath . moveToPoint ( CGPointMake ( x , y ) ) ;
852
+ } else {
853
+ CGPathMoveToPoint ( this . mPath , null , x , y ) ;
854
+ }
819
855
}
820
856
setFillType ( value : FillType ) : void {
821
857
this . mFillType = value ;
@@ -825,7 +861,11 @@ export class Path implements IPath {
825
861
return false ;
826
862
}
827
863
cubicTo ( cp1x : number , cp1y : number , cp2x : number , cp2y : number , x : number , y : number ) : void {
828
- CGPathAddCurveToPoint ( this . mPath , null , cp1x , cp1y , cp2x , cp2y , x , y ) ;
864
+ if ( this . mBPath ) {
865
+ this . mBPath . addCurveToPointControlPoint1ControlPoint2 ( CGPointMake ( x , y ) , CGPointMake ( cp1x , cp1y ) , CGPointMake ( cp2x , cp2y ) ) ;
866
+ } else {
867
+ CGPathAddCurveToPoint ( this . mPath , null , cp1x , cp1y , cp2x , cp2y , x , y ) ;
868
+ }
829
869
}
830
870
incReserve ( param0 : number ) : void {
831
871
console . error ( 'Method not implemented:' , 'incReserve' ) ;
@@ -841,7 +881,11 @@ export class Path implements IPath {
841
881
} else if ( length === 2 ) {
842
882
rect = ( params [ 0 ] as Rect ) . cgRect ;
843
883
}
844
- CGPathAddRect ( this . mPath , null , rect ) ;
884
+ if ( this . mBPath ) {
885
+ this . mBPath . appendPath ( UIBezierPath . bezierPathWithRect ( rect ) ) ;
886
+ } else {
887
+ CGPathAddRect ( this . mPath , null , rect ) ;
888
+ }
845
889
}
846
890
addOval ( ...params ) : void {
847
891
const length = params . length ;
@@ -851,13 +895,18 @@ export class Path implements IPath {
851
895
} else if ( length === 2 ) {
852
896
rect = ( params [ 0 ] as Rect ) . cgRect ;
853
897
}
854
- CGPathAddEllipseInRect ( this . mPath , null , rect ) ;
898
+ if ( this . mBPath ) {
899
+ this . mBPath . appendPath ( UIBezierPath . bezierPathWithOvalInRect ( rect ) ) ;
900
+ } else {
901
+ CGPathAddEllipseInRect ( this . mPath , null , rect ) ;
902
+ }
855
903
}
856
904
isInverseFillType ( ) : boolean {
857
905
return this . mFillType === FillType . INVERSE_EVEN_ODD || this . mFillType === FillType . INVERSE_WINDING ;
858
906
}
859
907
//@ts -ignore
860
908
set ( path : Path ) : void {
909
+ this . mBPath = null ;
861
910
this . mPath = CGPathCreateMutableCopy ( path . mPath ) ;
862
911
}
863
912
}
0 commit comments