{"id":1397,"url":"https://github.com/toineheuvelmans/Metron","last_synced_at":"2025-08-02T04:31:07.010Z","repository":{"id":56738645,"uuid":"94532056","full_name":"toineheuvelmans/Metron","owner":"toineheuvelmans","description":"Geometry, simplified.","archived":false,"fork":false,"pushed_at":"2019-07-05T06:53:28.000Z","size":2047,"stargazers_count":1035,"open_issues_count":6,"forks_count":35,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-07-25T10:51:32.696Z","etag":null,"topics":["coregraphics","geometry","swift","trigonometry"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/toineheuvelmans.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":"2017-06-16T10:09:00.000Z","updated_at":"2025-06-30T20:31:19.000Z","dependencies_parsed_at":"2022-08-16T01:00:48.701Z","dependency_job_id":null,"html_url":"https://github.com/toineheuvelmans/Metron","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/toineheuvelmans/Metron","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toineheuvelmans%2FMetron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toineheuvelmans%2FMetron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toineheuvelmans%2FMetron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toineheuvelmans%2FMetron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toineheuvelmans","download_url":"https://codeload.github.com/toineheuvelmans/Metron/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toineheuvelmans%2FMetron/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334610,"owners_count":24233793,"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-08-02T02:00:12.353Z","response_time":74,"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":["coregraphics","geometry","swift","trigonometry"],"created_at":"2024-01-05T20:15:45.502Z","updated_at":"2025-08-02T04:31:06.618Z","avatar_url":"https://github.com/toineheuvelmans.png","language":"Swift","funding_links":[],"categories":["Math","Swift"],"sub_categories":["Other Hardware","Other free courses"],"readme":"![](documentation/asset/metron_header.jpg)\n\n[![Build Status](https://travis-ci.com/toineheuvelmans/Metron.svg?branch=master)](https://travis-ci.com/toineheuvelmans/Metron)\n[![GitHub Release](https://img.shields.io/github/release/toineheuvelmans/Metron.svg)](https://github.com/toineheuvelmans/Metron/releases)\n[![CocoaPods Release](https://img.shields.io/cocoapods/v/Metron.svg?style=flat)](http://cocoapods.org/pods/Metron)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![SwiftPM Compatible](https://img.shields.io/badge/SwiftPM-compatible-orange.svg)](#swift-package-manager)\n[![Supported Platforms](https://img.shields.io/cocoapods/p/Metron.svg?style=flat)](http://cocoapods.org/pods/Metron)\n\n# Metron\n\n_Geometry, simplified._\n\nMetron is a comprehensive collection of geometric functions and types that extend the 2D geometric primitives provided by CoreGraphics. Completely written in Swift, Metron allows you to express complex geometric calculations in very intuitive statements:\n\n**Example 1.**\n\n```swift\nCircle(in: viewFrame).contains(touchPoint)\n```\n↳ creates a `Circle` that fits (centered) inside `viewFrame`, and checks if the `touchPoint` is inside that circle.\n\n**Example 2.**\n\n```swift\n(Angle(.pi) + Angle(270, unit: .degrees)).normalized // Angle of 0.5pi (90°)\n```\n↳ adds two `Angles`, one expressed in radians (default) and one in degrees. The sum is normalized to within 0 and 2𝛑 radians *(or 0 and 360 degrees)*.\n\n**Example 3.**\n\n```swift\nLineSegment(a: startPoint, b: currentPoint).intersection(with: viewFrame.lineSegment(for: minYEdge))\n```\n↳ creates a `LineSegment` between a (touch) start point and current point, and returns the intersection with the `minYEdge` of a view's frame (if these line segments indeed intersect).\n\n**Example 4.**\n\n```swift\nlet rotatedPoints = viewFrame.points.map { $0.applying(rotationTransform, anchorPoint: rotationPoint) }\nlet path: CGPath = Polygon(points: rotatedPoints).path\n```\n↳ maps each corner point of a view's frame (a `CGRect`) to a point to which a `rotationTransform` is applied, taking `rotationPoint` as the anchor point for the transform.\nWith these points, a `Polygon` is initialized, representing the rotated rectangular frame of the view. From that polygon, we derive a `CGPath` that can then be drawn.\n\n\n## And there's much more...\n\n### Extensions\n\n#### For CGPoint\n\n- [X] Distance to other `CGPoint`\n- [X] Clipping to `CGRect`\n- [X] Relative position in `CGRect`\n- [X] Normalized position in `CGRect`\n- [X] Convert to `CGVector`\n- [X] Round to non-decimal components\n- [X] Addition, subtraction, multiplication...\n- [X] Convex hull for an array of `CGPoints` (returns a `Polygon`)\n\n#### For CGVector\n\n- [X] Magnitude\n- [X] Angle\n- [X] Convenience initializer with magnitude and angle\n- [X] Convert to `CGPoint`\n- [X] Inverse\n- [X] Dominant edge\n- [X] Dominant corner\n- [X] Derive line through point\n- [X] Derive line segment from point\n- [X] `CGAffineTransform` extensions\n- [X] Addition, subtraction, multiplication...\n\n#### For CGSize\n\n- [X] Area\n- [X] Swap width and height\n- [X] Clip to other `CGSize`\n- [X] Scaling using multiplication and division\n\n#### For CGRect\n\n- [X] Many convenience initializers, including AspectFit / AspectFill for size\n- [X] Scaling\n- [X] Corner points\n- [X] Edges as line segments\n- [X] Area\n- [X] Center\n- [X] Perimeter\n- [X] `CGPath`\n\n#### For CGRectEdge\n\n- [X] Axis (x or y)\n- [X] Adjacent corners\n- [X] Opposite edge\n\n#### For CGAffineTransform\n\n- [X] Create translation transform using `CGVector`\n- [X] Apply transform with a specified anchor point\n\n### New Types\n\n#### Line\n\n- [X] Slope\n- [X] Y-intercept\n- [X] X-intercept\n- [X] Horizontal? / vertical? / parallel(to: ...)?\n- [X] Get a perpendicular line\n- [X] Determine intersection with other `Line` or `LineSegment`\n\n#### LineSegment\n\n- [X] Length\n- [X] Derive a `Line`\n- [X] Rotate\n- [X] Determine intersection with other `Line` or `LineSegment`\n- [X] `CGPath`\n\n#### Circle\n\n- [X] Radius\n- [X] Diameter\n- [X] Circumference\n- [X] Area\n- [X] Center\n- [X] Width / Height\n- [X] Bounding rect\n- [X] Contains point?\n- [X] `CGPath`\n- [X] Points along the perimeter (divide the circle into steps, rotating in a specific direction...)\n\n#### Triangle\n\n- [X] Vertices (as `CGPoint`)\n- [X] Sides (as `LineSegment`)\n- [X] Angles (as `Angle`, see further on)\n- [X] Angle bisectors (as `LineSegment`)\n- [X] Altitudes (as `LineSegment`)\n- [X] Equilateral? / isosceles? / scalene? / right? / oblique? / acute? / obtuse?\n- [X] Centroid\n- [X] Circumcenter\n- [X] Incenter\n- [X] Orthocenter\n- [X] Area\n- [X] Bounding rect\n- [X] Contains point?\n- [X] `CGPath`\n\n#### Square\n\n- [X] Edge length\n- [X] Area\n- [X] Perimeter\n- [X] Center\n- [X] `CGPath`\n- [X] `CGRect`\n\n#### Polygon\n\n- [X] Init with points or with line segments\n- [X] Edge count\n- [X] Self-intersecting?\n- [X] Convex? / concave?\n- [X] Area\n- [X] Perimeter\n- [X] Center\n- [X] Bounding rect\n- [X] Contains point?\n- [X] `CGPath`\n\n#### Corner\n\n- [X] Adjacent edges (`CGRectEdges`)\n- [X] Opposite corner\n\n#### Angle\n\n- [X] Init with radians or degrees\n- [X] Convert unit\n- [X] Normalize\n- [X] Invert\n- [X] Compare\n- [X] Addition, subtraction, multiplication...\n- [X] Basic trigonometric functions also accept `Angle`\n- [X] Create rotation `CGAffineTransform` with `Angle`\n\n\n## Installation\n\n### CocoaPods\n\nMetron is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"Metron\"\n```\n\n### Carthage\n\nMetron is also available through [Carthage](https://github.com/Carthage/Carthage). To install\nit, simply add the following line to your Cartfile:\n\n```\ngithub \"toineheuvelmans/Metron\"\n```\n\n### Swift Package Manager\n\nMetron can also be used with the [Swift Package Manager](https://swift.org/package-manager/). Add Metron to the `dependencies` value of your `Package.swift`:\n\n```swift\ndependencies: [\n    .Package(url: \"https://github.com/toineheuvelmans/metron.git\", majorVersion: 1)\n]\n```\n\n## Suggestions or feedback?\n\nFeel free to create a pull request, open an issue or find me [on Twitter](https://twitter.com/toineheuvelmans).\n\n## License\n\nMetron is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoineheuvelmans%2FMetron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoineheuvelmans%2FMetron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoineheuvelmans%2FMetron/lists"}