{"id":170,"date":"2010-10-14T21:19:17","date_gmt":"2010-10-14T20:19:17","guid":{"rendered":"https:\/\/greladesign.co\/blog\/?p=170"},"modified":"2010-10-14T21:19:17","modified_gmt":"2010-10-14T20:19:17","slug":"rectangle-with-%e2%80%9csorted%e2%80%9d-edges","status":"publish","type":"post","link":"https:\/\/greladesign.co\/blog\/2010\/10\/14\/rectangle-with-%e2%80%9csorted%e2%80%9d-edges\/","title":{"rendered":"Rectangle with \u201csorted\u201d edges"},"content":{"rendered":"<p>In some situation you would like to reassure that given Rectangle object have &#8220;top-down, left-right&#8221; order you can do it using following two snippets<\/p>\n<p>this creates &#8220;normalized&#8221; copy of the given rectangle<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\r\n\t\t\/**\r\n\t\t * Takes rectangle as a parameter and returns new with sorted edges, i.e. (x=50, y=50, w=-100, h=-100) becomes (x=-50, y=-50, w=100, h=100). In other words it makes sure that rectangles top and left are smaller than bottom and right respectively.\r\n\t\t * \r\n\t\t * @param\tp_oRect\r\n\t\t * @return\r\n\t\t *\/\r\n\t\tprotected function normalizeRect(p_oRect:Rectangle):Rectangle\r\n\t\t{\r\n\t\t\tvar nr:Rectangle = new Rectangle();\r\n\t\t\t\tnr.top = Math.min(p_oRect.top, p_oRect.bottom);\r\n\t\t\t\tnr.bottom = Math.max(p_oRect.top, p_oRect.bottom);\r\n\t\t\t\tnr.left = Math.min(p_oRect.left, p_oRect.right);\r\n\t\t\t\tnr.right = Math.max(p_oRect.left, p_oRect.right);\r\n\t\t\t\t\r\n\t\t\treturn nr;\r\n\t\t}\r\n<\/pre>\n<p>this modifies given rectangle directly<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\t\t\/**\r\n\t\t * Modifies the rectangle given in parameter and makes sure that edges are sorted, i.e. (x=50, y=50, w=-100, h=-100) becomes (x=-50, y=-50, w=100, h=100). In other words it makes sure that rectangles top and left are smaller than bottom and right respectively.\r\n\t\t * This method works directly on the object without making a copy.\r\n\t\t * @param\tp_oRectRef\r\n\t\t *\/\r\n\t\tprotected function normalizeRectV2(p_oRectRef:Rectangle):void\r\n\t\t{\r\n\t\t\tvar _nSwap:Number;\r\n\t\t\t_nSwap = p_oRectRef.top;\r\n\t\t\tp_oRectRef.top = Math.min(_nSwap, p_oRectRef.bottom);\r\n\t\t\tp_oRectRef.bottom = Math.max(_nSwap, p_oRectRef.top);\r\n\t\t\t\r\n\t\t\t_nSwap = p_oRectRef.left;\r\n\t\t\tp_oRectRef.left = Math.min(_nSwap, p_oRectRef.right);\r\n\t\t\tp_oRectRef.right = Math.max(_nSwap, p_oRectRef.left);\r\n\t\t}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In some situation you would like to reassure that given Rectangle object have &#8220;top-down, left-right&#8221; order you can do it using following two snippets this creates &#8220;normalized&#8221; copy of the given rectangle this modifies given rectangle directly<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":""},"categories":[17,9],"tags":[12,35,34],"_links":{"self":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/170"}],"collection":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":5,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":176,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/170\/revisions\/176"}],"wp:attachment":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}