{"id":2629,"date":"2019-01-15T16:28:44","date_gmt":"2019-01-15T08:28:44","guid":{"rendered":"https:\/\/www.aoisnow.net\/blog\/?p=2629"},"modified":"2019-01-15T16:28:44","modified_gmt":"2019-01-15T08:28:44","slug":"tont-40563-%e4%b8%ba%e4%bb%80%e4%b9%88rect%e4%bc%9a%e6%8e%92%e9%99%a4%e7%bb%88%e7%ab%af%e7%ab%af%e7%82%b9","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/2629","title":{"rendered":"TONT 40563 \u4e3a\u4ec0\u4e48RECT\u4f1a\u6392\u9664\u7ec8\u7aef\u7aef\u70b9"},"content":{"rendered":"<p>\u4e3a\u4e86\u4f60\u597d\u3002\uff08\u54a6\uff1f\uff09<\/p>\n<p><!--more--><\/p>\n<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20040218-00\/?p=40563\" target=\"_blank\" rel=\"noopener\">https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20040218-00\/?p=40563<\/a><\/p>\n<p>Endpoint-exclusive RECTs and lines are much easier to work with.<\/p>\n<p>\uff08\u7b80\u800c\u8a00\u4e4b\uff0c\uff09\u6392\u9664\u4e86\u7ec8\u7aef\u7aef\u70b9\u7684\u77e9\u5f62\uff08RECT\uff09\u5904\u7406\u8d77\u6765\u66f4\u5bb9\u6613\u3002<\/p>\n<p>For example, the width of a rectangle is right &#8211; left, and its height is bottom &#8211; top. If rectangles were endpoint-inclusive, then there would be annoying +1&#8217;s everywhere.<\/p>\n<p>\u4f8b\u5982\uff0c\u67d0\u4e2a\u77e9\u5f62\u7684\u5bbd\u5ea6\u662f\u53f3\u7aef\u70b9\u503c\u51cf\u5de6\u7aef\u70b9\u503c\uff0c\u5176\u9ad8\u4e3a\u4e0b\u7aef\u70b9\u503c\u51cf\u4e0a\u7aef\u70b9\u503c\uff0c\u5982\u679c\u77e9\u5f62\u5305\u542b\u7ec8\u7aef\u7aef\u70b9\uff0c\u90a3\u4e48\u5230\u5904\u90fd\u4f1a\u591a1\u4e2a\u50cf\u7d20\uff0c\u800c\u8fd9\u662f\u633a\u8ba8\u538c\u7684\u3002<\/p>\n<p>End-point exclusive rectangles also scale properly.<\/p>\n<p>\u6392\u9664\u7ec8\u7aef\u7aef\u70b9\u7684\u77e9\u5f62\u4e5f\u6709\u5229\u4e8e\u6b63\u786e\u5730\u8fdb\u884c\u7f29\u653e\u3002<\/p>\n<p>For example, suppose you have two rectangles (0,0)-(100,100) and (100,100)-(200,200). These two rectangles barely touch at the corner. Now suppose you magnify these rectangles by 2, so they are now (0,0)-(200,200) and (200,200)-(400,400). Notice that they still barely touch at the corner. Also the length of each edge doubled from 100 to 200.<\/p>\n<p>\u4e3e\u4f8b\u6765\u8bf4\uff0c\u73b0\u5728\u6709\u4e24\u4e2a\u77e9\u5f62(0,0)-(100,100)\u548c(100,100)-(200,200)\uff0c\u8fd9\u4e24\u4e2a\u77e9\u5f62\u5728\u4e24\u4e2a\u9876\u89d2\u5904\u521a\u521a\u597d\u78b0\u5728\u4e00\u8d77\u3002\u73b0\u5728\u5047\u8bbe\u5c06\u8fd9\u4e24\u4e2a\u77e9\u5f62\u653e\u59272\u500d\uff0c\u73b0\u5728\u4e24\u4e2a\u77e9\u5f62\u5c31\u5206\u522b\u662f(0,0)-(200,200)\u548c(200,200)-(400,400)\u4e86\uff0c\u53ef\u4ee5\u6ce8\u610f\u5230\u8fd9\u4e24\u4e2a\u77e9\u5f62\u4ecd\u7136\u5728\u9876\u89d2\u5904\u521a\u521a\u597d\u78b0\u5728\u4e00\u8d77\uff0c\u4e8c\u8005\u7684\u6bcf\u8fb9\u8fb9\u957f\u4e5f\u4ece100\u52a0\u500d\u5230\u4e86200\u3002<\/p>\n<p>Now suppose endpoints were inclusive, so the two rectangles would be (0,0)-(99,99) and (100,100)-(199,199). Now when you double them, you get (0,0)-(198,198) and (200,200)-(398,398). Notice that they no longer touch any more because (199,199) is missing. Note also that the length of the side of the square is now 199 pixels instead of 200.<\/p>\n<p>\u73b0\u5728\u5047\u8bbe\u77e9\u5f62\u7684\u8ba1\u7b97\u5305\u542b\u4e86\u7aef\u70b9\uff0c\u90a3\u8fd9\u4e24\u4e2a\u77e9\u5f62\u5c31\u4f1a\u53d8\u6210(0,0)-(99,99)\u548c(100,100)-(199,199)\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5c06\u5176\u52a0\u500d\u653e\u5927\uff0c\u83b7\u5f97\u7684\u7ed3\u679c\u5c06\u662f(0,0)-(198,198)\u548c(200,200)-(398,398)\u3002\u8bf7\u6ce8\u610f\u6b64\u65f6\u4e24\u4e2a\u77e9\u5f62\u7684\u9876\u89d2\u4e0d\u518d\u78b0\u5728\u4e00\u8d77\uff0c\u56e0\u4e3a(199,199)\u5904\u7684\u50cf\u7d20\u70b9\u6d88\u5931\u4e86\uff0c\u800c\u4e14\u77e9\u5f62\u7684\u8fb9\u957f\u73b0\u5728\u4e5f\u662f199\u50cf\u7d20\u800c\u4e0d\u662f\uff08\u6b63\u786e\u7684\uff09200\u50cf\u7d20\u3002<\/p>\n<p>Similar problems occur if you need to do subpixel computations.<\/p>\n<p>\u7c7b\u4f3c\u7684\u95ee\u9898\u5728\u9700\u8981\u8fdb\u884c\u5b50\u50cf\u7d20\u8ba1\u7b97\u65f6\u4e5f\u4f1a\u53d1\u751f\u3002<\/p>\n<p>&#8220;But that&#8217;s silly &#8212; who ever does magnification or subpixel computations?&#8221;<\/p>\n<p>\u300e\u53ef\u662f\u8fd9\u542c\u8d77\u6765\u633a\u50bb\u7684\uff0c\u6709\u8c01\u4f1a\u6574\u5929\u505a\u8fd9\u79cd\u653e\u5927\u548c\u5b50\u50cf\u7d20\u8ba1\u7b97\u7684\u4e8b\u60c5\u554a\uff1f\u300f<\/p>\n<p>Well, magnification is used more than you think. In addition to the obvious things like zooming in\/out, it&#8217;s also used in printing (since printers are 300dpi but the screen is usually much lower resolution) and in GDI mapping (ScaleWindowExtEx, StretchBlt). And subpixel computations are used in anti-aliasing.<\/p>\n<p>\u5176\u5b9e\u5427\uff0c\u50cf\u4e0a\u9762\u8fd9\u79cd\u653e\u5927\u8ba1\u7b97\u6bd4\u4f60\u60f3\u8c61\u7684\u573a\u5408\u8981\u591a\u3002\u9664\u4e86\u663e\u800c\u6613\u89c1\u7684\uff08\u5c4f\u5e55\u663e\u793a\uff09\u653e\u5927\/\u7f29\u5c0f\u4e4b\u5916\uff0c\u7c7b\u4f3c\u7684\u4e8b\u60c5\u5728\u6253\u5370\u65f6\uff08\u9274\u4e8e\u6253\u5370\u673a\u901a\u5e38\u7684\u5206\u8fa8\u7387\u662f300dpi\uff0c\u4f46\u5c4f\u5e55\u7684\u5206\u8fa8\u7387\u901a\u5e38\u8fdc\u4f4e\u4e8e\u6b64\u6570\u503c\uff09\u548cGDI\u6620\u5c04\uff08ScaleWindowExtEx\u3001StretchBlt\u7b49\uff09\u3002\u6b64\u5916\uff0c\u5b50\u50cf\u7d20\u8ba1\u7b97\u5728\u6297\u952f\u9f7f\u7b49\u529f\u80fd\u4e2d\u4e5f\u5f88\u5e38\u89c1\u3002<\/p>\n<p><a href=\"http:\/\/alvyray.com\/Memos\/MemosMicrosoft.htm#PixelIsNotSquare\" target=\"_blank\" rel=\"noopener\">With apologies to Alvy Ray<\/a>, I think the best way to interpret this is to view pixels as living between coordinates, not at them. For example, here&#8217;s a picture of the pixel that lives between (10,10) and (11,11). (In other words, this pixel is the rectangle (10,10)-(11,11).)<\/p>\n<p><a href=\"http:\/\/alvyray.com\/Memos\/MemosMicrosoft.htm#PixelIsNotSquare\" target=\"_blank\" rel=\"noopener\">\u5728\u8fd9\u91cc\u5bf9Alvy Ray\u8bf4\u58f0\u62b1\u6b49<\/a>\uff08\u8bd1\u6ce8\uff1a\u94fe\u63a5\u6307\u5411\u7684\u9875\u9762\u5df2\u65e0\u6cd5\u8bbf\u95ee\uff0c\u6240\u4ee5\u5e76\u4e0d\u77e5\u9053Raymond\u5728\u4e3a\u5565\u9053\u6b49\uff09\uff0c\u6211\u60f3\u89e3\u91ca\u8fd9\u4e2a\u95ee\u9898\u6700\u597d\u7684\u65b9\u5f0f\u662f\u5c06\u50cf\u7d20\u89c6\u4e3a\u5c45\u4e8e\u50cf\u7d20<strong>\u4e4b\u95f4<\/strong>\uff0c\u800c\u4e0d\u662f<strong>\u4e4b\u4e0a<\/strong>\u3002\u4f8b\u5982\uff0c\u4e0b\u56fe\u793a\u610f\u4e86\u4e00\u4e2a\u5c45\u4e8e\u5750\u6807(10,10)\u548c(11,11)\u4e4b\u95f4\u7684\u50cf\u7d20\u3002\uff08\u4ea6\u5373\uff0c\u8be5\u50cf\u7d20\u7b49\u540c\u4e8e\u77e9\u5f62(10,10)-(11,11)\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2630\" src=\"https:\/\/www.aoisnow.net\/blog\/wp-content\/uploads\/2019\/01\/tont-40563_1.png\" alt=\"\" width=\"131\" height=\"144\" \/><\/p>\n<p>With this interpretation, the exclusion of the endpoint becomes much more natural. For example, here&#8217;s the rectangle (10,10)-(13,12):<\/p>\n<p>\u57fa\u4e8e\u8fd9\u79cd\u89e3\u91ca\uff0c\uff08\u77e9\u5f62\uff09\u5bf9\u4e8e\u7ec8\u7aef\u7aef\u70b9\u7684\u6392\u9664\u5c31\u663e\u5f97\u66f4\u4e3a\u81ea\u7136\u4e86\u3002\u4f8b\u5982\uff0c\u4e0b\u56fe\u793a\u610f\u7684\u662f\u77e9\u5f62(10,10)-(13,12)\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2631\" src=\"https:\/\/www.aoisnow.net\/blog\/wp-content\/uploads\/2019\/01\/tont-40563_2.png\" alt=\"\" width=\"224\" height=\"186\" \/><\/p>\n<p>Observe that this rectangle starts at (10,10) and ends at (13,12), just like its coordinates say.<\/p>\n<p>\u89c2\u5bdf\u53ef\u5f97\u8be5\u77e9\u5f62\u4ece(10,10)\u5f00\u59cb\uff0c\u81f3(13,12)\u4e3a\u6b62\uff0c\u6b63\u5982\u5176\u5750\u6807\u6240\u8868\u8ff0\u7684\u90a3\u6837\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u4f60\u597d\u3002\uff08\u54a6\uff1f\uff09<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2629","post","type-post","status-publish","format-standard","hentry","category-tont_history"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/2629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=2629"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/2629\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=2629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=2629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=2629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}