@@ -593,11 +593,12 @@ export class Path implements IPath {
593593 return CGPathIsRect ( this . getCGPath ( ) , new interop . Reference ( rect . cgRect ) ) ;
594594 }
595595 getCurrentPoint ( ) {
596- const path = this . getCGPath ( ) ;
596+ let path = this . getCGPath ( ) ;
597597 if ( CGPathIsEmpty ( path ) ) {
598598 this . moveTo ( 0 , 0 ) ;
599+ path = this . mPath ;
599600 }
600- return CGPathGetCurrentPoint ( this . getCGPath ( ) ) ;
601+ return CGPathGetCurrentPoint ( path ) ;
601602 }
602603 rMoveTo ( dx : number , dy : number ) : void {
603604 const currentPoint = this . getCurrentPoint ( ) ;
@@ -709,44 +710,62 @@ export class Path implements IPath {
709710 const path = params [ 0 ] as Path ;
710711 if ( length === 1 ) {
711712 if ( this . mBPath ) {
712- this . mBPath . appendPath ( path . getBPath ( ) ) ;
713+ this . mBPath . appendPath ( path . getOrCreateBPath ( ) ) ;
713714 } else {
714- CGPathAddPath ( this . mPath , null , path . mPath ) ;
715+ CGPathAddPath ( this . getCGPath ( ) , null , path . getCGPath ( ) ) ;
715716 }
716717 // param0: IPath, param1: number, param2: number
717718 } else if ( length === 2 ) {
718719 const mat = params [ 1 ] as Matrix ;
719720 if ( this . mBPath ) {
720- this . mBPath . appendPath ( path . getBPath ( ) ) ;
721+ this . mBPath . appendPath ( path . getOrCreateBPath ( ) ) ;
721722 } else {
722- CGPathAddPath ( this . mPath , new interop . Reference ( mat . mTransform ) , path . mPath ) ;
723+ CGPathAddPath ( this . getCGPath ( ) , new interop . Reference ( mat . mTransform ) , path . getCGPath ( ) ) ;
723724 }
724725 // param0: IPath, param1: number, param2: number
725726 } else if ( length === 3 ) {
726727 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 ) ;
727731 } else {
728732 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 ( ) ) ;
730734 }
731735 // param0: IPath, param1: Matrix
732736 }
733737 }
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 ) ;
736743 }
737744 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+ }
739750 }
740751 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+ }
742757 }
743758 //@ts -ignore
744759 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 ) ;
748762 } 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+ }
750769 }
751770 }
752771 reset ( ) : void {
@@ -776,20 +795,33 @@ export class Path implements IPath {
776795 const cy = rect . origin . y + h * 0.5 ;
777796 const r = rect . size . width * 0.5 ;
778797 // 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+ }
782805 // CGPathMoveToPoint(this._path, null, center.x, center.y);
783806 }
784807 close ( ) : void {
808+ if ( this . mBPath ) {
809+ this . mBPath . closePath ( ) ;
810+ } else {
811+ CGPathCloseSubpath ( this . mPath ) ;
812+ }
785813 // CGPathCloseSubpath(this._path);
786814 }
787815 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 ) ;
790818 } 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+ }
793825 }
794826 }
795827 rewind ( ) : void {
@@ -815,7 +847,11 @@ export class Path implements IPath {
815847 }
816848 }
817849 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+ }
819855 }
820856 setFillType ( value : FillType ) : void {
821857 this . mFillType = value ;
@@ -825,7 +861,11 @@ export class Path implements IPath {
825861 return false ;
826862 }
827863 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+ }
829869 }
830870 incReserve ( param0 : number ) : void {
831871 console . error ( 'Method not implemented:' , 'incReserve' ) ;
@@ -841,7 +881,11 @@ export class Path implements IPath {
841881 } else if ( length === 2 ) {
842882 rect = ( params [ 0 ] as Rect ) . cgRect ;
843883 }
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+ }
845889 }
846890 addOval ( ...params ) : void {
847891 const length = params . length ;
@@ -851,13 +895,18 @@ export class Path implements IPath {
851895 } else if ( length === 2 ) {
852896 rect = ( params [ 0 ] as Rect ) . cgRect ;
853897 }
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+ }
855903 }
856904 isInverseFillType ( ) : boolean {
857905 return this . mFillType === FillType . INVERSE_EVEN_ODD || this . mFillType === FillType . INVERSE_WINDING ;
858906 }
859907 //@ts -ignore
860908 set ( path : Path ) : void {
909+ this . mBPath = null ;
861910 this . mPath = CGPathCreateMutableCopy ( path . mPath ) ;
862911 }
863912}
0 commit comments