Navaron Bracke

add size & corners for MacOS

@@ -542,10 +542,24 @@ extension CGImage { @@ -542,10 +542,24 @@ extension CGImage {
542 } 542 }
543 543
544 extension VNBarcodeObservation { 544 extension VNBarcodeObservation {
  545 + private func distanceBetween(_ p1: CGPoint, _ p2: CGPoint) -> CGFloat {
  546 + return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2))
  547 + }
  548 +
545 public func toMap() -> [String: Any?] { 549 public func toMap() -> [String: Any?] {
546 return [ 550 return [
547 - "rawValue": self.payloadStringValue ?? "",  
548 - "format": self.symbology.toInt ?? -1, 551 + "corners": [
  552 + ["x": Double(topLeft.x), "y": Double(topLeft.y)],
  553 + ["x": Double(topRight.x), "y": Double(topRight.y)],
  554 + ["x": Double(bottomRight.x), "y": Double(bottomRight.y)],
  555 + ["x": Double(bottomLeft.x), "y": Double(bottomLeft.y)],
  556 + ],
  557 + "format": symbology.toInt ?? -1,
  558 + "rawValue": payloadStringValue ?? "",
  559 + "size": [
  560 + "width": Double(distanceBetween(topLeft, topRight)),
  561 + "height": Double(distanceBetween(topLeft, bottomLeft)),
  562 + ],
549 ] 563 ]
550 } 564 }
551 } 565 }
@@ -585,7 +599,7 @@ extension VNBarcodeSymbology { @@ -585,7 +599,7 @@ extension VNBarcodeSymbology {
585 } 599 }
586 } 600 }
587 601
588 - var toInt:Int? { 602 + var toInt: Int? {
589 if #available(macOS 12.0, *) { 603 if #available(macOS 12.0, *) {
590 if(self == VNBarcodeSymbology.codabar){ 604 if(self == VNBarcodeSymbology.codabar){
591 return 8 605 return 8