Fix for flaky corner radius path generation (#958)

* fixed the flaky corner radius path generation

* format
This commit is contained in:
Mauro
2023-05-25 13:15:12 +02:00
committed by GitHub
parent bf2102e5d1
commit c3eb64bde5
25 changed files with 83 additions and 52 deletions
@@ -26,10 +26,41 @@ struct RoundedCornerShape: Shape {
}
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
return Path(path.cgPath)
var path = Path()
let width = rect.size.width
let height = rect.size.height
var topLeft: CGFloat = corners.contains(.topLeft) ? radius : 0.0
var topRight: CGFloat = corners.contains(.topRight) ? radius : 0.0
var bottomLeft: CGFloat = corners.contains(.bottomLeft) ? radius : 0.0
var bottomRight: CGFloat = corners.contains(.bottomRight) ? radius : 0.0
// Make sure we do not exceed the size of the rectangle
topRight = min(min(topRight, height / 2), width / 2)
topLeft = min(min(topLeft, height / 2), width / 2)
bottomLeft = min(min(bottomLeft, height / 2), width / 2)
bottomRight = min(min(bottomRight, height / 2), width / 2)
path.move(to: CGPoint(x: width / 2.0, y: 0))
path.addLine(to: CGPoint(x: width - topRight, y: 0))
path.addArc(center: CGPoint(x: width - topRight, y: topRight), radius: topRight,
startAngle: Angle(degrees: -90), endAngle: Angle(degrees: 0), clockwise: false)
path.addLine(to: CGPoint(x: width, y: height - bottomRight))
path.addArc(center: CGPoint(x: width - bottomRight, y: height - bottomRight), radius: bottomRight,
startAngle: Angle(degrees: 0), endAngle: Angle(degrees: 90), clockwise: false)
path.addLine(to: CGPoint(x: bottomLeft, y: height))
path.addArc(center: CGPoint(x: bottomLeft, y: height - bottomLeft), radius: bottomLeft,
startAngle: Angle(degrees: 90), endAngle: Angle(degrees: 180), clockwise: false)
path.addLine(to: CGPoint(x: 0, y: topLeft))
path.addArc(center: CGPoint(x: topLeft, y: topLeft), radius: topLeft,
startAngle: Angle(degrees: 180), endAngle: Angle(degrees: 270), clockwise: false)
path.closeSubpath()
return path
}
}
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a4983811f9c93ae9d91957ad62b91456beed84048abbc78339ccd159edb9b6e9
size 234145
oid sha256:79aed4e679f43602880d7cfbf76fdb4e0dc237ec785484d48eed49d959d43c6c
size 232894
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a1ddd83f9f845b6d6281f8e291674957f9d3b2d6d5dfad66b3ead58cf3faa147
size 278646
oid sha256:8b158cbc42c2f948549482d6b45a6eb0366eed3062da478674508509fed2f0a4
size 277271
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b24385ffd83f5124614ec088dbcc96ac80b717eeba49b0e87624b308a6a00875
size 234046
oid sha256:1cc4d04113af86b2ad7b426f8ed97d9c8272695636ec71b30d76148820d5a857
size 232804
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d16782fe705cc6c2d5dcf0c5e60ee72898c599c8226e6fc3abdbe0b2f6ede5f7
size 100181
oid sha256:6ff602b998ae429f5f68996f8b9b3029371fc52f521f004825a6c9206dce0c21
size 99742
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:863a56b98b4781de1da9122817c84df6791afd25defc3b9709737c9417e72481
size 122963
oid sha256:6e9af3b870c44cab4d22ba7e63cf564ceb856c64cc4c6fa589c821e369d9b2fe
size 122172
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:17578cec39bfddd1b1ff1963b74ce1e9863d073f133de441e0997a21c5bfdf37
size 298067
oid sha256:3e3ce58b1080c8bb5e0d017ebb37077f2cc3b60ad5715cf3d924bdfddff2b535
size 295604
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e44ebb4db0febc50dd1ae363c106d149e4a8e6e0386eb7c6e2b6b442a3784535
size 358633
oid sha256:bab561403412b563bac24b6676a3770caf6e63d26496afe7324902a02ac27171
size 358173
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:81b08daf45dccae39110df315f14d0aeb5027b805af18bee10ba8fa561fb980a
size 246221
oid sha256:e9c51054aa21e5196bcaa8d74b73f6a61f8b1dd061d2f57d0b89a39ae99bf1b0
size 245687
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0160aea39bc6016c5e423d2d846f247d1f1e9d0024a1f5c833a98be7e77ea207
size 358357
oid sha256:ef7e2f6841d0c8524d049605258e42e49dbc3f7a63dcdb019033cfeccd2c6647
size 357869
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9fc157e760cd2faf5936011d69f53744b7d037c9ee8f8434d071ff49e626e9da
size 155517
oid sha256:d501798000134f9672b6f1a3858815fac762f9303166bab6b8847e223ae9bd71
size 154888
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c849dbf18fda70046a9cc5e8a117078a69c7b5618222710c92f437b288217d74
size 191841
oid sha256:3360a287d9a4daeda773c49e3428f2ed78a6d507501b8515522d981c138271e2
size 191019
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:77e6a585c3e6057cbb2c92f7b525b1464c13570a67b809ba6c02a4f09b7e0a60
size 318416
oid sha256:08f472ec04d47cbaaae202fd04f5c796b47a52f0342ec197f44e6155adf56d69
size 317552
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:845e339376c379882e2a4811a4349cb89377abd348282a76b29640ec3ed5e551
size 235185
oid sha256:60065305a7afee817f9d7b6ab39387724f4e8e1cdd85001dfc598d54c1d42a59
size 233924
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5460a8e7171dccc726fc7a5da386d0408f86998ea4d51b06b05c90f077b8bc21
size 279028
oid sha256:52980d6dfbd4cc70655173693c25748eaff6caa6d99e2a7af19c2d1ff2e14f47
size 277659
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f7b7650aab00b11152a22a63721b2005364d1e915c44cd802a29ced4f5f586ab
size 235091
oid sha256:f3e2456cab029084b83a793ce8acedbece1fd326e2a4a00ef042f7c0462735fc
size 233828
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d413f50e7778b19fdb8baac0e11b6f78c76af3b58436e405a6f60a9b42a50940
size 100669
oid sha256:18e9ff4bf9613e832282bc58108491ea837ed52ed960e656425b47b9d3c668a4
size 100205
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:283db285833ed3fd65ae6adf61111ffca3f3a9d5fc3fb05d240f81fac7ea8b17
size 123454
oid sha256:e4446cf388de4a649573a7584e8f26e688143a87da5bd8129fb910c9b8ca99dc
size 122668
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3b7fb769b14c81ff5e9d9be36083ffa48623c90ea4d333105c071bf326d0c859
size 298553
oid sha256:5cdad7a291ac740aaa3d65ba42764e83fb35728c94061f707b895f11a4c9cbc0
size 296087
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a2ab1da0274529f2bc26af0b7d9d94ad399a5c46e6f3a496df3885d1cd650729
size 332000
oid sha256:00c8ff711be9887999ccf53c1d8a83b6eb3dc64a995cc4ff9befb3af2fcd5fda
size 331747
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8f2115478483a5e24fa09118e00efc8eedb79db01782b7a54ef0e70c5baf27b3
size 239702
oid sha256:14ce154e225fb44ab8d25ffd3a5fd4c9f31fff749ffcb2b85c9bf48ffdb222c7
size 239096
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b4764bac791d16b80ab2a2303e97bad7eb5971b45439319b8f633752718279cd
size 331646
oid sha256:01d80b393f47f65ada87ae257db7f6b6ff4ea1249a563cc4766957afb426a6a9
size 331400
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a1ef9a0b33c1c8c9fbae6fc66f0d9bbdbda390574539c6c2bfc94c1c8e3ac81a
size 156266
oid sha256:c7dc2cffb7f9f8fa6eded8cb651d244fe1cd38b49b46fe53333f99ab817575c5
size 155897
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8fc2fcf3937665fe3a581c9378d023ca57f4d5e630eb51496d7f21a1e4fe9a8f
size 192441
oid sha256:83b4a6ce0752c14c6b62fe945b2df0bf147be08556cadc7d6660924e067783f3
size 191958
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:643fdf24fa8f7553f120da069ddbfe13d5b2e2405ad2b0041ad765b0efd99797
size 305866
oid sha256:88b627d39519eca49a62970fb7924c754b75967894d9ba3367f60dce83eb7429
size 305045