Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glitchy UIBezierPaths when using fb_union, fb_difference etc functions #20

Open
AndrewHartAR opened this issue Nov 13, 2018 · 1 comment

Comments

@AndrewHartAR
Copy link

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

@sabiland
Copy link

sabiland commented Oct 8, 2021

Is this project still maintained? I noticed today that if:

  1. Take UIBezierPath rect (say 1000 x 1000)
  2. Take UIBezierPath triangle (exactly half of the rect)
  3. I was expecting to get exactly inverted triangle inside the rect

But fb_difference doesn't do anything in this case. It just returns the same triangle as input.

But if I resize rect just a little bit (up or down) then fb_difference works as it should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants