diff --git a/swift/Sources/QRCodeGenerator/QRCode.swift b/swift/Sources/QRCodeGenerator/QRCode.swift index a6320ce..8e5e2fb 100644 --- a/swift/Sources/QRCodeGenerator/QRCode.swift +++ b/swift/Sources/QRCodeGenerator/QRCode.swift @@ -240,7 +240,7 @@ struct QRCode { /// /// The top left corner has the coordinates (x=0, y=0). If the given /// coordinates are out of bounds, then `false` (white) is returned. - public func getModule(_ x: Int, _ y: Int) -> Bool { + public func getModule(x: Int, y: Int) -> Bool { 0 <= x && x < size && 0 <= y && y < size && self[x, y] } @@ -261,7 +261,7 @@ struct QRCode { let dimension = size + (border * 2) let path = (0.. 9) * 0x537) + } + let bits: UInt32 = (data << 10 | rem) ^ 0x5412 // uint15 + + // Draw first copy + for i in 0..<6 { + setFunctionModule(x: 8, y: i, isBlack: getBit(bits, i)) + } + setFunctionModule(x: 8, y: 7, isBlack: getBit(bits, 6)) + setFunctionModule(x: 8, y: 8, isBlack: getBit(bits, 7)) + setFunctionModule(x: 7, y: 8, isBlack: getBit(bits, 8)) + for i in 9..<15 { + setFunctionModule(x: 14 - i, y: 8, isBlack: getBit(bits, i)) + } + + // Draw second copy + for i in 0..<8 { + setFunctionModule(x: size - 1 - i, y: 8, isBlack: getBit(bits, i)) + } + for i in 0..<15 { + setFunctionModule(x: 8, y: size - 15 + i, isBlack: getBit(bits, i)) + } + setFunctionModule(x: 8, y: size - 8, isBlack: true) // Always black + } } diff --git a/swift/Sources/QRCodeGenerator/QRCodeMiscellaneous.swift b/swift/Sources/QRCodeGenerator/QRCodeMiscellaneous.swift index c5cd2ec..9c588e2 100644 --- a/swift/Sources/QRCodeGenerator/QRCodeMiscellaneous.swift +++ b/swift/Sources/QRCodeGenerator/QRCodeMiscellaneous.swift @@ -62,6 +62,6 @@ public enum QRCodeError: Error { } /// Returns true iff the i'th bit of x is set to 1. -func getBit(x: UInt32, i: UInt32) -> Bool { +func getBit(_ x: UInt32, _ i: UInt32) -> Bool { (x >> i) & 1 != 0 }