Skip to content

Commit 668aca8

Browse files
author
Oleksandr Glagoliev
committed
Add Demo. Refactor package
1 parent 7473e3f commit 668aca8

File tree

17 files changed

+1048
-30
lines changed

17 files changed

+1048
-30
lines changed

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 442 additions & 0 deletions
Large diffs are not rendered by default.

Demo/Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Demo/Demo/AppDelegate.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// AppDelegate.swift
3+
// Demo
4+
//
5+
// Created by Oleksandr Glagoliev on 3/4/20.
6+
// Copyright © 2020 Oleksandr Glagoliev. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
@UIApplicationMain
12+
class AppDelegate: UIResponder, UIApplicationDelegate {
13+
14+
var window: UIWindow?
15+
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
17+
window = UIWindow(frame: UIScreen.main.bounds)
18+
window?.rootViewController = ViewController()
19+
window?.makeKeyAndVisible()
20+
return true
21+
}
22+
23+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "29x29",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "29x29",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "40x40",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "40x40",
31+
"scale" : "3x"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"size" : "60x60",
36+
"scale" : "2x"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"size" : "60x60",
41+
"scale" : "3x"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"size" : "20x20",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"size" : "20x20",
51+
"scale" : "2x"
52+
},
53+
{
54+
"idiom" : "ipad",
55+
"size" : "29x29",
56+
"scale" : "1x"
57+
},
58+
{
59+
"idiom" : "ipad",
60+
"size" : "29x29",
61+
"scale" : "2x"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"size" : "40x40",
66+
"scale" : "1x"
67+
},
68+
{
69+
"idiom" : "ipad",
70+
"size" : "40x40",
71+
"scale" : "2x"
72+
},
73+
{
74+
"idiom" : "ipad",
75+
"size" : "76x76",
76+
"scale" : "1x"
77+
},
78+
{
79+
"idiom" : "ipad",
80+
"size" : "76x76",
81+
"scale" : "2x"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"size" : "83.5x83.5",
86+
"scale" : "2x"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"size" : "1024x1024",
91+
"scale" : "1x"
92+
}
93+
],
94+
"info" : {
95+
"version" : 1,
96+
"author" : "xcode"
97+
}
98+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="EHf-IW-A2E">
11+
<objects>
12+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
13+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
14+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
15+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16+
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
17+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
18+
</view>
19+
</viewController>
20+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
21+
</objects>
22+
<point key="canvasLocation" x="53" y="375"/>
23+
</scene>
24+
</scenes>
25+
</document>

