You cannot now overshoot the curve length in getUtoTmapping

This commit is contained in:
Richard Davey 2017-09-21 02:51:02 +01:00
parent cf4b97cbdc
commit 05d251a953

View file

@ -19,7 +19,7 @@ var Curve = new Class({
function Curve () function Curve ()
{ {
this.arcLengthDivisions = 200; this.arcLengthDivisions = 100;
this.cacheArcLengths = []; this.cacheArcLengths = [];
@ -122,6 +122,12 @@ var Curve = new Class({
this.getLengths(); this.getLengths();
}, },
// Given a distance in pixels, get a t to find p.
getTFromDistance: function (distance, divisions)
{
return this.getUtoTmapping(0, distance, divisions);
},
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
getUtoTmapping: function (u, distance, divisions) getUtoTmapping: function (u, distance, divisions)
@ -135,7 +141,8 @@ var Curve = new Class({
if (distance) if (distance)
{ {
targetArcLength = distance; // Cannot overshoot the curve
targetArcLength = Math.min(distance, arcLengths[il - 1]);
} }
else else
{ {