Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ script:
- xcodebuild test -project ./Bucket\ Sort/Tests/Tests.xcodeproj -scheme Tests
- xcodebuild test -project ./B-Tree/Tests/Tests.xcodeproj -scheme Tests
- xcodebuild test -project ./Comb\ Sort/Tests/Tests.xcodeproj -scheme Tests
- xcodebuild test -project ./Convex\ Hull/Convex\ Hull.xcodeproj -scheme Tests -destination 'platform=iOS Simulator,name=iPhone 7,OS=11.0'
- xcodebuild test -project ./Counting\ Sort/Tests/Tests.xcodeproj -scheme Tests
- xcodebuild test -project ./Depth-First\ Search/Tests/Tests.xcodeproj -scheme Tests
- xcodebuild test -project ./Graph/Graph.xcodeproj -scheme GraphTests
Expand Down
146 changes: 145 additions & 1 deletion Convex Hull/Convex Hull.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@
objects = {

/* Begin PBXBuildFile section */
1CB614301F89456C00A14493 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CB6142F1F89456C00A14493 /* Tests.swift */; };
1CB614371F8945B300A14493 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E6D68CB1E599CF100161780 /* View.swift */; };
8E6D68BA1E59989400161780 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E6D68B91E59989400161780 /* AppDelegate.swift */; };
8E6D68C11E59989400161780 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8E6D68C01E59989400161780 /* Assets.xcassets */; };
8E6D68C41E59989400161780 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8E6D68C21E59989400161780 /* LaunchScreen.storyboard */; };
8E6D68CC1E599CF100161780 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E6D68CB1E599CF100161780 /* View.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
1CB614321F89456C00A14493 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 8E6D68AE1E59989400161780 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 8E6D68B51E59989400161780;
remoteInfo = "Convex Hull";
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1CB6142D1F89456C00A14493 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
1CB6142F1F89456C00A14493 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
1CB614311F89456C00A14493 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8E6D68B61E59989400161780 /* Convex Hull.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Convex Hull.app"; sourceTree = BUILT_PRODUCTS_DIR; };
8E6D68B91E59989400161780 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
8E6D68C01E59989400161780 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand All @@ -23,6 +38,13 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
1CB6142A1F89456C00A14493 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
8E6D68B31E59989400161780 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -33,10 +55,20 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
1CB6142E1F89456C00A14493 /* Tests */ = {
isa = PBXGroup;
children = (
1CB6142F1F89456C00A14493 /* Tests.swift */,
1CB614311F89456C00A14493 /* Info.plist */,
);
path = Tests;
sourceTree = "<group>";
};
8E6D68AD1E59989400161780 = {
isa = PBXGroup;
children = (
8E6D68B81E59989400161780 /* Convex Hull */,
1CB6142E1F89456C00A14493 /* Tests */,
8E6D68B71E59989400161780 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -45,6 +77,7 @@
isa = PBXGroup;
children = (
8E6D68B61E59989400161780 /* Convex Hull.app */,
1CB6142D1F89456C00A14493 /* Tests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -64,6 +97,24 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
1CB6142C1F89456C00A14493 /* Tests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1CB614341F89456C00A14493 /* Build configuration list for PBXNativeTarget "Tests" */;
buildPhases = (
1CB614291F89456C00A14493 /* Sources */,
1CB6142A1F89456C00A14493 /* Frameworks */,
1CB6142B1F89456C00A14493 /* Resources */,
);
buildRules = (
);
dependencies = (
1CB614331F89456C00A14493 /* PBXTargetDependency */,
);
name = Tests;
productName = Tests;
productReference = 1CB6142D1F89456C00A14493 /* Tests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
8E6D68B51E59989400161780 /* Convex Hull */ = {
isa = PBXNativeTarget;
buildConfigurationList = 8E6D68C81E59989400161780 /* Build configuration list for PBXNativeTarget "Convex Hull" */;
Expand All @@ -87,10 +138,15 @@
8E6D68AE1E59989400161780 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastSwiftUpdateCheck = 0900;
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = Workmoose;
TargetAttributes = {
1CB6142C1F89456C00A14493 = {
CreatedOnToolsVersion = 9.0;
ProvisioningStyle = Automatic;
TestTargetID = 8E6D68B51E59989400161780;
};
8E6D68B51E59989400161780 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = 7C4LVS3ZVC;
Expand All @@ -112,11 +168,19 @@
projectRoot = "";
targets = (
8E6D68B51E59989400161780 /* Convex Hull */,
1CB6142C1F89456C00A14493 /* Tests */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
1CB6142B1F89456C00A14493 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
8E6D68B41E59989400161780 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -129,6 +193,15 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
1CB614291F89456C00A14493 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1CB614371F8945B300A14493 /* View.swift in Sources */,
1CB614301F89456C00A14493 /* Tests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
8E6D68B21E59989400161780 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -140,6 +213,14 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
1CB614331F89456C00A14493 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 8E6D68B51E59989400161780 /* Convex Hull */;
targetProxy = 1CB614321F89456C00A14493 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
8E6D68C21E59989400161780 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
Expand All @@ -152,6 +233,60 @@
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
1CB614351F89456C00A14493 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mnespor.Tests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Convex Hull.app/Convex Hull";
};
name = Debug;
};
1CB614361F89456C00A14493 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mnespor.Tests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Convex Hull.app/Convex Hull";
};
name = Release;
};
8E6D68C61E59989400161780 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -274,6 +409,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
1CB614341F89456C00A14493 /* Build configuration list for PBXNativeTarget "Tests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1CB614351F89456C00A14493 /* Debug */,
1CB614361F89456C00A14493 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
8E6D68B11E59989400161780 /* Build configuration list for PBXProject "Convex Hull" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1CB6142C1F89456C00A14493"
BuildableName = "Tests.xctest"
BlueprintName = "Tests"
ReferencedContainer = "container:Convex Hull.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
30 changes: 17 additions & 13 deletions Convex Hull/Convex Hull/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,11 @@ class View: UIView {
}

var pts = points

// calculate parameters of general line equation y = a * x + b
let a = (p1.y - p2.y) / (p1.x - p2.x)
let b = p1.y - a * p1.x

// calculate normal line's growth factor
let a1 = -1 / a

var maxDist: CGFloat = -1
var maxPoint: CGPoint = pts.first!

for p in pts { // for every point check the distance from our line
let b1 = p.y - a1 * p.x // calculate offset to line equation for given point p
let x = -(b - b1)/(a - a1) // calculate x where the two lines intersect
let y = a * x + b // calculate y value of this intersect point

let dist = pow(x - p.x, 2) + pow(y - p.y, 2) // calculate distance squared between intersection point and point p
let dist = distance(from: p, to: (p1, p2))
if dist > maxDist { // if distance is larger than current maxDist remember new point p
maxDist = dist
maxPoint = p
Expand Down Expand Up @@ -150,6 +138,22 @@ class View: UIView {
findHull(s2, maxPoint, p2)
}

func distance(from p: CGPoint, to line: (CGPoint, CGPoint)) -> CGFloat {
// If line.0 and line.1 are the same point, they don't define a line (and, besides,
// would cause division by zero in the distance formula). Return the distance between
// line.0 and point p instead.
if line.0 == line.1 {
return sqrt(pow(p.x - line.0.x, 2) + pow(p.y - line.0.y, 2))
}

// from Deza, Michel Marie; Deza, Elena (2013), Encyclopedia of Distances (2nd ed.), Springer, p. 86, ISBN 9783642309588
return abs((line.1.y - line.0.y) * p.x
- (line.1.x - line.0.x) * p.y
+ line.1.x * line.0.y
- line.1.y * line.0.x)
/ sqrt(pow(line.1.y - line.0.y, 2) + pow(line.1.x - line.0.x, 2))
}

override func draw(_ rect: CGRect) {

let context = UIGraphicsGetCurrentContext()
Expand Down
22 changes: 22 additions & 0 deletions Convex Hull/Tests/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Loading