Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Jun 28, 2020 · 6 comments
Assignees
Milestone

Comments

@CrisFavero
Copy link

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
Copy link

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 ystrot self-assigned this Jul 17, 2020
@ystrot ystrot added this to the 0.9.7 milestone Jul 17, 2020
@ystrot
Copy link
Member

ystrot commented Jul 17, 2020

This issue fixed in the master branch.

@ystrot ystrot closed this as completed Jul 17, 2020
@mzaatar
Copy link

mzaatar commented Jul 18, 2020

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

@IngMarFlo
Copy link

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

@ystrot
Copy link
Member

ystrot commented Aug 11, 2020

Hi @IngMarFlo,

Please you the latest release version 0.9.7.

@IngMarFlo
Copy link

IngMarFlo commented Aug 11, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants