Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Neumerzhitckii committed Jun 22, 2015
1 parent 9ab52f1 commit e15289f
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 107 deletions.
16 changes: 8 additions & 8 deletions Cosmos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
2B622ED91B37BB700090D81B /* CosmosSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622ECF1B37BB700090D81B /* CosmosSettings.swift */; };
2B622EDA1B37BB700090D81B /* CosmosDefaultSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622ED01B37BB700090D81B /* CosmosDefaultSettings.swift */; };
2B622EDB1B37BB700090D81B /* CosmosSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622ED11B37BB700090D81B /* CosmosSize.swift */; };
2B622EDC1B37BB700090D81B /* StarTouch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622ED21B37BB700090D81B /* StarTouch.swift */; };
2B622EDC1B37BB700090D81B /* CosmosTouch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622ED21B37BB700090D81B /* CosmosTouch.swift */; };
2B622EDF1B37BB850090D81B /* CosmosTouchTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622EDE1B37BB850090D81B /* CosmosTouchTarget.swift */; };
2B622EE31B37BBC20090D81B /* CosmosTouchTargetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622EE21B37BBC20090D81B /* CosmosTouchTargetTests.swift */; };
2B622EE51B37BBC60090D81B /* Round.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622EE41B37BBC60090D81B /* Round.swift */; };
2B622EE91B37BBD10090D81B /* CosmosViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622EE61B37BBD10090D81B /* CosmosViewTests.swift */; };
2B622EEA1B37BBD10090D81B /* CosmosLayersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622EE71B37BBD10090D81B /* CosmosLayersTests.swift */; };
2B622EEB1B37BBD10090D81B /* StarTouchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622EE81B37BBD10090D81B /* StarTouchTests.swift */; };
2B622EEB1B37BBD10090D81B /* CosmosTouchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622EE81B37BBD10090D81B /* CosmosTouchTests.swift */; };
2B622EF31B37BC120090D81B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B622EF21B37BC120090D81B /* AppDelegate.swift */; };
2B622EF81B37BC120090D81B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2B622EF61B37BC120090D81B /* Main.storyboard */; };
2B622EFA1B37BC120090D81B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2B622EF91B37BC120090D81B /* Assets.xcassets */; };
Expand Down Expand Up @@ -81,13 +81,13 @@
2B622ECF1B37BB700090D81B /* CosmosSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosSettings.swift; sourceTree = "<group>"; };
2B622ED01B37BB700090D81B /* CosmosDefaultSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosDefaultSettings.swift; sourceTree = "<group>"; };
2B622ED11B37BB700090D81B /* CosmosSize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosSize.swift; sourceTree = "<group>"; };
2B622ED21B37BB700090D81B /* StarTouch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarTouch.swift; sourceTree = "<group>"; };
2B622ED21B37BB700090D81B /* CosmosTouch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosTouch.swift; sourceTree = "<group>"; };
2B622EDE1B37BB850090D81B /* CosmosTouchTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosTouchTarget.swift; sourceTree = "<group>"; };
2B622EE21B37BBC20090D81B /* CosmosTouchTargetTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosTouchTargetTests.swift; sourceTree = "<group>"; };
2B622EE41B37BBC60090D81B /* Round.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Round.swift; sourceTree = "<group>"; };
2B622EE61B37BBD10090D81B /* CosmosViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosViewTests.swift; sourceTree = "<group>"; };
2B622EE71B37BBD10090D81B /* CosmosLayersTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosLayersTests.swift; sourceTree = "<group>"; };
2B622EE81B37BBD10090D81B /* StarTouchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StarTouchTests.swift; sourceTree = "<group>"; };
2B622EE81B37BBD10090D81B /* CosmosTouchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CosmosTouchTests.swift; sourceTree = "<group>"; };
2B622EF01B37BC120090D81B /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
2B622EF21B37BC120090D81B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2B622EF71B37BC120090D81B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -159,7 +159,7 @@
2B622ECF1B37BB700090D81B /* CosmosSettings.swift */,
2B622ED01B37BB700090D81B /* CosmosDefaultSettings.swift */,
2B622ED11B37BB700090D81B /* CosmosSize.swift */,
2B622ED21B37BB700090D81B /* StarTouch.swift */,
2B622ED21B37BB700090D81B /* CosmosTouch.swift */,
2B622EB21B37BAE50090D81B /* Cosmos.h */,
2B622EB41B37BAE50090D81B /* Info.plist */,
);
Expand All @@ -173,7 +173,7 @@
2B622EE11B37BBBA0090D81B /* TestHelpers */,
2B622EE61B37BBD10090D81B /* CosmosViewTests.swift */,
2B622EE71B37BBD10090D81B /* CosmosLayersTests.swift */,
2B622EE81B37BBD10090D81B /* StarTouchTests.swift */,
2B622EE81B37BBD10090D81B /* CosmosTouchTests.swift */,
2B622EC01B37BAE50090D81B /* Info.plist */,
);
path = CosmosTests;
Expand Down Expand Up @@ -395,7 +395,7 @@
2B622ED71B37BB700090D81B /* CosmosText.swift in Sources */,
2B622ED51B37BB700090D81B /* StarFillMode.swift in Sources */,
2B622ED41B37BB700090D81B /* CosmosView.swift in Sources */,
2B622EDC1B37BB700090D81B /* StarTouch.swift in Sources */,
2B622EDC1B37BB700090D81B /* CosmosTouch.swift in Sources */,
2B622EDB1B37BB700090D81B /* CosmosSize.swift in Sources */,
2B622EDA1B37BB700090D81B /* CosmosDefaultSettings.swift in Sources */,
);
Expand All @@ -408,7 +408,7 @@
2B622EE31B37BBC20090D81B /* CosmosTouchTargetTests.swift in Sources */,
2B622EE91B37BBD10090D81B /* CosmosViewTests.swift in Sources */,
2B622EEA1B37BBD10090D81B /* CosmosLayersTests.swift in Sources */,
2B622EEB1B37BBD10090D81B /* StarTouchTests.swift in Sources */,
2B622EEB1B37BBD10090D81B /* CosmosTouchTests.swift in Sources */,
2B622EE51B37BBC60090D81B /* Round.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion Cosmos/StarTouch.swift → Cosmos/CosmosTouch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import UIKit
Functions for working with touch input.

*/
struct StarTouch {
struct CosmosTouch {
/**

Calculates the rating based on the touch location.
Expand Down
2 changes: 1 addition & 1 deletion Cosmos/CosmosView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Shows: ★★★★☆ (132)

*/
func onDidTouch(locationX: CGFloat, starsWidth: CGFloat) {
let calculatedTouchRating = StarTouch.touchRating(locationX, starsWidth: starsWidth,
let calculatedTouchRating = CosmosTouch.touchRating(locationX, starsWidth: starsWidth,
settings: settings)

if settings.updateOnTouch {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import XCTest
@testable import Cosmos

class StarTouchTests: XCTestCase {
class CosmosTouchTests: XCTestCase {
// MARK: - Touch rating

func testTouchRating_full() {
var settings = CosmosSettings()
settings.fillMode = .Full
settings.minTouchRating = 0
let result = StarTouch.touchRating(200, starsWidth: 500, settings: settings)
let result = CosmosTouch.touchRating(200, starsWidth: 500, settings: settings)
XCTAssertEqual(2, result)
}

Expand All @@ -19,7 +19,7 @@ class StarTouchTests: XCTestCase {
settings.totalStars = 500
settings.minTouchRating = 0

let result = StarTouch.touchRating(200, starsWidth: 500, settings: settings)
let result = CosmosTouch.touchRating(200, starsWidth: 500, settings: settings)
XCTAssertEqual(200, result)
}

Expand All @@ -29,7 +29,7 @@ class StarTouchTests: XCTestCase {
settings.fillMode = .Full
settings.minTouchRating = 0

let result = StarTouch.touchRating(600, starsWidth: 500, settings: settings)
let result = CosmosTouch.touchRating(600, starsWidth: 500, settings: settings)
XCTAssertEqual(5, result)
}

Expand All @@ -39,7 +39,7 @@ class StarTouchTests: XCTestCase {
settings.fillMode = .Full
settings.minTouchRating = 0

let result = StarTouch.touchRating(-100, starsWidth: 500, settings: settings)
let result = CosmosTouch.touchRating(-100, starsWidth: 500, settings: settings)
XCTAssertEqual(0, result)
}

Expand All @@ -49,7 +49,7 @@ class StarTouchTests: XCTestCase {
settings.fillMode = .Half
settings.minTouchRating = 0

let result = StarTouch.touchRating(200, starsWidth: 500, settings: settings)
let result = CosmosTouch.touchRating(200, starsWidth: 500, settings: settings)
XCTAssertEqual(2.5, result)
}

Expand All @@ -59,7 +59,7 @@ class StarTouchTests: XCTestCase {
settings.fillMode = .Precise
settings.minTouchRating = 0

let result = StarTouch.touchRating(215, starsWidth: 500, settings: settings)
let result = CosmosTouch.touchRating(215, starsWidth: 500, settings: settings)
XCTAssertEqual(2.15, result)
}

Expand All @@ -69,7 +69,7 @@ class StarTouchTests: XCTestCase {
settings.fillMode = .Precise
settings.minTouchRating = 1.1

let result = StarTouch.touchRating(0, starsWidth: 500, settings: settings)
let result = CosmosTouch.touchRating(0, starsWidth: 500, settings: settings)
XCTAssertEqual(1.1, result)
}
}
178 changes: 89 additions & 89 deletions Distrib/CosmosDistrib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,43 @@ public struct CosmosSettings {
}


// ----------------------------
//
// CosmosSize.swift
//
// ----------------------------

import UIKit

/**

Helper class for calculating size for the cosmos view.

*/
class CosmosSize {
/**

Calculates the size of the cosmos view. It goes through all the star and text layers and makes size the view size is large enough to show all of them.

*/
class func calculateSizeToFitLayers(layers: [CALayer]) -> CGSize {
var size = CGSize()

for layer in layers {
if layer.frame.maxX > size.width {
size.width = layer.frame.maxX
}

if layer.frame.maxY > size.height {
size.height = layer.frame.maxY
}
}

return size
}
}


// ----------------------------
//
// CosmosText.swift
Expand Down Expand Up @@ -455,6 +492,57 @@ class CosmosText {
}


// ----------------------------
//
// CosmosTouch.swift
//
// ----------------------------

import UIKit

/**

Functions for working with touch input.

*/
struct CosmosTouch {
/**

Calculates the rating based on the touch location.

- parameter locationX: The horizontal location of the touch relative to the width of the stars.

- parameter starsWidth: The width of the stars excluding the text.

- returns: The rating representing the touch location.

*/
static func touchRating(locationX: CGFloat, starsWidth: CGFloat, settings: CosmosSettings) -> Double {

let position = locationX / starsWidth
let totalStars = Double(settings.totalStars)
let actualRating = totalStars * Double(position)
var correctedRating = actualRating

if settings.fillMode != .Precise {
correctedRating += 0.25
}

let starFloorNumber = floor(correctedRating)
let singleStarRemainder = correctedRating - starFloorNumber

correctedRating = starFloorNumber + CosmosLayers.starFillLevel(
ratingRemainder: singleStarRemainder, fillMode: settings.fillMode)

correctedRating = min(totalStars, correctedRating) // Can't go bigger than number of stars
correctedRating = max(0, correctedRating) // Can't be less than zero
correctedRating = max(settings.minTouchRating, correctedRating) // Can't be less than min rating

return correctedRating
}
}


// ----------------------------
//
// CosmosView.swift
Expand Down Expand Up @@ -669,7 +757,7 @@ Shows: ★★★★☆ (132)

*/
func onDidTouch(locationX: CGFloat, starsWidth: CGFloat) {
let calculatedTouchRating = StarTouch.touchRating(locationX, starsWidth: starsWidth,
let calculatedTouchRating = CosmosTouch.touchRating(locationX, starsWidth: starsWidth,
settings: settings)

if settings.updateOnTouch {
Expand Down Expand Up @@ -908,91 +996,3 @@ struct StarLayer {
}


// ----------------------------
//
// CosmosSize.swift
//
// ----------------------------

import UIKit

/**

Helper class for calculating size for the cosmos view.

*/
class CosmosSize {
/**

Calculates the size of the cosmos view. It goes through all the star and text layers and makes size the view size is large enough to show all of them.

*/
class func calculateSizeToFitLayers(layers: [CALayer]) -> CGSize {
var size = CGSize()

for layer in layers {
if layer.frame.maxX > size.width {
size.width = layer.frame.maxX
}

if layer.frame.maxY > size.height {
size.height = layer.frame.maxY
}
}

return size
}
}


// ----------------------------
//
// StarTouch.swift
//
// ----------------------------

import UIKit

/**

Functions for working with touch input.

*/
struct StarTouch {
/**

Calculates the rating based on the touch location.

- parameter locationX: The horizontal location of the touch relative to the width of the stars.

- parameter starsWidth: The width of the stars excluding the text.

- returns: The rating representing the touch location.

*/
static func touchRating(locationX: CGFloat, starsWidth: CGFloat, settings: CosmosSettings) -> Double {

let position = locationX / starsWidth
let totalStars = Double(settings.totalStars)
let actualRating = totalStars * Double(position)
var correctedRating = actualRating

if settings.fillMode != .Precise {
correctedRating += 0.25
}

let starFloorNumber = floor(correctedRating)
let singleStarRemainder = correctedRating - starFloorNumber

correctedRating = starFloorNumber + CosmosLayers.starFillLevel(
ratingRemainder: singleStarRemainder, fillMode: settings.fillMode)

correctedRating = min(totalStars, correctedRating) // Can't go bigger than number of stars
correctedRating = max(0, correctedRating) // Can't be less than zero
correctedRating = max(settings.minTouchRating, correctedRating) // Can't be less than min rating

return correctedRating
}
}


0 comments on commit e15289f

Please sign in to comment.