Graphical Issue

I'm using 12.3 Xcode and am going through the Drawing Paths and Shapes part of the Swift UI tutorial. Running the provided project files for the tutorial the shape looks correct but when add the code to my project one of the points is further right then it should be.

I have commented out the path.addQuadCurve and reduced the line length to better view the shape and the top right point extends nearly the right end of the phone. All other points are in the correct position. Has anyone else seen this issue?

I don't believe there is anything wrong with the code but Xcode.

Code Block swift
import CoreGraphics
struct HexagonParameters {
  struct Segment {
    let line: CGPoint
    let curve: CGPoint
    let control: CGPoint
  }
  static let adjustment: CGFloat = 0.085
  static let segments = [
    Segment(
      line:  CGPoint(x: 0.60, y: 0.05),
      curve:  CGPoint(x: 0.40, y: 0.05),
      control: CGPoint(x: 0.50, y: 0.00)
    ),
    Segment(
      line:  CGPoint(x: 0.05, y: 0.20 + adjustment),
      curve:  CGPoint(x: 0.00, y: 0.30 + adjustment),
      control: CGPoint(x: 0.00, y: 0.25 + adjustment)
    ),
    Segment(
      line:  CGPoint(x: 0.00, y: 0.70 - adjustment),
      curve:  CGPoint(x: 0.05, y: 0.80 - adjustment),
      control: CGPoint(x: 0.00, y: 0.75 - adjustment)
    ),
    Segment(
      line:  CGPoint(x: 0.40, y: 0.95),
      curve:  CGPoint(x: 0.60, y: 0.95),
      control: CGPoint(x: 0.50, y: 1.00)
    ),
    Segment(
      line:  CGPoint(x: 0.95, y: 0.80 - adjustment),
      curve:  CGPoint(x: 1.00, y: 0.70 - adjustment),
      control: CGPoint(x: 1.00, y: 0.75 - adjustment)
    ),
    Segment(
      line:  CGPoint(x: 1.00, y: 0.30 + adjustment),
      curve:  CGPoint(x: 0.95, y: 0.20 + adjustment),
      control: CGPoint(x: 1.00, y: 0.25 + adjustment)
    )
  ]
}


Code Block swift
import SwiftUI
struct BadgeBackground: View {
  var body: some View {
    GeometryReader { geometry in
      Path { path in
        var width = min(geometry.size.width, geometry.size.height)
        let height = width
        let xScale: CGFloat = 0.832
        let xOffset = (width * (1.0 - xScale)) / 2.0
        width *= xScale
        path.move(
          to: CGPoint(
            x: width * 0.95 + xOffset,
            y: height * (0.20 + HexagonParameters.adjustment)
          )
        )
        HexagonParameters.segments.forEach { segment in
          path.addLine(
            to: CGPoint(
              x: segment.line.x * 100.0,
              y: segment.line.y * 100.0
            )
          )
//          path.addQuadCurve(
//            to: CGPoint(
//              x: width * segment.curve.x + xOffset,
//              y: height * segment.curve.y
//            ),
//            control: CGPoint(
//              x: width * segment.control.x + xOffset,
//              y: height * segment.control.y
//            )
//          )
        }
      }
      .fill(LinearGradient(
        gradient: Gradient(colors: [Self.gradientStart, Self.gradientEnd]),
        startPoint: UnitPoint(x: 0.5, y: 0),
        endPoint: UnitPoint(x: 0.5, y: 0.6)
      ))
    }
    .aspectRatio(1, contentMode: .fit)
  }
  static let gradientStart = Color(red: 239.0 / 255, green: 120.0 / 255, blue: 221.0 / 255)
  static let gradientEnd = Color(red: 239.0 / 255, green: 172.0 / 255, blue: 120.0 / 255)
}



Answered by gamerking001 in 665354022
I continued on with the tutorial and in the next section the graphic looks as expected without any code changes. It is strange that previously it had the graphical issue in Preview, Simulator and Device.
Accepted Answer
I continued on with the tutorial and in the next section the graphic looks as expected without any code changes. It is strange that previously it had the graphical issue in Preview, Simulator and Device.

I don't believe there is anything wrong with the code but Xcode.

I do believe there is something wrong with your code.

Why have you changed line 23 and 24 from the original code?
Code Block
x: width * segment.line.x + xOffset,
y: height * segment.line.y

If you want to modify some points, all other points needs to be modified consistently. Only modifying this part is making your shape broken.
I mentioned why I changed those lines of code, it was to reduce the size of the shape drawn to see if it was bug in Xcode. After continuing on with the bug I figured it is a bug in Xcode.

I mentioned why I changed those lines of code, it was to reduce the size of the shape drawn to see if it was bug in Xcode.

As I wrote in my previous post, you need to change all the CGPoints consistently if you want to reduce the size.
So, your code shown cannot be any sort of proof it was a bug of Xcode.
Graphical Issue
 
 
Q