{"id":43013,"date":"2003-07-30T18:20:00","date_gmt":"2003-07-30T18:20:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2003\/07\/30\/answer-to-yesterdays-exercise\/"},"modified":"2003-07-30T18:20:00","modified_gmt":"2003-07-30T18:20:00","slug":"answer-to-yesterdays-exercise","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20030730-00\/?p=43013","title":{"rendered":"Answer to yesterday&#039;s exercise"},"content":{"rendered":"<p>\n        <i>iMin<\/i> is the lowest-index element which intersects the paint rectangle, so a\n        simple truncating division produces the desired index.\n    <\/p>\n<p>\n        The formula for <i>iMax<\/i> can be interpreted two ways. One is that it is the roundup\n        of the first invisible line. Recall the rectangles are exclusive of the endpoint,\n        so <i>rcPaint.bottom<\/i> is actually the first row <i>outside<\/i> the rectangle. Since\n        we want the first element that is completely outside the rectangle, we must round\n        up.\n    <\/p>\n<p>\n        A second interpretation begins with the seemingly equivalent formula. First, the expression\n    <\/p>\n<pre>    (pps-&gt;rcPaint.bottom - 1) \/ g_cyLine\n<\/pre>\n<p>\n        computes the index of the last visible item. By adding unity, we get the index of\n        the first invisible item.\n    <\/p>\n<p>\n        In both cases, we do not allow the computed value to exceed <i>g_cItems<\/i> so we\n        don&#8217;t try to draw items that don&#8217;t exist.\n    <\/p>\n<p>\n        The answer to the next question is that the seemingly equivalent formula does not\n        work correctly when <i>rcPaint.bottom<\/i> is zero or negative because the result of\n        integer division is rounded towards zero, which would result in an erroneous computation\n        that the value of <i>iMax<\/i> should be one instead of zero. If integer divisions\n        were rounded towards negative infinity, then the formula would be correct.\n    <\/p>\n<p>\n        And the answer to the final question is that the only harm is that we sometimes draw\n        one item that we really didn&#8217;t need to. In our example, this is not that big a deal\n        since drawing an item is relatively fast. But in cases where drawing an item is expensive,\n        avoiding the drawing of even a single item may prove significant.\n    <\/p>\n<p>\n        And we&#8217;ll see in Part 4 that playing with the origin can cause the paint rectangle\n        to end up in odd positions.\n    <\/p>\n","protected":false},"excerpt":{"rendered":"<p>iMin is the lowest-index element which intersects the paint rectangle, so a simple truncating division produces the desired index. The formula for iMax can be interpreted two ways. One is that it is the roundup of the first invisible line. Recall the rectangles are exclusive of the endpoint, so rcPaint.bottom is actually the first row [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-43013","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>iMin is the lowest-index element which intersects the paint rectangle, so a simple truncating division produces the desired index. The formula for iMax can be interpreted two ways. One is that it is the roundup of the first invisible line. Recall the rectangles are exclusive of the endpoint, so rcPaint.bottom is actually the first row [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=43013"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43013\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=43013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}