Bezier curve tool bug

A forum dedicated to the Draft, Arch and BIM workbenches development.
carlopav
Posts: 442
Joined: Mon Dec 31, 2018 1:49 pm

Bezier curve tool bug

Postby carlopav » Tue Apr 02, 2019 7:33 pm

Hello, I noticed the strange behaviour of the bezier curve tool:
the user keep adding points and the tool just create a big bezier curve, instead of splitting it into several segments.

I'd like it to work like this:
kF3uXBNl4D.gif
kF3uXBNl4D.gif (293.64 KiB) Viewed 596 times
The behaviour in the gif is good but i think i broke the tool :lol:

soo... I investigated a bit ad i realized that the tool, when committing the creation of the curve dont give Draft.makeBezCurve the degree of the curve. If i'm able to fix also the preview i'll start with this small fix that should improve the usability a lot i think :)

PS I've not finished with the editing tool, but i was searching for something to have fun and not thinking about it :)
vocx
Posts: 2410
Joined: Thu Oct 18, 2018 9:18 pm

Re: Bezier curve tool bug

Postby vocx » Wed Apr 03, 2019 12:35 am

carlopav wrote:
Tue Apr 02, 2019 7:33 pm
Hello, I noticed the strange behaviour of the bezier curve tool:
the user keep adding points and the tool just create a big bezier curve, instead of splitting it into several segments.
...
I don't understand. Do you want to change the default behavior of the tool?
  • Current: the Bezier curve creates a single curve with many control points.
  • Your proposal: it should create multiple segments, each segment being its own Bezier curve.
The behaviour in the gif is good but i think i broke the tool :lol:
What exactly is broken?
Last edited by vocx on Sun May 12, 2019 6:13 pm, edited 1 time in total.
carlopav
Posts: 442
Joined: Mon Dec 31, 2018 1:49 pm

Re: Bezier curve tool bug

Postby carlopav » Wed Apr 03, 2019 5:58 am

vocx wrote:
Wed Apr 03, 2019 12:35 am
I don't understand. Do you want to change the default behavior of the tool?
  • Current: the Bezier curve creates a single curve with many control points.
  • Your proposal: it should create multiple segments, each segment being its own Bezier curves.
Exactly:
the draft bezier creation tool works with these arguments:

Code: Select all

Draft.makeBezCurve(pointslist,closed=False,placement=None,face=None,support=None,Degree=None):
but the Drafttools.bezCurve just give him this:

Code: Select all

Draft.makeBezCurve(points,closed='+str(closed)+',support='+sup+')
without the Degree, Draft just create a single bezier segment, aumenting the degree with every node added. And i think this is not good and counterintuitive. Instead the user should set the curve degree before starting the creation and it should remain fixed for the whole curve.

I also find this comment on the code:
# not quite right. draws 1 big bez. sb segmented

Do you agree?
User avatar
microelly2
Posts: 4508
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Bezier curve tool bug

Postby microelly2 » Wed Apr 03, 2019 7:29 am

The Draft Bezier tools creates for n points a bezier curve of degree n-1. You can change the property degree to get lower degree bezier segments in a next step
If you have 7 points and set degree to 3 you get 2 bezier segments.
with 10 points you get 3 bezier segments.
Here an example with teh same controlpoints anbd different degrees.
red is linear Degree 1
yellow is degree 3 - this is inkscape like.

Image

more examples see
http://freecadbuch.de/doku.php?id=blog: ... zierkurven
vocx
Posts: 2410
Joined: Thu Oct 18, 2018 9:18 pm

Re: Bezier curve tool bug

Postby vocx » Wed Apr 03, 2019 7:53 am

carlopav wrote:
Wed Apr 03, 2019 5:58 am
Exactly:
the draft bezier creation tool works with these arguments:

Code: Select all

Draft.makeBezCurve(pointslist,closed=False,placement=None,face=None,support=None,Degree=None):
but the Drafttools.bezCurve just give him this:

Code: Select all

Draft.makeBezCurve(points,closed='+str(closed)+',support='+sup+')
OK, I think I understand now. Draft.makeBezCurve() in Draft.py is the low level code that creates a Bezier curve by calling the even more primitive Part.BezierCurve() function.

Then, the class BezCurve in DraftTools.py is the higher level code (user interface, button) that calls Draft.makeBezCurve().
without the Degree, Draft just create a single bezier segment, aumenting the degree with every node added. And i think this is not good and counterintuitive.
I also found this behavior a bit strange at the beginning, but actually... I think it's not that bad. I don't have a lot of experience using Bezier curves, but I think in most cases a user will use a curve to smooth or round a corner made of two other straight lines. In this case, what the user wants is to produce a smooth curve by clicking many intermediate points. So the more he or she clicks, the smoother the curve gets because the degree becomes larger. This is similar to how Draft BSpline works.

The degree of the Bezier is one less than the number of points, so if the user clicks 5 times, he or she will get a curve of degree 4, which is two end points and three intermediate points. I think in most cases, the user would not need degrees larger than 4, which is why quadratic (2nd degree, 3 points) and cubic (3rd degree, 4 points) Beziers are so popular in most drawing programs.

