Skip to content

Commit

Permalink
Double Native Values (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpiazza authored Aug 15, 2021
1 parent b06f94c commit ef024d6
Show file tree
Hide file tree
Showing 25 changed files with 107 additions and 107 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/richardpiazza/Swift2D.git",
"state": {
"branch": null,
"revision": "d3aa067d4c9bfa97fb09b67b2b638bc134fae8d7",
"version": "1.1.0"
"revision": "4df6f74d3e3ad11075ea53fbb13fceda7c60b7b6",
"version": "2.0.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/MaxDesiatov/XMLCoder.git", from: "0.11.1"),
.package(url: "https://github.com/richardpiazza/Swift2D.git", from: "1.1.0"),
.package(url: "https://github.com/richardpiazza/Swift2D.git", from: "2.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
16 changes: 8 additions & 8 deletions Sources/SwiftSVG/Circle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ import XMLCoder
public struct Circle: Element {

/// The x-axis coordinate of the center of the circle.
public var x: Float = 0.0
public var x: Double = 0.0
/// The y-axis coordinate of the center of the circle.
public var y: Float = 0.0
public var y: Double = 0.0
/// The radius of the circle.
public var r: Float = 0.0
public var r: Double = 0.0

// CoreAttributes
public var id: String?

// PresentationAttributes
public var fillColor: String?
public var fillOpacity: Float?
public var fillOpacity: Double?
public var fillRule: Fill.Rule?
public var strokeColor: String?
public var strokeWidth: Float?
public var strokeOpacity: Float?
public var strokeWidth: Double?
public var strokeOpacity: Double?
public var strokeLineCap: Stroke.LineCap?
public var strokeLineJoin: Stroke.LineJoin?
public var strokeMiterLimit: Float?
public var strokeMiterLimit: Double?
public var transform: String?

// StylingAttributes
Expand All @@ -58,7 +58,7 @@ public struct Circle: Element {
public init() {
}

public init(x: Float, y: Float, r: Float) {
public init(x: Double, y: Double, r: Double) {
self.x = x
self.y = y
self.r = r
Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftSVG/Ellipse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ import XMLCoder
public struct Ellipse: Element {

/// The x position of the ellipse.
public var x: Float = 0.0
public var x: Double = 0.0
/// The y position of the ellipse.
public var y: Float = 0.0
public var y: Double = 0.0
/// The radius of the ellipse on the x axis.
public var rx: Float = 0.0
public var rx: Double = 0.0
/// The radius of the ellipse on the y axis.
public var ry: Float = 0.0
public var ry: Double = 0.0

// CoreAttributes
public var id: String?

// PresentationAttributes
public var fillColor: String?
public var fillOpacity: Float?
public var fillOpacity: Double?
public var fillRule: Fill.Rule?
public var strokeColor: String?
public var strokeWidth: Float?
public var strokeOpacity: Float?
public var strokeWidth: Double?
public var strokeOpacity: Double?
public var strokeLineCap: Stroke.LineCap?
public var strokeLineJoin: Stroke.LineJoin?
public var strokeMiterLimit: Float?
public var strokeMiterLimit: Double?
public var transform: String?

// StylingAttributes
Expand Down Expand Up @@ -57,7 +57,7 @@ public struct Ellipse: Element {
public init() {
}

public init(x: Float, y: Float, rx: Float, ry: Float) {
public init(x: Double, y: Double, rx: Double, ry: Double) {
self.x = x
self.y = y
self.rx = rx
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSVG/Fill.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Swift2D
public struct Fill {

public var color: String?
public var opacity: Float?
public var opacity: Double?
public var rule: Rule = .nonZero

public init() {}
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftSVG/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public struct Group: Container, Element {

// PresentationAttributes
public var fillColor: String?
public var fillOpacity: Float?
public var fillOpacity: Double?
public var fillRule: Fill.Rule?
public var strokeColor: String?
public var strokeWidth: Float?
public var strokeOpacity: Float?
public var strokeWidth: Double?
public var strokeOpacity: Double?
public var strokeLineCap: Stroke.LineCap?
public var strokeLineJoin: Stroke.LineJoin?
public var strokeMiterLimit: Float?
public var strokeMiterLimit: Double?
public var transform: String?

// StylingAttributes
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftSVG/Internal/EllipseProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import Foundation

struct EllipseProcessor {

let x: Float
let y: Float
let rx: Float
let ry: Float
let x: Double
let y: Double
let rx: Double
let ry: Double

/// The _optimal_ offset for control points when representing a
/// circle/ellipse as 4 bezier curves.
///
/// [Stack Overflow](https://stackoverflow.com/questions/1734745/how-to-create-circle-with-bézier-curves)
static func controlPointOffset(_ radius: Float) -> Float {
return (Float(4.0/3.0) * tan(Float.pi / 8.0)) * radius
static func controlPointOffset(_ radius: Double) -> Double {
return (Double(4.0/3.0) * tan(Double.pi / 8.0)) * radius
}

init(ellipse: Ellipse) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSVG/Internal/Path.Command+Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extension Path.Command {
/// - parameter value: The value to add to the existing value. If the current value equal `.isNaN`, than the
/// supplied value is used as-is.
/// - throws: `Path.Command.Error`
func adjustingArgument(at position: Int, by value: Float) throws -> Path.Command {
func adjustingArgument(at position: Int, by value: Double) throws -> Path.Command {
switch self {
case .moveTo(let point):
switch position {
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftSVG/Internal/PathProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PathProcessor {
private var currentPoint: Point = .zero
/// The argument position of the _command to be processed.
private var argumentPosition: Int = 0
/// Indicates that only a single `Float` will be processed on the next component pass.
/// Indicates that only a single `Double` will be processed on the next component pass.
private var singleValue: Bool = false
private var _commands: [Path.Command] = []

Expand All @@ -28,7 +28,7 @@ class PathProcessor {
///
/// For each of the command components:
/// * If a `Path.Command.Prefix` is identified: Setup a new `Command`.
/// * If a `Float` is identified: Continue a non-complete `Command`, or begin a new command using the last prefix.
/// * If a `Double` is identified: Continue a non-complete `Command`, or begin a new command using the last prefix.
/// * Ascertain if the command is complete and update `pathOrigin`/`currentPoint`.
func commands() throws -> [Path.Command] {
_commands.removeAll()
Expand All @@ -44,8 +44,8 @@ class PathProcessor {
default:
try setupCommand(prefix: prefix)
}
} else if let _value = Float(component) {
let value = Float(_value)
} else if let _value = Double(component) {
let value = Double(_value)
if let command = _command {
try continueCommand(command, value: value)
} else {
Expand Down Expand Up @@ -185,7 +185,7 @@ class PathProcessor {
}

/// Process Value
private func continueCommand(_ command: Path.Command, value: Float) throws {
private func continueCommand(_ command: Path.Command, value: Double) throws {
switch command {
case .moveTo, .cubicBezierCurve, .quadraticBezierCurve, .ellipticalArcCurve:
_command = try command.adjustingArgument(at: argumentPosition, by: value)
Expand Down Expand Up @@ -231,7 +231,7 @@ class PathProcessor {
}

/// New Command (using the last prefix)
private func setupNextCommand(value: Float) throws {
private func setupNextCommand(value: Double) throws {
guard let command = _commands.last else {
throw Path.Command.Error.invalidRelativeCommand
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftSVG/Internal/Point+SwiftSVG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ import Swift2D

extension Point {
static var nan: Point {
return Point(x: Float.nan, y: Float.nan)
return Point(x: Double.nan, y: Double.nan)
}

var hasNaN: Bool {
return x.isNaN || y.isNaN
}

/// Returns a copy of the instance with the **x** value replaced with the provided value.
func with(x value: Float) -> Point {
func with(x value: Double) -> Point {
return Point(x: value, y: y)
}

/// Returns a copy of the instance with the **y** value replaced with the provided value.
func with(y value: Float) -> Point {
func with(y value: Double) -> Point {
return Point(x: x, y: value)
}

/// Adjusts the **x** value by the provided amount.
///
/// This will explicitly check for `.isNaN`, and if encountered, will simply
/// use the provided value.
func adjusting(x value: Float) -> Point {
func adjusting(x value: Double) -> Point {
return (x.isNaN) ? with(x: value) : with(x: x + value)
}

/// Adjusts the **y** value by the provided amount.
///
/// This will explicitly check for `.isNaN`, and if encountered, will simply
/// use the provided value.
func adjusting(y value: Float) -> Point {
func adjusting(y value: Double) -> Point {
return (y.isNaN) ? with(y: value) : with(y: y + value)
}
}
4 changes: 2 additions & 2 deletions Sources/SwiftSVG/Internal/PolygonProcressor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ struct PolygonProcessor {

var firstValue: Bool = true
for (idx, component) in components.enumerated() {
guard let _value = Float(component) else {
guard let _value = Double(component) else {
return commands
}

let value = Float(_value)
let value = Double(_value)

if firstValue {
if idx == 0 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSVG/Internal/PolylineProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct PolylineProcessor {
func commands() throws -> [Path.Command] {
let pairs = points.components(separatedBy: " ")
let components = pairs.flatMap({ $0.components(separatedBy: ",") })
let values = components.compactMap({ Float($0) }).map({ Float($0) })
let values = components.compactMap({ Double($0) }).map({ Double($0) })

guard values.count > 2 else {
// More than just a starting point is required.
Expand All @@ -30,7 +30,7 @@ struct PolylineProcessor {

commands.append(.moveTo(point: Point(x: move[0], y: move[1])))

var _value: Float = .nan
var _value: Double = .nan
segments.forEach { (value) in
if _value.isNaN {
_value = value
Expand Down
18 changes: 9 additions & 9 deletions Sources/SwiftSVG/Line.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ import XMLCoder
public struct Line: Element {

/// Defines the x-axis coordinate of the line starting point.
public var x1: Float = 0.0
public var x1: Double = 0.0
/// Defines the x-axis coordinate of the line ending point.
public var y1: Float = 0.0
public var y1: Double = 0.0
/// Defines the y-axis coordinate of the line starting point.
public var x2: Float = 0.0
public var x2: Double = 0.0
/// Defines the y-axis coordinate of the line ending point.
public var y2: Float = 0.0
public var y2: Double = 0.0

// CoreAttributes
public var id: String?

// PresentationAttributes
public var fillColor: String?
public var fillOpacity: Float?
public var fillOpacity: Double?
public var fillRule: Fill.Rule?
public var strokeColor: String?
public var strokeWidth: Float?
public var strokeOpacity: Float?
public var strokeWidth: Double?
public var strokeOpacity: Double?
public var strokeLineCap: Stroke.LineCap?
public var strokeLineJoin: Stroke.LineJoin?
public var strokeMiterLimit: Float?
public var strokeMiterLimit: Double?
public var transform: String?

// StylingAttributes
Expand Down Expand Up @@ -57,7 +57,7 @@ public struct Line: Element {
public init() {
}

public init(x1: Float, y1: Float, x2: Float, y2: Float) {
public init(x1: Double, y1: Double, x2: Double, y2: Double) {
self.x1 = x1
self.y1 = y1
self.x2 = x2
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSVG/Path.Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension Path {
/// Draw a smooth curve using two points (+ origin)
case quadraticBezierCurve(cp: Point, point: Point)
/// Draw a curve defined as a portion of an ellipse
case ellipticalArcCurve(rx: Float, ry: Float, angle: Float, largeArc: Bool, clockwise: Bool, point: Point)
case ellipticalArcCurve(rx: Double, ry: Double, angle: Double, largeArc: Bool, clockwise: Bool, point: Point)
/// ClosePath instructions draw a straight line from the current position to the first point in the path.
case closePath

Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftSVG/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public struct Path: Element {

// PresentationAttributes
public var fillColor: String?
public var fillOpacity: Float?
public var fillOpacity: Double?
public var fillRule: Fill.Rule?
public var strokeColor: String?
public var strokeWidth: Float?
public var strokeOpacity: Float?
public var strokeWidth: Double?
public var strokeOpacity: Double?
public var strokeLineCap: Stroke.LineCap?
public var strokeLineJoin: Stroke.LineJoin?
public var strokeMiterLimit: Float?
public var strokeMiterLimit: Double?
public var transform: String?

// StylingAttributes
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftSVG/Polygon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public struct Polygon: Element {

// PresentationAttributes
public var fillColor: String?
public var fillOpacity: Float?
public var fillOpacity: Double?
public var fillRule: Fill.Rule?
public var strokeColor: String?
public var strokeWidth: Float?
public var strokeOpacity: Float?
public var strokeWidth: Double?
public var strokeOpacity: Double?
public var strokeLineCap: Stroke.LineCap?
public var strokeLineJoin: Stroke.LineJoin?
public var strokeMiterLimit: Float?
public var strokeMiterLimit: Double?
public var transform: String?

// StylingAttributes
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftSVG/Polyline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public struct Polyline: Element {

// PresentationAttributes
public var fillColor: String?
public var fillOpacity: Float?
public var fillOpacity: Double?
public var fillRule: Fill.Rule?
public var strokeColor: String?
public var strokeWidth: Float?
public var strokeOpacity: Float?
public var strokeWidth: Double?
public var strokeOpacity: Double?
public var strokeLineCap: Stroke.LineCap?
public var strokeLineJoin: Stroke.LineJoin?
public var strokeMiterLimit: Float?
public var strokeMiterLimit: Double?
public var transform: String?

// StylingAttributes
Expand Down
Loading

0 comments on commit ef024d6

Please sign in to comment.