@@ -64,18 +64,23 @@ class CanvasRenderer {
6464
6565 /**
6666 * Converts an RGBA array [R, G, B, A] with values between 0 and 1 to a CSS color string.
67- * @param {number[] } rgba - The RGBA array.
67+ * @param {number[]|object } rgba - The RGBA array or object with r, g, b, a properties .
6868 * @returns {string } The CSS color string.
6969 */
7070 rgbaToCssColor ( rgba ) {
71- const [ r , g , b , a ] = rgba ;
72- return `rgba(${ Math . round ( r * 255 ) } , ${ Math . round ( g * 255 ) } , ${ Math . round ( b * 255 ) } , ${ a } )` ;
71+ if ( rgba . r !== undefined ) {
72+ const { r, g, b, a } = rgba ;
73+ return `rgba(${ Math . round ( r * 255 ) } , ${ Math . round ( g * 255 ) } , ${ Math . round ( b * 255 ) } , ${ a } )` ;
74+ } else {
75+ const [ r , g , b , a ] = rgba ;
76+ return `rgba(${ Math . round ( r * 255 ) } , ${ Math . round ( g * 255 ) } , ${ Math . round ( b * 255 ) } , ${ a } )` ;
77+ }
7378 }
7479
7580 /**
7681 * Draw a point.
7782 * @param {Point } p
78- * @param {number[] } [color=[0, 0, 0, 1]]
83+ * @param {number[]|object } [color=[0, 0, 0, 1]]
7984 * @param {number } [size=5]
8085 */
8186 drawPoint ( p , color = [ 0 , 0 , 0 , 1 ] , size = 5 ) {
@@ -86,11 +91,15 @@ class CanvasRenderer {
8691 /**
8792 * Draw a line.
8893 * @param {Line } l
89- * @param {number[] } [color=[0, 0, 0, 1]]
94+ * @param {number[]|object } [color=[0, 0, 0, 1]]
95+ * @param {boolean } [showArrow=false] (not implemented, just for parameter consistency)
96+ * @param {number[] } [lineDash=[]]
97+ * @param {number } [lineWidth=1]
9098 */
91- drawLine ( l , color = [ 0 , 0 , 0 , 1 ] ) {
99+ drawLine ( l , color = [ 0 , 0 , 0 , 1 ] , showArrow = false , lineDash = [ ] , lineWidth = 1 ) {
100+ this . ctx . setLineDash ( lineDash . map ( value => value * this . lengthScale ) ) ;
92101 this . ctx . strokeStyle = this . rgbaToCssColor ( color ) ;
93- this . ctx . lineWidth = 1 * this . lengthScale ;
102+ this . ctx . lineWidth = lineWidth * this . lengthScale ;
94103 this . ctx . beginPath ( ) ;
95104 let ang1 = Math . atan2 ( ( l . p2 . x - l . p1 . x ) , ( l . p2 . y - l . p1 . y ) ) ;
96105 let cvsLimit = ( Math . abs ( l . p1 . x + this . origin . x ) + Math . abs ( l . p1 . y + this . origin . y ) + this . canvas . height + this . canvas . width ) / Math . min ( 1 , this . scale ) ;
@@ -102,14 +111,15 @@ class CanvasRenderer {
102111 /**
103112 * Draw a ray.
104113 * @param {Line } r
105- * @param {number[] } [color=[0, 0, 0, 1]]
114+ * @param {number[]|object } [color=[0, 0, 0, 1]]
106115 * @param {boolean } [showArrow=true]
107116 * @param {number[] } [lineDash=[]]
117+ * @param {number } [lineWidth=1]
108118 */
109- drawRay ( r , color = [ 0 , 0 , 0 , 1 ] , showArrow = false , lineDash = [ ] ) {
110- this . ctx . setLineDash ( lineDash ) ;
119+ drawRay ( r , color = [ 0 , 0 , 0 , 1 ] , showArrow = false , lineDash = [ ] , lineWidth = 1 ) {
120+ this . ctx . setLineDash ( lineDash . map ( value => value * this . lengthScale ) ) ;
111121 this . ctx . strokeStyle = this . rgbaToCssColor ( color ) ;
112- this . ctx . lineWidth = 1 * this . lengthScale ;
122+ this . ctx . lineWidth = lineWidth * this . lengthScale ;
113123 this . ctx . fillStyle = this . rgbaToCssColor ( color ) ;
114124
115125 // Check if ray has a valid direction
@@ -190,14 +200,15 @@ class CanvasRenderer {
190200 /**
191201 * Draw a segment.
192202 * @param {Line } s
193- * @param {number[] } [color=[0, 0, 0, 1]]
203+ * @param {number[]|object } [color=[0, 0, 0, 1]]
194204 * @param {boolean } [showArrow=true]
195- * @param {number } [arrowPosition=0.67] Position of arrow along line (0 to 1, where 0 is at p1 and 1 is at p2)
205+ * @param {number[] } [lineDash=[]]
206+ * @param {number } [lineWidth=1]
196207 */
197- drawSegment ( s , color = [ 0 , 0 , 0 , 1 ] , showArrow = false , lineDash = [ ] ) {
198- this . ctx . setLineDash ( lineDash ) ;
208+ drawSegment ( s , color = [ 0 , 0 , 0 , 1 ] , showArrow = false , lineDash = [ ] , lineWidth = 1 ) {
209+ this . ctx . setLineDash ( lineDash . map ( value => value * this . lengthScale ) ) ;
199210 this . ctx . strokeStyle = this . rgbaToCssColor ( color ) ;
200- this . ctx . lineWidth = 1 * this . lengthScale ;
211+ this . ctx . lineWidth = lineWidth * this . lengthScale ;
201212 this . ctx . fillStyle = this . rgbaToCssColor ( color ) ;
202213
203214 // Calculate arrow size first to determine if we should draw it
@@ -272,7 +283,7 @@ class CanvasRenderer {
272283 /**
273284 * Draw a circle.
274285 * @param {Circle } c
275- * @param {String } [color='black']
286+ * @param {String|object } [color='black']
276287 */
277288 drawCircle ( c , color = 'black' ) {
278289 this . ctx . strokeStyle = color ;
0 commit comments