Skip to content

Commit c13d840

Browse files
committed
Added pinch inset generator
1 parent 1b6b04c commit c13d840

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

Sources/QRCode/styles/data/pixel/inset-generator/QRCodePixelShapeInset+Generator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extension QRCode {
5454
@objc public static let generators: [QRCodePixelInsetGenerator.Type] = [
5555
QRCode.PixelInset.Fixed.self,
5656
QRCode.PixelInset.Random.self,
57+
QRCode.PixelInset.Pinch.self,
5758
QRCode.PixelInset.Punch.self,
5859
QRCode.PixelInset.HorizontalWave.self,
5960
QRCode.PixelInset.VerticalWave.self,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Copyright © 2025 Darren Ford. All rights reserved.
3+
//
4+
// MIT license
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7+
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
8+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9+
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all copies or substantial
12+
// portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
15+
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
16+
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18+
//
19+
20+
import CoreGraphics
21+
import Foundation
22+
23+
public extension QRCode.PixelInset {
24+
/// A pixel inset generator that creates a bigger inset the closer to the center of the QR code
25+
@objc(QRCodePixelInsetPinch)
26+
class Pinch: NSObject, QRCodePixelInsetGenerator {
27+
public static var Name: String { "pinch" }
28+
public static func Create() -> QRCodePixelInsetGenerator { QRCode.PixelInset.Pinch() }
29+
public func reset() {}
30+
public func copyInsetGenerator() -> QRCodePixelInsetGenerator { QRCode.PixelInset.Pinch() }
31+
public func insetValue(for matrix: BoolMatrix, row: Int, column: Int, insetFraction: CGFloat) -> CGFloat {
32+
assert(insetFraction.in(0 ... 1))
33+
let half = Double(matrix.dimension) / 2
34+
35+
let cc = Double(column) - half
36+
let cr = Double(row) - half
37+
38+
let len = sqrt(cc*cc + cr*cr) / half
39+
return len * insetFraction
40+
}
41+
}
42+
}

Sources/QRCode/styles/data/pixel/inset-generator/QRCodePixelShapeInset+Punch.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import CoreGraphics
2121
import Foundation
2222

2323
public extension QRCode.PixelInset {
24-
/// A pixel inset generator that creates a bigger inset the closer to the center of the QR code
24+
/// A pixel inset generator that creates a bigger inset the closer to the edge of the QR code
2525
@objc(QRCodePixelInsetPunch)
2626
class Punch: NSObject, QRCodePixelInsetGenerator {
2727
public static var Name: String { "punch" }

0 commit comments

Comments
 (0)