swhitty / SwiftDraw

@@ -34,6 +34,12 @@
Loading
34 34
    final class RadialGradient: Element {
35 35
36 36
        var id: String
37 +
        var r: Coordinate?
38 +
        var cx: Coordinate?
39 +
        var cy: Coordinate?
40 +
        var fr: Coordinate?
41 +
        var fx: Coordinate?
42 +
        var fy: Coordinate?
37 43
38 44
        var stops: [Stop]
39 45
        var gradientUnits: Units?

@@ -215,9 +215,12 @@
Loading
215 215
                let start = provider.createPoint(from: pathStart)
216 216
                let end = provider.createPoint(from: pathEnd)
217 217
218 +
                if !fillGradient.transform.isEmpty {
219 +
                    //commands.append(contentsOf: renderCommands(forTransforms: fillGradient.transform))
220 +
                }
221 +
218 222
                let apha = provider.createFloat(from: fill.opacity)
219 223
                commands.append(.setAlpha(apha))
220 -
221 224
                commands.append(.drawLinearGradient(gradient, from: start, to: end))
222 225
                commands.append(.popState)
223 226
            case .radialGradient(let fillGradient):
@@ -232,6 +235,10 @@
Loading
232 235
                let y = (pathBounds.center.y - pathBounds.origin.y)
233 236
                let radius = provider.createFloat(from: sqrt(x*x+y*y))
234 237
238 +
                if !fillGradient.transform.isEmpty {
239 +
                   // commands.append(contentsOf: renderCommands(forTransforms: fillGradient.transform))
240 +
                }
241 +
235 242
                let apha = provider.createFloat(from: fill.opacity)
236 243
                commands.append(.setAlpha(apha))
237 244
                commands.append(.drawRadialGradient(gradient, center: center, radius: radius))

@@ -232,6 +232,8 @@
Loading
232 232
            gradient.units = .userSpaceOnUse
233 233
        }
234 234
235 +
        gradient.transform = Self.createTransforms(from: element.gradientTransform)
236 +
235 237
        guard gradient.stops.count > 1 else {
236 238
            return nil
237 239
        }
@@ -252,6 +254,8 @@
Loading
252 254
            gradient.units = .userSpaceOnUse
253 255
        }
254 256
257 +
        gradient.transform = Self.createTransforms(from: element.gradientTransform)
258 +
255 259
        guard gradient.stops.count > 1 else {
256 260
            return nil
257 261
        }

@@ -68,13 +68,12 @@
Loading
68 68
69 69
extension DOM.LinearGradient: Equatable {
70 70
    static func ==(lhs: DOM.LinearGradient, rhs: DOM.LinearGradient) -> Bool {
71 -
        return
72 -
        lhs.id == rhs.id &&
73 -
        lhs.x1 == rhs.x1 &&
74 -
        lhs.y1 == rhs.y1 &&
75 -
        lhs.x2 == rhs.x2 &&
76 -
        lhs.y2 == rhs.y2 &&
77 -
        lhs.stops == rhs.stops
71 +
        return lhs.id == rhs.id &&
72 +
               lhs.x1 == rhs.x1 &&
73 +
               lhs.y1 == rhs.y1 &&
74 +
               lhs.x2 == rhs.x2 &&
75 +
               lhs.y2 == rhs.y2 &&
76 +
               lhs.stops == rhs.stops
78 77
    }
79 78
}
80 79

