exyte / Macaw

Powerful and easy-to-use vector graphics Swift library with SVG support
MIT License
6.01k stars 553 forks source link

ColorMatrix Type Failure - The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions #709

Closed CrisFavero closed 4 years ago

CrisFavero commented 4 years ago

While building Macaw with xcode12-beta We get the build error The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions on line sixty in colorMatrix

https://github.com/exyte/Macaw/blob/master/Source/model/draw/ColorMatrix.swift#L60

icloudendswiftui commented 4 years ago

import Foundation

open class ColorMatrix {

public static let identity = ColorMatrix(
    values: [1, 0, 0, 0, 0,
             0, 1, 0, 0, 0,
             0, 0, 1, 0, 0,
             0, 0, 0, 1, 0])

public static let luminanceToAlpha = ColorMatrix(
    values: [1, 0, 0, 0, 0,
             0, 1, 0, 0, 0,
             0, 0, 1, 0, 0,
             0.2125, 0.7154, 0.0721, 0, 0])

public let values: [Double]

public init(values: [Double]) {
    if values.count != 20 {
        fatalError("ColorMatrix: wrong matrix count")
    }
    self.values = values
}

public convenience init(color: Color) {
    self.init(values: [0, 0, 0, 0, Double(color.r()) / 255.0,
                       0, 0, 0, 0, Double(color.g()) / 255.0,
                       0, 0, 0, 0, Double(color.b()) / 255.0,
                       0, 0, 0, Double(color.a()) / 255.0, 0])
}

public convenience init(saturate: Double) {
    let s = max(min(saturate, 1), 0)
    self.init(values: [0.213 + 0.787 * s, 0.715 - 0.715 * s, 0.072 - 0.072 * s, 0, 0,
                       0.213 - 0.213 * s, 0.715 + 0.285 * s, 0.072 - 0.072 * s, 0, 0,
                       0.213 - 0.213 * s, 0.715 - 0.715 * s, 0.072 + 0.928 * s, 0, 0,
                       0, 0, 0, 1, 0])
}

public convenience init(hueRotate: Double) {
    let c = cos(hueRotate)
    let s = sin(hueRotate)
    let m1 = [0.213, 0.715, 0.072,
              0.213, 0.715, 0.072,
              0.213, 0.715, 0.072]
    let m2 = [0.787, -0.715, -0.072,
              -0.213, 0.285, -0.072,
              -0.213, -0.715, 0.928]
    let m3 = [-0.213, -0.715, 0.928,
              0.143, 0.140, -0.283,
              -0.787, 0.715, 0.072]
   /*
    let a = { i in
        m1[i] + c * m2[i] + s * m3[i]
    }

*/ self.init(values: [ acal(i:0, m1: m1, c: c, m2: m2, s: s, m3: m3), acal(i:1, m1: m1, c: c, m2: m2, s: s, m3: m3), acal(i:2, m1: m1, c: c, m2: m2, s: s, m3: m3), 0, 0, acal(i:3, m1: m1, c: c, m2: m2, s: s, m3: m3), acal(i:4, m1: m1, c: c, m2: m2, s: s, m3: m3), acal(i:5, m1: m1, c: c, m2: m2, s: s, m3: m3), 0, 0, acal(i:6, m1: m1, c: c, m2: m2, s: s, m3: m3), acal(i:7, m1: m1, c: c, m2: m2, s: s, m3: m3), acal(i:8, m1: m1, c: c, m2: m2, s: s, m3: m3), 0, 0,0, 0, 0, 1, 0]) }

}

func acal(i:Int,m1:[Double],c:Double,m2:[Double],s:Double,m3:[Double]) -> Double { return m1[i] + c m2[i] + s m3[i]

}

ystrot commented 4 years ago

This issue fixed in the master branch.

mzaatar commented 4 years ago

So now we can use it in iOS 14.0 beta Thanks mate!

IngMarFlo commented 4 years ago

i have this problem in the Colors.swift file, in the line 56. I use in xcode 11.6.

ystrot commented 4 years ago

Hi @IngMarFlo,

Please you the latest release version 0.9.7.

IngMarFlo commented 4 years ago

Thanks, i'll try

El mar., 11 de agosto de 2020 1:30 a. m., Yuri Strot < notifications@github.com> escribió:

Hi @IngMarFlo https://github.com/IngMarFlo,

Please you the latest release version 0.9.7.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/exyte/Macaw/issues/709#issuecomment-671755936, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZ3VISGGMIU2BGJVAPMYFTSADQQXANCNFSM4OKTDCPA .