Demo/Demo/CGContext+Helpers.swift

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import UIKit
2+
3+
extension CGContext {
4+
public func drawCircle(
5+
origin: CGPoint,
6+
radius: CGFloat,
7+
strokeColor: UIColor = .black,
8+
strokeWidth: CGFloat = 1.0,
9+
fillColor: UIColor = .white,
10+
startAngle: CGFloat = 0,
11+
endAngle: CGFloat = .pi * 2) {
12+
13+
let circle = UIBezierPath(
14+
arcCenter: origin,
15+
radius: radius,
16+
startAngle: startAngle,
17+
endAngle: endAngle,
18+
clockwise: true
19+
)
20+
21+
saveGState()
22+
fillColor.setFill()
23+
setLineWidth(strokeWidth)
24+
strokeColor.setStroke()
25+
addPath(circle.cgPath)
26+
drawPath(using: CGPathDrawingMode.fillStroke)
27+
restoreGState()
28+
}
29+
30+
public func drawSegment(
31+
from: CGPoint,
32+
to: CGPoint,
33+
strokeColor: UIColor = .black,
34+
strokeWidth: CGFloat = 1.0) {
35+
36+
saveGState()
37+
setLineWidth(strokeWidth)
38+
strokeColor.setStroke()
39+
move(to: from)
40+
addLine(to: to)
41+
strokePath()
42+
restoreGState()
43+
}
44+
45+
46+
public func drawPolygonFromCCWPoints(_ points: [Site], color: UIColor) {
47+
guard points.count > 1 else { return }
48+
saveGState()
49+
setFillColor(color.cgColor)
50+
move(to: points[0].cgPoint)
51+
for i in (0..<points.count) {
52+
addLine(to: points[i].cgPoint)
53+
}
54+
closePath()
55+
fillPath()
56+
restoreGState()
57+
}
58+
59+
60+
public func drawQuadBezier(
61+
from: CGPoint,
62+
to: CGPoint,
63+
cp: CGPoint,
64+
strokeColor: UIColor = .black,
65+
strokeWidth: CGFloat = 1.0
66+
) {
67+
saveGState()
68+
setLineWidth(strokeWidth)
69+
setLineJoin(.bevel)
70+
setLineCap(.round)
71+
strokeColor.setStroke()
72+
move(to: from)
73+
addQuadCurve(to: to, control: cp)
74+
strokePath()
75+
restoreGState()
76+
}
77+
78+
public func drawLine(
79+
from: CGPoint,
80+
to: CGPoint,
81+
color: UIColor = .lightGray,
82+
lineWidth: CGFloat = 1.0
83+
) {
84+
saveGState()
85+
setLineWidth(lineWidth)
86+
color.setStroke()
87+
move(to: from)
88+
addLine(to: to)
89+
strokePath()
90+
restoreGState()
91+
}
92+
93+
public func drawCross(
94+
_ point: Site,
95+
size: CGFloat,
96+
strokeWidth: CGFloat = 1.0,
97+
strokeColor: UIColor = .black
98+
) {
99+
let p = point.cgPoint
100+
let tl = CGPoint(x: p.x - size, y: p.y - size)
101+
let bl = CGPoint(x: p.x - size, y: p.y + size)
102+
let br = CGPoint(x: p.x + size, y: p.y + size)
103+
let tr = CGPoint(x: p.x + size, y: p.y - size)
104+
drawLine(from: tl, to: br, color: strokeColor, lineWidth: strokeWidth)
105+
drawLine(from: bl, to: tr, color: strokeColor, lineWidth: strokeWidth)
106+
}
107+
}

Demo/Demo/CGContext+Voronoi.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import UIKit
2+
3+
extension CGPoint {
4+
public var point: Site {
5+
Site(x: Double(x), y: Double(y))
6+
}
7+
}
8+
9+
extension Site {
10+
public var cgPoint: CGPoint {
11+
CGPoint(x: x, y: y)
12+
}
13+
}
14+
15+
extension CGContext {
16+
public func drawSite(_ site: Site, visited: Bool) {
17+
drawCircle(
18+
origin: site.cgPoint,
19+
radius: 2.0,
20+
strokeColor: .black,
21+
fillColor: visited
22+
? .visitedSite
23+
: .notVisitedSite
24+
)
25+
}
26+
27+
public func drawBreakpoint(_ point: Site) {
28+
drawCross(point, size: 4.0)
29+
}
30+
31+
public func drawUpcomingCircleEvent(_ point: Site) {
32+
drawCross(point, size: 4.0, strokeColor: .circleEventPoint)
33+
}
34+
35+
public func drawArc(_ arc: (start: Site, cp: Site, end: Site)) {
36+
drawQuadBezier(
37+
from: arc.start.cgPoint,
38+
to: arc.end.cgPoint,
39+
cp: arc.cp.cgPoint,
40+
strokeColor: .lightGray,
41+
strokeWidth: 2
42+
)
43+
}
44+
45+
public func drawVertex(_ point: Site) {
46+
drawCircle(
47+
origin: point.cgPoint,
48+
radius: 2.0,
49+
strokeColor: .clear,
50+
fillColor: .black
51+
)
52+
}
53+
54+
55+
56+
}
57+

Demo/Demo/Demo.entitlements

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.network.client</key>
8+
<true/>
9+
</dict>
10+
</plist>

0 commit comments

Comments
 (0)