I changed one line in my text-layout code to be compatible with immutable rectangles:
- metrics.area.location = metrics.area.location.neg.add offset + metrics.area = rect metrics.area.location.neg.add(offset), metrics.area.sizeI can tell you there were no bugs in the new immutable Rectangle class.
Can you spot the bug?
There is no bug. The new line is correct, and yet that's all I changed.
It turns out I originally had a bug due to a mutation I wasn't taking into account, but that mutation made the layout algorithm work. When I stopped mutating the rectangle object, the "bug" stopped making the algorithm work. The reason it took me hours to find this bug was the new code was "right", but the algorithm was wrong.
Here's what was actually wrong, in 3 code snippets (CoffeeScript):
1) The original code that worked but had an accidental mutation:
updateTextLayout: -> offset = point() @area = @metricsList.area # object assigned here for metrics in @metricsList metrics.area.location = metrics.area.location.neg.add offset # gets mutated here the first time through the loop offset = offset.add 0, @fontSize @area = @area.union metrics.area @size = @area.size2) Code with one line changed that seemed correct but didn't work:
updateTextLayout: -> offset = point() @area = @metricsList.area for metrics in @metricsList metrics.area = rect metrics.area.location.neg.add(offset), metrics.area.size # @area no longer gets mutated offset = offset.add 0, @fontSize @area = @area.union metrics.area @size = @area.size3) Final working code:
updateTextLayout: -> offset = point() @area = null # FIX - don't capture the wrong value here for metrics in @metricsList metrics.area = rect metrics.area.location.neg.add(offset), metrics.area.size offset = offset.add 0, @fontSize @area = if @area then @area.union metrics.area else metrics.area # FIX - capture the right value here @size = @area.size
Tread cautiously and rigorously test your software to find all problems pre-deployment, or test less and ship faster with greater tolerance for bugs in production. Moreover, Click Here to get our customized solutions for Interior Painting Services in Suwanee, GA.ReplyDelete
Daftar Joker123 Slot Review | ShootercasinoReplyDelete
Find out 1xbet korean about the Daftar Joker123 online slot 제왕 카지노 review & play its demo free or for real money 메리트카지노 at ShootCasino.com. Check the complete review.