nodebox icon indicating copy to clipboard operation
nodebox copied to clipboard

pointOnPath wraps at 100% to 0%

Open fjenett opened this issue 8 years ago • 3 comments

Currently (NodeBox 3.0.45) the point-on-path wraps at 100% to 0% which is not desirable because one might want to step up to the full 100% (think animation never reaching the final destination).

I think the problem is the modulo here: https://github.com/nodebox/nodebox/blob/c15874a11f7b90c262afcd2db5f20ea69dc011b2/src/main/java/nodebox/function/CoreVectorFunctions.java#L460

Checking > 100 and then setting to exactly 100 (same for 0) would be a better strategy:

    public static Point pointOnPath(AbstractGeometry shape, double t) {
        if (shape == null) return null;
        if ( t < 0 ) t = 0;
        else if ( t > 100 ) t = 100;
        return shape.pointAt(t / 100);
    }

fjenett avatar Jun 21 '16 11:06 fjenett

Thanks! This is indeed not the desired behaviour.

There are two "correct" solutions:

  • as-is: this is useful in some cases where going over the point actually gives an interesting result (think "extrapolation", ie. http://www.enigmeta.com/codevember/18/).
  • Clamping: so values stay on the path.

I'm not sure which is the right one. I'm leaning toward the first one, and then using an extra node to clamp the value.

fdb avatar Jun 21 '16 17:06 fdb

Extrapolation is fine with me and yes it is interesting. My problem is that it never reaches 100%, so it is not possible to animate between two states because the final state is never reached.

fjenett avatar Jul 22 '16 14:07 fjenett

This is a frequent problem for me too. My workaround is wrap a subnetwork around pointOnPath with a switch inside. If T<100 the switch returns an intermediate state based on pointOnPath; if T=100 it returns the end state instead.

jcartan avatar Mar 16 '19 04:03 jcartan