@@ -788,18 +788,23 @@ function getFreehandPath(mark: Mark, isPressure: boolean) {
788
788
789
789
function getRectPath ( mark : Mark ) {
790
790
const { points } = mark
791
+ const path = new Path2D ( )
792
+ if ( points . length < 2 ) return path
793
+
791
794
const x0 = Math . min ( points [ 0 ] [ 0 ] , points [ 1 ] [ 0 ] )
792
795
const y0 = Math . min ( points [ 0 ] [ 1 ] , points [ 1 ] [ 1 ] )
793
796
const x1 = Math . max ( points [ 0 ] [ 0 ] , points [ 1 ] [ 0 ] )
794
797
const y1 = Math . max ( points [ 0 ] [ 1 ] , points [ 1 ] [ 1 ] )
795
798
796
- const path = new Path2D ( )
797
799
path . rect ( x0 , y0 , x1 - x0 , y1 - y0 )
798
800
return path
799
801
}
800
802
801
803
function getEllipsePath ( mark : Mark ) {
802
804
const { points } = mark
805
+ const path = new Path2D ( )
806
+ if ( points . length < 2 ) return path
807
+
803
808
const x0 = Math . min ( points [ 0 ] [ 0 ] , points [ 1 ] [ 0 ] )
804
809
const y0 = Math . min ( points [ 0 ] [ 1 ] , points [ 1 ] [ 1 ] )
805
810
const x1 = Math . max ( points [ 0 ] [ 0 ] , points [ 1 ] [ 0 ] )
@@ -809,21 +814,22 @@ function getEllipsePath(mark: Mark) {
809
814
const cx = x0 + w / 2
810
815
const cy = y0 + h / 2
811
816
812
- const path = new Path2D ( )
813
817
path . ellipse ( cx , cy , w / 2 , h / 2 , 0 , 0 , Math . PI * 2 )
814
818
return path
815
819
}
816
820
817
821
function getArrowPath ( mark : Mark ) {
818
822
const { points } = mark
823
+ const path = new Path2D ( )
824
+ if ( points . length < 2 ) return path
825
+
819
826
const [ [ x0 , y0 ] , [ x1 , y1 ] ] = points
820
827
const angle = Math . atan2 ( y1 - y0 , x1 - x0 )
821
828
const distance = Math . hypot ( y1 - y0 , x1 - x0 )
822
829
const leg = ( Math . min ( distance / 2 , 48 ) * mark . size ) / 16
823
830
const [ x2 , y2 ] = projectPoint ( x1 , y1 , angle + Math . PI * 1.2 , leg )
824
831
const [ x3 , y3 ] = projectPoint ( x1 , y1 , angle - Math . PI * 1.2 , leg )
825
832
826
- const path = new Path2D ( )
827
833
path . moveTo ( x0 , y0 )
828
834
path . lineTo ( x1 , y1 )
829
835
path . lineTo ( x2 , y2 )
0 commit comments