Skip to content

Commit 0ba317b

Browse files
committed
Update README, podspec
1 parent 2f8d3d0 commit 0ba317b

File tree

2 files changed

+79
-19
lines changed

2 files changed

+79
-19
lines changed

README.md

+68-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,87 @@
11
# VectorKit
22

3-
[![CI Status](http://img.shields.io/travis/David Lee/VectorKit.svg?style=flat)](https://travis-ci.org/David Lee/VectorKit)
4-
[![Version](https://img.shields.io/cocoapods/v/VectorKit.svg?style=flat)](http://cocoapods.org/pods/VectorKit)
5-
[![License](https://img.shields.io/cocoapods/l/VectorKit.svg?style=flat)](http://cocoapods.org/pods/VectorKit)
6-
[![Platform](https://img.shields.io/cocoapods/p/VectorKit.svg?style=flat)](http://cocoapods.org/pods/VectorKit)
3+
[![CI Status](http://img.shields.io/travis/David Lee/Vector.svg?style=flat)](https://travis-ci.org/David Lee/Vector)
4+
[![Version](https://img.shields.io/cocoapods/v/Vector.svg?style=flat)](http://cocoapods.org/pods/Vector)
5+
[![License](https://img.shields.io/cocoapods/l/Vector.svg?style=flat)](http://cocoapods.org/pods/Vector)
6+
[![Platform](https://img.shields.io/cocoapods/p/Vector.svg?style=flat)](http://cocoapods.org/pods/Vector)
77

88
## Usage
99

10-
To run the example project, clone the repo, and run `pod install` from the Example directory first.
10+
VectorKit provides a `Vector` protocol which can give any type the power to perform vector operations.
1111

12-
## Requirements
12+
Here is a `CGPoint` extension, adopting the `Vector` protocol.
13+
14+
```swift
15+
extension CGPoint: Vector {
16+
// We need to specify the number of dimensions, so that the vector operations can be configured to fit the dimension.
17+
public var numberOfDimensions: Int { return 2 }
18+
19+
// Every `Vector` can be initialized from a collection. This allows easy conversion among similar vector types.
20+
public init<T where T: CollectionType, T.Generator.Element == CGFloat>(collection: T) {
21+
var g = collection.generate()
22+
guard let x = g.next(), let y = g.next() else {
23+
fatalError()
24+
}
25+
self.init(x: x, y: y)
26+
}
27+
28+
// `Vector` inherits from `CollectionType`, and internally leverages `CollectionType`'s methods for support
29+
// for multi-dimensional vectors.
30+
public subscript(index: Int) -> CGFloat {
31+
switch index {
32+
case 0:
33+
return x
34+
case 1:
35+
return y
36+
default:
37+
fatalError()
38+
}
39+
}
40+
}
41+
```
42+
43+
Once we define this adoption, we can use all of `Vector`'s operations within `CGPoint`.
44+
45+
```swift
46+
let pt1 = CGPoint(x: 3, y: 4)
47+
let pt2 = CGPoint(collection: [1, -2])
48+
49+
pt1.magnitude == 5
50+
pt1 + pt2 == CGPoint(x: 4, y: 2)
51+
pt2 * 0.5 == CGPoint(x: 0.5, y: -1)
52+
-pt1 == CGPoint(x: -4, y: -2)
53+
```
54+
55+
`Vector` also supports a handful of operations which can combine different kinds of `Vector`s. In the following example, both `CGPoint` and `CGSize` have adopted `Vector`.
56+
57+
```swift
58+
let point = CGPoint(x: 1, y: -1)
59+
let size = CGSize(width: 5, height: 10)
60+
61+
let pointDifference: CGPoint = point - size
62+
let sizeDifference: CGSize = point - size
63+
64+
pointDifference == CGPoint(x: -4, y: -11)
65+
sizeDifference == CGSize(width: -4, height: -11)
66+
```
67+
68+
## Running the tests
69+
70+
To run the tests included in the example project, clone the repo, and run `pod install` from the Example directory first.
1371

1472
## Installation
1573

16-
VectorKit is available through [CocoaPods](http://cocoapods.org). To install
74+
Vector is available through [CocoaPods](http://cocoapods.org). To install
1775
it, simply add the following line to your Podfile:
1876

1977
```ruby
20-
pod "VectorKit"
78+
pod "VectorKit", :git => "https://github.com/davidisaaclee/VectorKit.git"
2179
```
2280

2381
## Author
2482

25-
David Lee, aewofij@gmail.com
83+
David Lee, http://david-lee.net
2684

2785
## License
2886

29-
VectorKit is available under the MIT license. See the LICENSE file for more info.
87+
Vector is available under the MIT license. See the LICENSE file for more info.

VectorKit.podspec

+11-9
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@
77
#
88

99
Pod::Spec.new do |s|
10-
s.name = "VectorKit"
11-
s.version = "0.1.0"
12-
s.summary = "A short description of VectorKit."
10+
s.name = "VectorKit"
11+
s.version = "0.1.0"
12+
s.summary = "Powerful vector operations for the types you're already using."
1313

1414
# This description is used to generate tags and improve search results.
1515
# * Think: What does it do? Why did you write it? What is the focus?
1616
# * Try to keep it short, snappy and to the point.
1717
# * Write the description between the DESC delimiters below.
1818
# * Finally, don't worry about the indent, CocoaPods strips it!
1919
s.description = <<-DESC
20+
VectorKit gives you powerful vector operations for the types you're already using, by providing a Vector
21+
protocol which can give any type the power to perform vector operations.
2022
DESC
2123

22-
s.homepage = "https://github.com/<GITHUB_USERNAME>/VectorKit"
23-
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
24-
s.license = 'MIT'
25-
s.author = { "David Lee" => "aewofij@gmail.com" }
26-
s.source = { :git => "https://github.com/<GITHUB_USERNAME>/VectorKit.git", :tag => s.version.to_s }
27-
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
24+
s.homepage = "https://github.com/davidisaaclee/VectorKit"
25+
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
26+
s.license = 'MIT'
27+
s.author = { "David Lee" => "david.isaac.lee@gmail.com" }
28+
s.source = { :git => "https://github.com/davidisaaclee/VectorKit.git", :tag => s.version.to_s }
29+
# s.social_media_url = 'https://twitter.com/davidisaaclee'
2830

2931
s.platform = :ios, '8.0'
3032
s.requires_arc = true

0 commit comments

Comments
 (0)