@@ -30,52 +30,54 @@
Loading
30 30
//
31 31
32 32
extension LayerTree {
33 -
  
34 -
  struct Gradient: Hashable {
35 -
    var start: Point
36 -
    var end: Point
37 -
    var stops: [Stop]
38 -
    var units: Units = .objectBoundingBox
39 33
40 -
    var colorSpace: ColorSpace {
41 -
      if stops.contains(where: { $0.color.isP3 }) {
42 -
        return .p3
43 -
      }
44 -
      return .srgb
45 -
    }
34 +
    struct Gradient: Hashable {
35 +
        var start: Point
36 +
        var end: Point
37 +
        var stops: [Stop]
38 +
        var units: Units = .objectBoundingBox
39 +
        var transform: [Transform]
46 40
47 -
    init(start: Point, end: Point) {
48 -
      self.start = start
49 -
      self.end = end
50 -
      self.stops = []
51 -
    }
41 +
        var colorSpace: ColorSpace {
42 +
            if stops.contains(where: { $0.color.isP3 }) {
43 +
                return .p3
44 +
            }
45 +
            return .srgb
46 +
        }
52 47
53 -
    struct Stop: Hashable {
54 -
      var offset: Float
55 -
      var color: Color
56 -
      var opacity: Float
57 -
      
58 -
      init(offset: Float, color: Color, opacity: Float) {
59 -
        self.offset = offset
60 -
        self.color = color
61 -
        self.opacity = opacity
62 -
      }
63 -
    }
48 +
        init(start: Point, end: Point) {
49 +
            self.start = start
50 +
            self.end = end
51 +
            self.stops = []
52 +
            self.transform = []
53 +
        }
54 +
55 +
        struct Stop: Hashable {
56 +
            var offset: Float
57 +
            var color: Color
58 +
            var opacity: Float
59 +
60 +
            init(offset: Float, color: Color, opacity: Float) {
61 +
                self.offset = offset
62 +
                self.color = color
63 +
                self.opacity = opacity
64 +
            }
65 +
        }
64 66
65 -
    enum Units: Hashable {
66 -
      case userSpaceOnUse
67 -
      case objectBoundingBox
67 +
        enum Units: Hashable {
68 +
            case userSpaceOnUse
69 +
            case objectBoundingBox
70 +
        }
68 71
    }
69 -
  }
70 72
}
71 73
72 74
private extension LayerTree.Color {
73 -
  var isP3: Bool {
74 -
    switch self {
75 -
    case .rgba(r: _, g: _, b: _, a: _, space: .p3):
76 -
      return true
77 -
    default:
78 -
      return false
75 +
    var isP3: Bool {
76 +
        switch self {
77 +
        case .rgba(r: _, g: _, b: _, a: _, space: .p3):
78 +
            return true
79 +
        default:
80 +
            return false
81 +
        }
79 82
    }
80 -
  }
81 83
}

@@ -51,6 +51,12 @@
Loading
51 51
52 52
        let nodeAtt: AttributeParser = try parseAttributes(e)
53 53
        let node = DOM.RadialGradient(id: try nodeAtt.parseString("id"))
54 +
        node.r = try? nodeAtt.parseCoordinate("r")
55 +
        node.cx = try? nodeAtt.parseCoordinate("cx")
56 +
        node.cy = try? nodeAtt.parseCoordinate("cy")
57 +
        node.fr = try? nodeAtt.parseCoordinate("fr")
58 +
        node.fx = try? nodeAtt.parseCoordinate("fx")
59 +
        node.fy = try? nodeAtt.parseCoordinate("fy")
54 60
55 61
        for n in e.children where n.name == "stop" {
56 62
            let att: AttributeParser = try parseAttributes(n)

@@ -37,7 +37,7 @@
Loading
37 37
38 38
extension LayerTree {
39 39
  
40 -
  enum Transform: Equatable {
40 +
  enum Transform: Hashable {
41 41
    case matrix(Matrix)
42 42
    case scale(sx: Float, sy: Float)
43 43
    case translate(tx: Float, ty: Float)
@@ -58,7 +58,7 @@
Loading
58 58
      return .matrix(m)
59 59
    }
60 60
    
61 -
    struct Matrix: Equatable {
61 +
    struct Matrix: Hashable {
62 62
      var a: Float
63 63
      var b: Float
64 64
      var c: Float
Files Coverage
SwiftDraw 75.70%
Project Totals (64 files) 75.70%
1
ignore:
2
  - "SwiftDrawTests"
3
  - "CommandLine"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading