From 378afdbf4ee1aba75475c3986080045a9d69f43c Mon Sep 17 00:00:00 2001 From: junha Date: Wed, 4 Oct 2023 20:14:34 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=AB=A7::=20=EC=82=BC=EA=B0=81=ED=98=95=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Classes/PContributionsView.swift | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/PContributionsView/Classes/PContributionsView.swift b/PContributionsView/Classes/PContributionsView.swift index 743f57c..da06170 100644 --- a/PContributionsView/Classes/PContributionsView.swift +++ b/PContributionsView/Classes/PContributionsView.swift @@ -221,27 +221,18 @@ open class PContributionsView: UIView { path.addLine(to: CGPoint(x: x.x, y: x.y)) path.close() case .triangle: - let angle: CGFloat = .pi / 10 + let radius: CGFloat = CGFloat(rectWidth) / 2 + let centerX: CGFloat = (x.x + y.x) / 2 + let centerY: CGFloat = (x.y + y.y) / 2 - var shouldMove: Bool = true - var currentPoint = CGPoint.zero - - for i in 0..<10 { - let radius = (i % 2 == 0) ? cornerRadius : cornerRadius / 2 - let xVal = (radius * cos(angle * CGFloat(i))) + (x.x + y.x) / 2 - let yVal = (radius * sin(angle * CGFloat(i))) + (x.y + y.y) / 2 - let point = CGPoint(x: xVal, y: yVal) - - if shouldMove { - path.move(to: point) - currentPoint = point - shouldMove = false - } else { - path.addLine(to: point) - } - - currentPoint = point - } + let point1 = CGPoint(x: centerX, y: centerY - radius) + let point2 = CGPoint(x: centerX - radius * cos(.pi / 6), y: centerY + radius * sin(.pi / 6)) + let point3 = CGPoint(x: centerX + radius * cos(.pi / 6), y: centerY + radius * sin(.pi / 6)) + + path.move(to: point1) + path.addLine(to: point2) + path.addLine(to: point3) + path.close() case .pentagon: // 5각형 그리기 let radius: CGFloat = CGFloat(rectWidth / 2)