Skip to content

Glitchy UIBezierPaths when using fb_union, fb_difference etc functions #20

@AndrewHartAR

Description

@AndrewHartAR

I'm using the fb_union, fb_difference functions to create a complex bezier path. I'm finding that there are many issues with these functions.

Here is code that generates a rectangle by combining a series of smaller rectangles:

var bezier = UIBezierPath()
	
for x in 20..<30 {
  for y in 15..<20 {
    let rect = CGRect(x: x * 10, y: y * 10, width: 11, height: 11)
    let bezier2 = UIBezierPath(rect: rect)
			
    bezier = bezier.fb_union(bezier2)
  }
}

The width/height is 11 to create a little overlap. From the result I can see that this works, and creates what appears to be a larger rectangle (albeit with a complex single-shape geometry, once printed).

img_5476

<UIBezierPath: 0x282f98780; <MoveTo {290.49999999999994, 201}>,
 <LineTo {280.49999999999994, 201}>,
 <LineTo {280.49999999999994, 200.99999999999997}>,
 <LineTo {270.50000000000006, 201}>,
 <LineTo {270.49999999999994, 200.99999999999997}>,
 <LineTo {260.50000000000006, 201}>,
 <LineTo {260.49999999999994, 201}>,
 <LineTo {250.5, 201}>,
 <LineTo {250.49999999999994, 201}>,
 <LineTo {240.5, 201}>,
 <LineTo {240.49999999999997, 201}>,
 <LineTo {230.50000000000003, 201}>,
 <LineTo {230.5, 201}>,
 <LineTo {220.50000000000003, 201}>,
 <LineTo {210.50000000000003, 201}>,
 <LineTo {200, 201}>,
 <LineTo {200, 190.50000000000003}>,
 <LineTo {199.99999999999994, 190.50000000000003}>,
 <LineTo {199.99999999999994, 180.5}>,
 <LineTo {200, 170.5}>,
 <LineTo {200, 170.50000000000003}>,
 <LineTo {200, 160.50000000000003}>,
 <LineTo {200, 150}>,
 <LineTo {210.5, 150}>,
 <LineTo {210.50000000000003, 150}>,
 <LineTo {220.49999999999997, 150}>,
 <LineTo {220.50000000000003, 150}>,
 <LineTo {230.50000000000003, 150}>,
 <LineTo {240.50000000000003, 150}>,
 <LineTo {250.50000000000003, 150}>,
 <LineTo {250.5, 150}>,
 <LineTo {260.49999999999994, 150}>,
 <LineTo {260.50000000000006, 150}>,
 <LineTo {270.49999999999994, 150}>,
 <LineTo {270.50000000000006, 150}>,
 <LineTo {280.49999999999994, 150}>,
 <LineTo {280.5, 150}>,
 <LineTo {290.49999999999994, 150}>,
 <LineTo {290.50000000000006, 150}>,
 <LineTo {301, 150}>,
 <LineTo {301, 160.50000000000003}>,
 <LineTo {301, 170.50000000000003}>,
 <LineTo {301, 180.50000000000003}>,
 <LineTo {301, 190.50000000000003}>,
 <LineTo {301, 201}>,
 <LineTo {290.5, 201}>,
 <Close>

Then I remove every other column, by only drawing columns on even rows:

var bezier = UIBezierPath()
	
for x in 20..<30 {
  if floor(Double(x) / 2) != Double(x) / 2 {
    continue
  }

  for y in 15..<20 {
    let rect = CGRect(x: x * 10, y: y * 10, width: 11, height: 11)
    let bezier2 = UIBezierPath(rect: rect)
			
    bezier = bezier.fb_union(bezier2)
  }
}

The result here is that some of the shapes which should be drawn, inexplicably aren't.

img_5477

This is an example result - I'm only showing issues with fb_union here, but this issue is very prevalent across uses of these functions. This can be tested using the attached sample project.

beziertest.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions