Latest | 0.1.0 |
---|---|

Homepage | https://github.com/nkopilovskii/NKAdditionalGeometry |

License | MIT |

Platforms | ios 10.0 |

Authors |

## Description

The library is represented by a set of protocols and extensions of the CoreGraphics framework, which automate some geometric calculations.

## Interface

All the protocols described have a realization in extensions of the corresponding types

### Protocol `NKPoint`

```
/**
Transformation of a point from one coordinate system to another
- Parameters:
- initial: `CGRect` of coordinate system which contains current `CGPoint` instance
- destination: `CGRect` of coordinate system in which needs to get point corresponding to the current `CGPoint` instance
- Returns: `CGPoint` in `destinationRect` coordinate system corresponding to current instance in `initialRect` coordinate system
*/
func similar(from initial: CGRect, in destination: CGRect) -> CGPoint
/**
- Parameters:
- point: `CGPoint` to which needs to calculate difference in values of the corresponding coordinates
- Returns: `CGVector` difference in values of the corresponding coordinates
*/
func diffence(with point: CGPoint) -> CGVector
/**
- Parameters:
- difference: `CGVector` difference in values of the corresponding coordinates between two points
- Returns: `CGPoint` by adding difference in values of the corresponding coordinates to current instance
*/
func point(byAdding difference: CGVector) -> CGPoint
/**
- Parameters:
- point: `CGPoint` to which needs to calculate the distance
- Returns: `CGFloat` distance between current instance and `point`
*/
func distance(to point: CGPoint) -> CGFloat
/**
- Parameters:
- p1: `CGPoint` to which needs to calculate the distance
- p2: `CGPoint` to which needs to calculate the distance
- Returns: `CGFloat` angle between segments `instance-p1` and `instance-p2`
*/
func angle(with p1: CGPoint, _ p2: CGPoint) -> CGFloat
/**
The method calculates equidistant points from the instance with an equal radial pitch between them.
In other words, the method divides the circle into equal segments
- Parameters:
- count: `Int` count of devide points
- radius: `CGFloat` remoteness of computed points from the instance
- Returns: `[CGPoint]` array of equidistant points from the instance with an equal radial pitch between them
*/
func devidePoints(count: Int, for radius: CGFloat) -> [CGPoint]
/**
The method calculates `CGPoint` at a given distance with the angle of deviation from the axis Ox
- Parameters:
- count: `Int` count of devide points
- angle: `CGFloat` angle based on instance
- Returns: `[CGPoint]` array of equidistant points from the instance with an equal radial pitch between them
*/
func point(on distance: CGFloat, with angle: CGFloat) -> CGPoint
```

### Protocol `NKVector`

```
/**
Module (length) of the vector
*/
var length: CGFloat { get }
```

### Protocol `NKSize`

```
/**
The method calculates the maximum size that can be accommodated in the given, with the remaining aspect ratio of the instance
- Parameters:
- size: `CGSize` in which it is necessary to place a new size
- Returns: `CGSize` that can be accommodated in the `size`
*/
func scaleToMax(in size: CGSize) -> CGSize
/**
Еhe method calculates the size corresponding to the instance, observing the ratios of the corresponding parameter given sizes
- Parameters:
- initial: `CGSize` in the coordinate system of which there is instance
- destination: `CGSize` in the coordinate system of which needs to transfer the current object
- Returns: `CGSize` corresponding to the instance, observing the ratios of the corresponding parameter given sizes
*/
func similar(from initial: CGSize, to destination: CGSize) -> CGSize
```

### Protocol `NKRect`

```
/// Center of the rectangle in the parent system
var center: CGPoint { set get }
/// Square of the maximum size in the center of instance
var centralSquare: CGRect { get }
/// Radius of a circle inscribed in instance
var incircleRadius: CGFloat { get }
/// Radius of a circle circumscribed around instance
var circumcircleRadius: CGFloat { get }
/**
Transformation of a rect from one coordinate system to another
- Parameters:
- initial: `CGRect` of coordinate system which contains current `CGRect` instance
- destination: `CGRect` of coordinate system in which needs to get rect corresponding to the current `CGRect` instance
- Returns: `CGRect` in `destination` coordinate system corresponding to current instance in `initial` coordinate system
*/
func similar(from initial: CGRect, to destination: CGRect) -> CGRect
/**
Create a new rectangle by scaling the current instance's `size`
- Parameters:
- value: `CGFloat` scale factor
- Returns: `CGRect` with instance's `origin` and instance's scaled `size`
*/
func scaled(with value: CGFloat) -> CGRect
/**
Create a new rectangle by resizing the current instance's `size`
- Parameters:
- value: `CGFloat` value for increase instance's `size`
- Returns: `CGRect` with instance's `origin` and instance's resized `size`
*/
func changedSize(with value: CGFloat) -> CGRect
/**
The method calculates points at incircle radius distance from the instance's center with an equal radial pitch between them.
In other words, the method divides the circle inscribed in the instance into equal segments
- Parameters:
- count: `Int` count of devide points
- Returns: `[CGPoint]` array of equidistant points from the instance's center with an equal radial pitch between them
*/
func incircleDevidePoints(_ count: Int) -> [CGPoint]
/**
The method calculates divide point at a given position in array of divide points of the circle inscribed in instance
- Parameters:
- index: `Int` number of divide point
- count: `Int` count of devide points
- Returns: `CGPoint` divide point at position `index` in array of divide points with size `count`
*/
func incircleDevidePoint(for index: Int, in count: Int) -> CGPoint
/**
The method calculates points at circumcircle radius distance from the instance's center with an equal radial pitch between them.
In other words, the method divides the circle circumscribed around the instance into equal segments
- Parameters:
- count: `Int` count of devide points
- Returns: `[CGPoint]` array of equidistant points from the instance's center with an equal radial pitch between them
*/
func circumcircleDevidePoints(_ count: Int) -> [CGPoint]
/**
The method calculates divide point at a given position in array of divide points of the circle circumscribed around instance
- Parameters:
- index: `Int` number of divide point
- count: `Int` count of devide points
- Returns: `CGPoint` divide point at position `index` in array of divide points with size `count`
*/
func circumcircleDevidePoint(for index: Int, in count: Int) -> CGPoint
```

## Visual representation

*Similar point*

*Similar point*

*Distance and difference between points*

*Distance and difference between points*

*Divide points, angle*

*Divide points, angle*

*Center, central square*

*Center, central square*

*Incircle and circumcircle radiuses*

*Incircle and circumcircle radiuses*

*Similar frame*

*Similar frame*

## Installation

NKAdditionalGeometry is available through CocoaPods. To install

it, simply add the following line to your Podfile:

`pod 'NKAdditionalGeometry'`

## Requirements

iOS 10.0

Xcode 9

Swift 4.0

## Author

nkopilovskii, [email protected]

## License

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

### Latest podspec

{ "name": "NKAdditionalGeometry", "version": "0.1.0", "summary": "Extensions for CoreGraphics types", "description": "The library is represented by a set of protocols and extensions of the CoreGraphics framework, which automate some geometric calculations.", "homepage": "https://github.com/nkopilovskii/NKAdditionalGeometry", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "nkopilovskii": "[email protected]" }, "source": { "git": "https://github.com/nkopilovskii/NKAdditionalGeometry.git", "tag": "0.1.0" }, "social_media_url": "https://twitter.com/mkopilovskii", "platforms": { "ios": "10.0" }, "swift_version": "4.2", "source_files": "NKAdditionalGeometry/Classes/**/*.swift" }

Wed, 03 Oct 2018 13:00:17 +0000