ID 144410 - value.integrate() miscalculates

Follow

Problem summary
 
The function works (albeit with weird intraframe results) if you use a definite frame range, for example, .integrate((frame-5),frame) but does not work when you calculate something like .integrate(0,frame)

The below image shows the source curve (SquareWave) and the resulting integrals (Test and Test2), and the expressions used for each.



Customer reported version
nuke.n/a

Customer reported platform
Linux

Steps to reproduce
1) Open Nuke

2) Copy and paste the following code into the node graph: 
 

set cut_paste_input [stack 0]version 11.1 v1push $cut_paste_inputOutput { name tcl_bug selected true xpos -40 ypos -145 addUserKnob {20 User} addUserKnob {7 Test2} Test2 {{SquareWave.integrate(0,int(frame))}} addUserKnob {7 Test} Test {{SquareWave.integrate(frame-5,int(frame))}} addUserKnob {7 SquareWave} SquareWave {{int(sin(2*pi*(frame)/24)+1)}}}
 
3) Double clcik on the node, before opening the Curve Editor.

4) Select the 'Test' and 'Test2' curves, and notice the shape is incorrect.

5) The expression of the curve can be viewed by right-clicking on its name from the list, then Edit > Edit Expression

Workaround
For working with a definite range, changing the expression from:
SquareWave.integrate(frame-5,int(frame))

To the following: 
SquareWave.integrate(rint(frame-5),rint(frame))

​ 
By using the rint function, it seems to give a result that is, or is closer to, what you would expect to see.

For indefinite frame ranges, using Python code again produces a more desirable result:
 

This was produced by using the following code:
n = nuke.thisNode()
frame = nuke.frame()
distance = 0
for i in range(0,frame):
distance += n['SquareWave'].getValueAt(i)
ret = distance
 
Copy and paste the following into the node graph to see both workarounds:
 

set cut_paste_input [stack 0]version 11.1 v1push $cut_paste_inputOutput { name TCL_Workaround selected true xpos -57 ypos -137 addUserKnob {20 User} addUserKnob {7 SquareWave} SquareWave {{int(sin(2*pi*(frame)/24)+1)}} addUserKnob {7 Test1} Test1 {{SquareWave.integrate(frame-5,frame)}} addUserKnob {7 Test2} Test2 {{"\[python -execlocal n\\ =\\ nuke.thisNode()\\nframe\\ =\\ nuke.frame()\\n\\ndistance\\ =\\ 0\\n\\nfor\\ i\\ in\\ range(0,frame):\\n\\ \\ \\ \\ distance\\ +=\\ n\\\['SquareWave'\\].getValueAt(i)\\n\\nret\\ =\\ distance]"}}}
 
Reproduced by support
This bug has been reproduced in:
Nuke11.1v1 - Windows 10 - Linux CentOS 7 - OSX High Sierra 
Nuke11.0v3 - Windows 10
Nuke11.0v1 - Windows 10
Nuke10.5v7 - Windows 10
Nuke10.5v1 - Windows 10
Nuke9.0v9 - Windows 10
Nuke9.0v1 - Windows 10
Nuke8.0v7 - Windows 10
Nuke8.0v1 - Windows 10
Nuke7.0v10 - Windows 10 - Linux CentOS 7 - OSX High Sierra

Earliest version tested
- This issue appears to be in all versions of the product
 
Expected behaviour
The integrate function to be calculated correctly.

Actual behaviour
The integrate function is not being calculated correctly, you can tell this by the odd shape of the curve.

    We're sorry to hear that

    Please tell us why