{"id":28739911,"url":"https://github.com/opyh/motion-ui-geometry","last_synced_at":"2025-09-07T04:40:33.189Z","repository":{"id":3774324,"uuid":"4851371","full_name":"opyh/motion-ui-geometry","owner":"opyh","description":"Access CoreGraphics UI geometry the Ruby way.","archived":false,"fork":false,"pushed_at":"2012-07-07T16:41:28.000Z","size":151,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-01T07:33:24.389Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opyh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-01T15:56:19.000Z","updated_at":"2024-06-21T15:34:30.000Z","dependencies_parsed_at":"2022-08-17T23:01:01.744Z","dependency_job_id":null,"html_url":"https://github.com/opyh/motion-ui-geometry","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/opyh/motion-ui-geometry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opyh%2Fmotion-ui-geometry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opyh%2Fmotion-ui-geometry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opyh%2Fmotion-ui-geometry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opyh%2Fmotion-ui-geometry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opyh","download_url":"https://codeload.github.com/opyh/motion-ui-geometry/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opyh%2Fmotion-ui-geometry/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273997107,"owners_count":25204473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-06-16T06:11:14.010Z","updated_at":"2025-09-07T04:40:33.141Z","avatar_url":"https://github.com/opyh.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# motion-ui-geometry\n\nWrite Cocoa Touch UIs like a boss™! A gem\ndesigned for [RubyMotion](http://rubymotion.com) for iOS.\n\n##\n\n## Usage\n\n### OOP-Style Access to Geometry Functions\n\nCarefully adapted to match Ruby's style while keeping method names\nobvious for people with CoreGraphics knowledge.\n\nSome examples:\n\n#### `Float`\n\n```ruby\nmy_float.clamp(min, max)\nmy_float.to_radians\nmy_float.to_degrees\n```\n\n#### `CGPoint`\n\n```ruby\ninteger_point = point.round\ninteger_point = point.floor\npoint.distance_to other_point\npoint.clamp_to_rect boundary_rect # returns the nearest point inside given rect\npoint.to_size\n```\n\n#### `CGSize`\n\n```ruby\ninteger_size = size.round\ninteger_size = size.floor\nsize.to_point\n```\n\n#### `CGRect`\n\n```ruby\nrect = CGRect.from_origin(origin, size)\n\nrect.empty?\nrect.intersect?(other_rect)\nrect.contain?(other_rect)\nrect.null?\n\nrect.inset(5, 5)\nrect.union(other_rect)\nrect.intersection(other_rect)\n[right_division, left_division] = rect.divide(0.2, :right)\n\nrect.top_left, rect.bottom_left, rect.bottom_right, rect.top_right\ncenter_point = rect.center\n```\n\n#### `CGAffineTransform`\n\n```ruby\nidentity_transform = CGAffineTransform.identity\n\nCGAffineTransform.rotation(angle)\nCGAffineTransform.scale(sx, sy)\nCGAffineTransform.translation(tx, ty)\nCGAffineTransform.skew(sx, sy)\n\nmy_transform.rotate(angle)\nmy_transform.scale(sx, sy)\nmy_transform.translate(tx, ty)\nmy_transform.skew(sx, sy)\n\ntransformed_transform = my_transform.concat other_transform\ntransformed_transform = other_transform.apply_on my_transform\ndeterminant = transform.det\n\ntransform.identity?\n\ninverse = some_transform.invert\nsome_transform * inverse == CGAffineTransform.identity\n```\n\n#### Obtaining `NSValue`s\n\nHandy for use with CoreAnimation.\n\nJust call `#to_value` on your geometry:\n\n```ruby\nfloat_value = some_float.to_value\npoint_value = some_point.to_value\nsize_value = some_size.to_value\nrect_value = some_rect.to_value\ntransform_value = some_transform.to_value\n```\n\n#### Conversion from/to `NSString` and `NSDictionary`\n\nHandy for serialization:\n\n```ruby\npoint.to_s\nsize.to_s\nrect.to_s\ntransform.to_s\n\nstring.to_point\nstring.to_size\nstring.to_rect\nstring.to_transform\n```\n\n### Approximate Comparison of Geometry via `=~`\n\n```ruby\nsome_float =~ 1.5                      # =\u003e true if float is ~1.5\nsome_float.roughly_equal?(1.5, 0.001)  # =\u003e true if float is ~1.5 within 0.001 error margin\n\nrect == other_rect            # =\u003e true if coordinates are exactly equal\n\nsize =~ other_size            # =\u003e true if coordinates are roughly equal\npoint =~ other_point          # =\u003e true if coordinates are roughly equal\ntransform =~ other_transform  # =\u003e true if coordinates are roughly equal\n```\n\n### Transforming Geometry Using Operators\n\nI have tried to keep operator behavior obvious.\n\n#### `+ - * /` + Operand Type Mixing\n\n```ruby\noffset_point   = point + other_point\noffset_point   = point - offset_size\nnegative_point = -point\n\noffset_size    = size + offset_point\noffset_size    = size - offset_size\nnegative_size  = -size\n\noffset_rect    = rect + point\noffset_rect    = rect + size\nnegative_rect  = -rect\n\nscaled_point   = point * 3.0\nscaled_size    = size * 2.0\nscaled_rect    = rect * 4.0\nscaled_rect    = rect * CGSizeMake(1, 2)\n\nscaled_point   = point / 3.0\nscaled_size    = size / 2.0\nscaled_rect    = rect / 4.0\n\noffset_rect    = rect + point\nresized_rect   = rect + size\n```\n\n#### Scale, Rotate, Transform and Skew `UIView`s and Geometry\n\nJust create a `CGAffineTransform` and multiply with it to transform:\n\n```ruby\ndouble_size = CGAffineTransform.scale(2.0, 2.0)\nrotation = CGAffineTransform.rotation(30.0.to_rad)\n\nmy_image_view.transform = rotation\n\nrotated_point = point * rotation\nrotated_size = size * rotation\nrotated_rect = rect * rotation\n\nscaled_rotation = rotation * double_size\nscaled_transform = some_transform * 2.0 # scales x and y\n\nscaled_rotated_rect = rect * scaled_rotation\nscaled_rotated_point = point * scaled_rotation\n\ntranslated_transform       = transform + offset_point\nother_translated_transform = transform + offset_size\n```\n\n#### Unionize and Intersect `CGRect`s\n\n```ruby\nunion          = rect1 | rect2\nintersection   = rect1 \u0026 rect2\n```\n\n## Installation\n\n1. If not done yet, add `bundler` gem management to your RubyMotion app.\n   See \u003chttp://thunderboltlabs.com/posts/using-bundler-with-rubymotion\u003e for\n   an explanation how.\n\n2. Add this line to your application's Gemfile:\n\n   ```ruby\n   gem 'motion-ui-geometry'\n   ```\n\n3. Execute:\n\n   ```bash\n   $ bundle\n   ```\n\n## Contributing\n\nFeel free to fork the project and send me a pull request if you would\nlike me to integrate your bugfix, enhancement, or feature. I'm also open for suggestions regarding new features and the interface design.\n\nTo contribute,\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\nIf the feature has specs, I will probably merge it :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopyh%2Fmotion-ui-geometry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopyh%2Fmotion-ui-geometry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopyh%2Fmotion-ui-geometry/lists"}