@@ -889,13 +889,30 @@ export class Context {
889
889
*/
890
890
stroke ( ) {
891
891
let flat_path = flatten_path ( this . path )
892
- let stroke_path = path_to_stroked_path ( flat_path , this . lineWidth )
892
+ let stroke_path = path_to_stroked_path ( flat_path , this . lineWidth / 2 )
893
893
const lines = pathToLines ( stroke_path )
894
+ const old_fillStyle = this . fillStyle
895
+ this . fillStyle = this . strokeStyle
894
896
this . imageSmoothingEnabled ? this . fill_aa ( lines ) : this . fill_noaa ( lines ) ;
895
- // this.strokeStyle = 'red'
896
- // this.lineWidth = 1
897
- // pathToLines(this.path).forEach((line)=> this.drawLine(line));
898
- // pathToLines(stroke_path).forEach(line => this.drawLine(line))
897
+ this . fillStyle = old_fillStyle
898
+
899
+ if ( this . debug ) {
900
+ this . save ( )
901
+ let old_ss = this . strokeStyle
902
+ let old_lw = this . lineWidth
903
+ this . strokeStyle = 'red'
904
+ this . lineWidth = 1
905
+ console . log ( "path is" , this . path )
906
+ pathToLines ( this . path ) . forEach ( ( line ) => this . drawLine ( line ) ) ;
907
+ console . log ( "flat path is" , flat_path )
908
+ pathToLines ( flat_path ) . forEach ( ( line ) => this . drawLine ( line ) ) ;
909
+ console . log ( "stroke path is" , stroke_path )
910
+ pathToLines ( stroke_path ) . forEach ( line => this . drawLine ( line ) )
911
+ console . log ( "final lines are" , lines )
912
+ this . strokeStyle = old_ss
913
+ this . lineWidth = old_lw
914
+ this . restore ( )
915
+ }
899
916
}
900
917
901
918
/**
@@ -913,6 +930,7 @@ export class Context {
913
930
* @memberof Context
914
931
*/
915
932
drawLine ( line ) {
933
+ if ( line . is_invalid ( ) ) return console . error ( 'cannot draw line' , line )
916
934
this . imageSmoothingEnabled ?this . drawLine_aa ( line ) :this . drawLine_noaa ( line )
917
935
}
918
936
@@ -1322,7 +1340,7 @@ function path_to_stroked_path(path, w) {
1322
1340
let path_start = 0
1323
1341
1324
1342
function project ( A , B , scale ) {
1325
- // console.log("projecting ",A,B)
1343
+ if ( A . equals ( B ) ) console . log ( "same points! " , A , B )
1326
1344
let delta_unit = A . subtract ( B ) . unit ( )
1327
1345
let C_unit = delta_unit . rotate ( toRad ( 90 ) )
1328
1346
let D_unit = delta_unit . rotate ( toRad ( - 90 ) )
@@ -1365,6 +1383,7 @@ function path_to_stroked_path(path, w) {
1365
1383
if ( cmd [ 0 ] === PATH_COMMAND . LINE ) {
1366
1384
const A = curr
1367
1385
const B = cmd [ 1 ]
1386
+ if ( A . equals ( B ) ) return console . log ( "can't project the same paths" , i , cmd , A , B )
1368
1387
// console.log(i,"====",B)
1369
1388
let next = path [ i + 1 ]
1370
1389
//if first
@@ -1384,6 +1403,7 @@ function path_to_stroked_path(path, w) {
1384
1403
return
1385
1404
}
1386
1405
const C = next [ 1 ]
1406
+ if ( C . equals ( B ) ) return console . log ( "can't project the same paths" , i , cmd , A , B )
1387
1407
// console.log(i,A,B,C)
1388
1408
// console.log("next",next)
1389
1409
let BA = A . subtract ( B )
0 commit comments