In this picture, from top to bottom, the two lines are tied with Beziers of degrees 4 (quartic), 3 (cubic) and 2 (quadratic).
Draft_BezCurve_smooth.png
Draft_BezCurve_smooth.png (10.55 KiB) Viewed 539 times
Instead the user should set the curve degree before starting the creation and it should remain fixed for the whole curve.

I also find this comment on the code:
# not quite right. draws 1 big bez. sb segmented

Do you agree?
I do think that having an option in the Task panel (DraftGui.py) to lock the degree of the Bezier would be good, as it gives more possibilities to the user. But how would the user use the tool, just a start point and end point? It would need two points?

If the order is three, and I put two points, the code would have to automatically create the two intermediate control points at an arbitrary location without regards for my preferred curvature. Then I would have to go back into edit mode to modify the control points to suit my needs. If the tool stays as it is now, I can more or less direct the curvature of the Bezier by how I place the points along a path.

What I wouldn't like is to click many times on the 3D view, and that it creates multiple curves; that would be surprising. A single use of the tool should create a single object, not multiple objects. For example, if I use the Draft Wire, I want to get a single wire object, not many individual line objects; that'd just get messy in the tree view, you'd end with many, many objects in a short time.

Now, Draft already has a "continuation mode" to create multiple objects, one after the other. You activate this mode by pressing T in the keyboard (or checking the "continue" checkbox) after you enter the Task panel. That means that when you finish one object, it immediately starts creating a new object from the last point selected. So, basically, a Draft Wire is the same as a Draft Line with continuation mode on. It just creates line segments one after the other.

In your case, it would be like choosing (locking) the degree of the curve to 3, using continuation mode, then clicking two points; after the second point it would start creating a second curve, also of 3rd degree, and so on.

I think locking the degree of the curve is fine (with a checkbox and spinbox to choose the degree), but not breaking a high order curve into many objects, if the user doesn't want to.
carlopav
Posts: 442
Joined: Mon Dec 31, 2018 1:49 pm

Re: Bezier curve tool bug

Postby carlopav » Wed Apr 03, 2019 12:59 pm

I do think that having an option in the Task panel (DraftGui.py) to lock the degree of the Bezier would be good, as it gives more possibilities to the user.
+1
But how would the user use the tool, just a start point and end point? It would need two points?
i think we could provide two options:
  • cubic (fixed 3rd degree),
  • incremental degree (actual behaviour).
Keep in mind that the user can always change the degree of the curve after the creation, and this will affects the segment subdivision on document recompute.

I think locking the degree of the curve is fine (with a checkbox and spinbox to choose the degree), but not breaking a high order curve into many objects, if the user doesn't want to.
Agree, i think the goal should be to obtain a single curve object with several segments (depending on how many points the user clicked and the curve degree)
carlopav
Posts: 442
Joined: Mon Dec 31, 2018 1:49 pm

Re: Bezier curve tool bug

Postby carlopav » Wed Apr 03, 2019 1:08 pm

microelly2 wrote:
Wed Apr 03, 2019 7:29 am
The Draft Bezier tools creates for n points a bezier curve of degree n-1. You can change the property degree to get lower degree bezier segments in a next step
Sorry, didnt see the response before. Of course you can. But that behaviour seemed odd to me, maybe i worked too much with inkscape in the last times... :) I'd like to draw it cubic since the beginning (eventually with drag and drop to define control points).
Letting of course the user decide if he wants keep using the current mode. What do you think?

PS I realized that i should change the name of the topic if everyone thinks that it's acceptable like it is :)
chrisb
Posts: 20660
Joined: Tue Mar 17, 2015 9:14 am

Re: Bezier curve tool bug

Postby chrisb » Wed Apr 03, 2019 1:38 pm

carlopav wrote:
Wed Apr 03, 2019 1:08 pm
I realized that i should change the name of the topic if everyone thinks that it's acceptable like it is :)
It is not a bug, so the title might well be changed.

Here are quite some Inkscape users around, so an Inkscape-compatibility mode seems reasonable.
vocx
Posts: 2410
Joined: Thu Oct 18, 2018 9:18 pm

Re: Bezier curve tool bug

Postby vocx » Wed Apr 03, 2019 5:45 pm

carlopav wrote:
Wed Apr 03, 2019 1:08 pm
PS I realized that i should change the name of the topic if everyone thinks that it's acceptable like it is :)
It is not a bug, "it just works in a particular way that may be unexpected if you come from other drawing applications".
vocx
Posts: 2410
Joined: Thu Oct 18, 2018 9:18 pm

Re: Bezier curve tool bug

Postby vocx » Wed Apr 03, 2019 5:48 pm

carlopav wrote:
Wed Apr 03, 2019 12:59 pm
i think we could provide two options:
  • cubic (fixed 3rd degree),
  • incremental degree (actual behaviour).
Keep in mind that the user can always change the degree of the curve after the creation, and this will affects the segment subdivision on document recompute.
I think this makes sense. The tool should create by default a cubic Bezier, as it's probably the most used degree. But the user should also have the possibility of having the current system.