@@ -6,29 +6,29 @@ const OUTSIDE = 'outside';
66
77export default function ( paths , point , {
88 lineWidth = 1.0 ,
9- precision = 0.1 ,
10- miterLimit = 5 .0,
9+ scale = 10.0 ,
10+ miterLimit = 2 .0,
1111 fillOffset = CENTER
1212} = { } ) {
1313 // calculate linewith
14- lineWidth /= precision * 2.0 ;
14+ lineWidth *= scale / 2.0 ;
1515 // convert point to uppercase
16- point = { X : point . x / precision , Y : point . y / precision } ;
16+ point = { X : point . x * scale , Y : point . y * scale } ;
1717
1818 // create clipper shape
1919 const shape = new Shape ( paths , false , true , true , true )
2020 // scale up for precision
21- . scaleDown ( precision )
21+ . scaleUp ( scale )
2222 // convert lines to polygons (this gives lines width)
23- . offset ( 2.0 , { jointType : 'jtMiter' , endType : 'etOpenSquare' , miterLimit : 1.0 } )
23+ . offset ( lineWidth , { jointType : 'jtMiter' , endType : 'etOpenSquare' , miterLimit } )
2424 // union all overlapping paths
2525 . removeOverlap ( )
2626 // make all holes outlines and all outlines holes
2727 . reverse ( )
2828 // seperate all shapes into (these all all plausible fills)
2929 . seperateShapes ( )
3030 // find shape with hit
31- . find ( shape => shape . pointInShape ( point ) ) ;
31+ . find ( fill => fill . pointInShape ( point ) ) ;
3232
3333 // if no fill has been found return empty shape
3434 if ( ! shape ) return [ ] ;
@@ -37,24 +37,24 @@ export default function(paths, point, {
3737 let offset ;
3838 switch ( fillOffset ) {
3939 case CENTER :
40- offset = 2.0 ;
40+ offset = lineWidth ;
4141 break ;
4242 case INSIDE :
43- offset = 2.0 - lineWidth ;
43+ offset = 0 ;
4444 break ;
4545 case OUTSIDE :
46- offset = 2.0 + lineWidth ;
46+ offset = lineWidth * 2.0 ;
4747 break ;
4848 default :
49- offset = 2.0 ;
49+ offset = lineWidth ;
5050 break ;
5151 }
5252
5353 return shape
5454 // offset result to account for converting to polygon
5555 . offset ( offset , { jointType : 'jtMiter' , endType : 'etClosedPolygon' , miterLimit } )
5656 // scale down to accout for scale up
57- . scaleUp ( precision )
57+ . scaleDown ( scale )
5858 // convert uppercase points to lowercase points
5959 . mapToLower ( ) ;
6060}
0 commit comments