Contents

toineheuvelmans/metron

_Geometry, simplified._

And there's much more...

Extensions

For CGPoint
  • [X] Distance to other CGPoint
  • [X] Clipping to CGRect
  • [X] Relative position in CGRect
  • [X] Normalized position in CGRect
  • [X] Convert to CGVector
  • [X] Round to non-decimal components
  • [X] Addition, subtraction, multiplication...
  • [X] Convex hull for an array of CGPoints (returns a Polygon)
For CGVector
  • [X] Magnitude
  • [X] Angle
  • [X] Convenience initializer with magnitude and angle
  • [X] Convert to CGPoint
  • [X] Inverse
  • [X] Dominant edge
  • [X] Dominant corner
  • [X] Derive line through point
  • [X] Derive line segment from point
  • [X] CGAffineTransform extensions
  • [X] Addition, subtraction, multiplication...
For CGSize
  • [X] Area
  • [X] Swap width and height
  • [X] Clip to other CGSize
  • [X] Scaling using multiplication and division
For CGRect
  • [X] Many convenience initializers, including AspectFit / AspectFill for size
  • [X] Scaling
  • [X] Corner points
  • [X] Edges as line segments
  • [X] Area
  • [X] Center
  • [X] Perimeter
  • [X] CGPath
For CGRectEdge
  • [X] Axis (x or y)
  • [X] Adjacent corners
  • [X] Opposite edge
For CGAffineTransform
  • [X] Create translation transform using CGVector
  • [X] Apply transform with a specified anchor point

New Types

Line
  • [X] Slope
  • [X] Y-intercept
  • [X] X-intercept
  • [X] Horizontal? / vertical? / parallel(to: ...)?
  • [X] Get a perpendicular line
  • [X] Determine intersection with other Line or LineSegment
LineSegment
  • [X] Length
  • [X] Derive a Line
  • [X] Rotate
  • [X] Determine intersection with other Line or LineSegment
  • [X] CGPath
Circle
  • [X] Radius
  • [X] Diameter
  • [X] Circumference
  • [X] Area
  • [X] Center
  • [X] Width / Height
  • [X] Bounding rect
  • [X] Contains point?
  • [X] CGPath
  • [X] Points along the perimeter (divide the circle into steps, rotating in a specific direction...)
Triangle
  • [X] Vertices (as CGPoint)
  • [X] Sides (as LineSegment)
  • [X] Angles (as Angle, see further on)
  • [X] Angle bisectors (as LineSegment)
  • [X] Altitudes (as LineSegment)
  • [X] Equilateral? / isosceles? / scalene? / right? / oblique? / acute? / obtuse?
  • [X] Centroid
  • [X] Circumcenter
  • [X] Incenter
  • [X] Orthocenter
  • [X] Area
  • [X] Bounding rect
  • [X] Contains point?
  • [X] CGPath
Square
  • [X] Edge length
  • [X] Area
  • [X] Perimeter
  • [X] Center
  • [X] CGPath
  • [X] CGRect
Polygon
  • [X] Init with points or with line segments
  • [X] Edge count
  • [X] Self-intersecting?
  • [X] Convex? / concave?
  • [X] Area
  • [X] Perimeter
  • [X] Center
  • [X] Bounding rect
  • [X] Contains point?
  • [X] CGPath
Corner
  • [X] Adjacent edges (CGRectEdges)
  • [X] Opposite corner
Angle
  • [X] Init with radians or degrees
  • [X] Convert unit
  • [X] Normalize
  • [X] Invert
  • [X] Compare
  • [X] Addition, subtraction, multiplication...
  • [X] Basic trigonometric functions also accept Angle
  • [X] Create rotation CGAffineTransform with Angle

Installation

CocoaPods

Metron is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Metron"

Carthage

Metron is also available through Carthage. To install it, simply add the following line to your Cartfile:

github "toineheuvelmans/Metron"

Swift Package Manager

Metron can also be used with the Swift Package Manager. Add Metron to the dependencies value of your Package.swift:

dependencies: [
    .Package(url: "https://github.com/toineheuvelmans/metron.git", majorVersion: 1)
]

Suggestions or feedback?

Feel free to create a pull request, open an issue or find me on Twitter.

License

Metron is available under the MIT license. See the LICENSE file for more info.

Package Metadata

Repository: toineheuvelmans/metron

Default branch: master

README: README.md