{"id":18286214,"url":"https://github.com/azrafe7/intersectrect","last_synced_at":"2026-02-12T20:31:54.715Z","repository":{"id":11587971,"uuid":"14078463","full_name":"azrafe7/IntersectRect","owner":"azrafe7","description":"Find rectangles overlapping area (AS3 vs custom - proof of concept in FlashPunk).","archived":false,"fork":false,"pushed_at":"2013-11-18T20:46:20.000Z","size":276,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-12T19:01:01.394Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"ActionScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azrafe7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-03T01:44:24.000Z","updated_at":"2013-11-18T20:46:22.000Z","dependencies_parsed_at":"2022-08-20T17:50:14.632Z","dependency_job_id":null,"html_url":"https://github.com/azrafe7/IntersectRect","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/azrafe7/IntersectRect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azrafe7%2FIntersectRect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azrafe7%2FIntersectRect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azrafe7%2FIntersectRect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azrafe7%2FIntersectRect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azrafe7","download_url":"https://codeload.github.com/azrafe7/IntersectRect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azrafe7%2FIntersectRect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29380604,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T19:05:20.189Z","status":"ssl_error","status_checked_at":"2026-02-12T19:01:44.216Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T13:19:15.343Z","updated_at":"2026-02-12T20:31:54.701Z","avatar_url":"https://github.com/azrafe7.png","language":"ActionScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"IntersectRect\n=============\n\nFind rectangles overlapping area (AS3 vs custom - proof of concept in FlashPunk). [(swf)](https://dl.dropboxusercontent.com/u/32864004/dev/FPDemo/IntersectRect.swf)\n\n\nJust found out - _through bad times_ - that the rects involved in `Rectangle.intersection()` (and `intersects()`) calls\nmust guarantee to have non-negative sizes, otherwise no collision will be detected, even though they effectively overlap.\n\nBasically just ensure you have only non-negative-sized rectangles in your app, or run the rect through something like this and you'll be fine:\n\n```as3\n/**\n * Fix rectangle if dimensions are negative.\n * \n * Ex.: [x: 5, y:5, w:-15, h:10] -\u003e [x: -10, y:5, w:15, h:10]\n */\npublic function fixRect(rect:Rectangle):Rectangle \n{\n\tif (rect.width \u003c 0) {\n\t\trect.x += rect.width;\n\t\trect.width *= -1;\n\t}\n\tif (rect.height \u003c 0) {\n\t\trect.y += rect.height;\n\t\trect.height *= -1;\n\t}\n\t\n\treturn rect;\n}\n```\n\nHere's a fairly generic code for future reference (doesn't even use `right` and `bottom` properties) to \ncalc the overlapping region and optionally account for negative rect dimensions:\n\n```as3\n/**\n * Finds overlapping area between [rect1] and [rect2]. Notes: ...\n * \n * Set [fixDimensions] to true to make it work also for rectangles with negative widths or heights.\n * The original rects will not be modified.\n * \n * @param\trect1\t\t\t\tRectangle to check for collision/overlapping with [rect2].\n * @param\trect2\t\t\t\tRectangle to check for collision/overlapping with [rect1].\n * @param\tfixDimensions\t\tAdjust dimensions \u0026 pos if width || height \u003c 0?\n * \n * @return Overlapping rectangle region or an empty rectangle if [rect1] and [rect2] don't overlap.\n */\npublic function intersection(rect1:Rectangle, rect2:Rectangle, fixDimensions:Boolean = true):Rectangle \n{\n\t// init\n\tvar x1:Number = rect1.x, \t\ty1:Number = rect1.y,\t\t// rect1 pos\n\t\tw1:Number = rect1.width, \th1:Number = rect1.height,\t// rect1 size\n\t\tx2:Number = rect2.x, \t\ty2:Number = rect2.y,\t\t// rect2 pos\n\t\tw2:Number = rect2.width, \th2:Number = rect2.height;\t// rect2 size\n\t\t\n\t// convert to positive dimensions?\n\tif (fixDimensions) {\n\t\t// rect1\n\t\tif (w1 \u003c 0) { x1 += w1; w1 = -w1; }\n\t\tif (h1 \u003c 0) { y1 += h1; h1 = -h1; }\n\t\t// rect2\n\t\tif (w2 \u003c 0) { x2 += w2; w2 = -w2; }\n\t\tif (h2 \u003c 0) { y2 += h2; h2 = -h2; }\n\t}\n\t\n\t// calc bounds\n\tvar left:Number = Math.max(x1, x2);\n\tvar right:Number = Math.min(x1 + w1, x2 + w2);\n\tvar top:Number = Math.max(y1, y2);\n\tvar bottom:Number = Math.min(y1 + h1, y2 + h2);\n\t\n\t// calc size\n\tvar width:Number = right - left;\n\tvar height:Number = bottom - top;\n\t\n\treturn (width \u003c 0 || height \u003c 0) ? new Rectangle() : new Rectangle(left, top, width, height);\n}\n```\n\n\nNote that for systems where the origin point is in the bottom-left corner\n(instead of top-left like AS3 and many others) you'll need to change this:\n\n```as3\n\tvar top:Number = Math.max(y1, y2);\n\tvar bottom:Number = Math.min(y1 + h1, y2 + h2);\n```\n\nwith:\n\n```as3\n\tvar top:Number = Math.min(y1, y2);\n\tvar bottom:Number = Math.max(y1 + h1, y2 + h2);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazrafe7%2Fintersectrect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazrafe7%2Fintersectrect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazrafe7%2Fintersectrect/lists"}