# \[Bug Report\] fillRect draw at wrong position when -1\<left\<0

**URL:** <https://forum.makecode.com/t/bug-report-fillrect-draw-at-wrong-position-when-1-left-0/21474>\
**Category:** Help\
**Tags:** graphics-and-math\
**Created:** [July 24, 2023, 11:45pm UTC](https://forum.makecode.com/t/bug-report-fillrect-draw-at-wrong-position-when-1-left-0/21474 "2023-07-24T23:45:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [July 24, 2023, 11:45pm UTC](https://forum.makecode.com/t/bug-report-fillrect-draw-at-wrong-position-when-1-left-0/21474/1 "2023-07-24T23:45:42Z")

</div>

> **[bug-fillRect\_ani](https://arcade.makecode.com/S99591-56787-09975-20335)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

**Phenomenon:**  
As this demo project shown, when the x value(prined first line in each rect) between -1 and 0, it drawn as if 0\<x\<1.

**Expect:**  
values between -1~0 treated as -1, while 0~1 treaded as 0.

The second value in each rect is the x after " **|0**", that maybe the point caused this issue. It used in the pack() function(libs\screen\image.ts), and that called by many other functions, include “fillRect” and “drawRect”, etc.

**Workaround:**  
A workround is minus 1 when -1\<x\<0, you can edit source code, to try it.

> const workaround=true

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [July 25, 2023, 4:33pm UTC](https://forum.makecode.com/t/bug-report-fillrect-draw-at-wrong-position-when-1-left-0/21474/2 "2023-07-25T16:33:57Z")

</div>

**Correct:**  
This issue not only impact in range -1\<x\<0, but all range x\<0.  
Saying “-1\<x\<0”, just for descript the issue easily. 😄

---

<div class="post-metadata">

**Author:** ![AqeeAqee](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/aqeeaqee/32/5424_2.png) [@AqeeAqee](https://forum.makecode.com/u/AqeeAqee)\
**Post date:** [July 25, 2023, 10:27pm UTC](https://forum.makecode.com/t/bug-report-fillrect-draw-at-wrong-position-when-1-left-0/21474/3 "2023-07-25T22:27:23Z")

</div>

Hi @richard @jwunderl  
Correct me pls, if there’s any misunderstand of me.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [July 25, 2023, 11:16pm UTC](https://forum.makecode.com/t/bug-report-fillrect-draw-at-wrong-position-when-1-left-0/21474/4 "2023-07-25T23:16:31Z")

</div>

yes, this is the result of us using `| 0` on all values in our draw functions. if I were to guess, I’d bet this also reproduces for all of our other draw functions (including images) which use the same trick.

the reason we use `| 0` like this is because it’s super fast on hardware. the question is, will fixing this negatively impact perf? i don’t know the answer, but we have to be careful here since it affects much of our most perf-intensive code.

@jwunderl didn’t you and i talk about this a long while back?

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [July 25, 2023, 11:40pm UTC](https://forum.makecode.com/t/bug-report-fillrect-draw-at-wrong-position-when-1-left-0/21474/5 "2023-07-25T23:40:42Z")

</div>

I don’t remember this one in particular for sure, but some cases like this, yeah (and similarly, a few places where we didn’t do this and added it in for consistency)- I’d personally probably lean towards saying that drawing at decimal places should probably be considered basically undefined behavior anyway (we could round but 🤷‍♂️ what’s it really mean to draw at half a pixel), and that if you particularly care for how things round it should be made explicit before calling fillRect (e.g. math.floor, math.ceil, math.round, etc) - we do |0 because it’s the cheapest & prevents things from crashing

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [July 25, 2023, 11:42pm UTC](https://forum.makecode.com/t/bug-report-fillrect-draw-at-wrong-position-when-1-left-0/21474/6 "2023-07-25T23:42:41Z")

</div>

yeah i agree, drawing at decimal places is undefined. this _does_ prevent smoothly scrolling images past the 0 point, however (they’ll get hung up at the 0 point for an extra pixel). not sure if that’s enough of a scenario to fix it though
