-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from boostcamp-2020/feature/kmeans/initialize-…
…centroids KMeans 중심값 생성 함수 추가 및 코드 리팩토링
- Loading branch information
Showing
10 changed files
with
371 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Project17-C-Map/InteractiveClusteringMap/Clustering/KMeans/Degree.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Degree.swift | ||
// InteractiveClusteringMap | ||
// | ||
// Created by Seungeon Kim on 2020/11/27. | ||
// | ||
|
||
import Foundation | ||
|
||
enum Degree { | ||
static let right = 90.0 | ||
static let straight = 180.0 | ||
static let turn = 360.0 | ||
} |
File renamed without changes.
57 changes: 55 additions & 2 deletions
57
...veClusteringMap/VO/KMeansClustering.swift → ...steringMap/Clustering/KMeans/KMeans.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Project17-C-Map/InteractiveClusteringMap/Clustering/KMeans/Quadrant.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// Quadrant.swift | ||
// InteractiveClusteringMap | ||
// | ||
// Created by Seungeon Kim on 2020/11/27. | ||
// | ||
|
||
import Foundation | ||
|
||
enum Quadrant: Int { | ||
case first = 0, second = 1, third = 2, fourth = 3 | ||
|
||
static func findQuadrant(angle: Double) -> Quadrant { | ||
guard angle != .zero else { return Quadrant.first } | ||
|
||
let number = Int(angle / Degree.right) | ||
if angle.truncatingRemainder(dividingBy: Degree.right) == 0 { | ||
return Quadrant(rawValue: number - 1) ?? Quadrant.first | ||
} else { | ||
return Quadrant(rawValue: number) ?? Quadrant.first | ||
} | ||
} | ||
|
||
func theta(angle: Double) -> Double { | ||
if self == .first || self == .third { | ||
return Degree.right - angle | ||
} else { | ||
return angle | ||
} | ||
} | ||
|
||
func degree(center: Coordinate, boundary: Coordinate) -> Coordinate { | ||
switch self { | ||
case .first: | ||
return Coordinate(x: center.x + boundary.x, y: center.y) | ||
case .second: | ||
return Coordinate(x: center.x, y: center.y - boundary.y) | ||
case .third: | ||
return Coordinate(x: center.x - boundary.x, y: center.y) | ||
case .fourth: | ||
return Coordinate(x: center.x, y: center.y + boundary.y) | ||
} | ||
} | ||
|
||
func convertToCoordinate(center: Coordinate, distance: Coordinate) -> Coordinate { | ||
switch self { | ||
case .first: | ||
return Coordinate(x: center.x + distance.x, y: center.y + distance.y) | ||
case .second: | ||
return Coordinate(x: center.x + distance.x, y: center.y - distance.y) | ||
case .third: | ||
return Coordinate(x: center.x - distance.x, y: center.y - distance.y) | ||
case .fourth: | ||
return Coordinate(x: center.x - distance.x, y: center.y + distance.y) | ||
} | ||
} | ||
} |
Oops, something went wrong.