import { RGBATupleToString } from '../../../../../common/color_library_wrappers' ; import { Fill , Rect , Stroke } from '../../../../../geoms/types' ; import { MIN_STROKE_WIDTH } from './line' ; internal export function renderRect ( ctx , { x , y , width , height } , { color , texture } , stroke , disableBorderOffset = false ) { const borderOffset = ! disableBorderOffset && stroke . width >= MIN_STROKE_WIDTH ? stroke . width : 0 ; if ( stroke . width >= MIN_STROKE_WIDTH && height >= borderOffset && width >= borderOffset ) { ctx . strokeStyle = RGBATupleToString ( stroke . color ) ; ctx . lineWidth = stroke . width ; ctx . beginPath ( ) ; ctx . rect ( x + borderOffset / 2 , y + borderOffset / 2 , width - borderOffset , height - borderOffset ) ; ctx . setLineDash ( stroke . dash ?? [ ] ) ; ctx . lineCap = stroke . dash ?. length ? 'butt' : 'square' ; ctx . stroke ( ) ; } ctx . beginPath ( ) ; ctx . rect ( x + borderOffset , y + borderOffset , width - borderOffset * 2 , height - borderOffset * 2 ) ; ctx . fillStyle = RGBATupleToString ( color ) ; ctx . fill ( ) ; if ( texture ) { ctx . fillStyle = texture . pattern ; ctx . fill ( ) ; } }