mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-10 20:45:35 +01:00
102 lines
2.6 KiB
Plaintext
102 lines
2.6 KiB
Plaintext
function Path() constructor {
|
|
lengthTotal = 0;
|
|
lengths = [];
|
|
lengthAccs = [];
|
|
boundary = new BoundingBox();
|
|
loop = false;
|
|
|
|
static getBoundary = function() { return boundary; }
|
|
static getAccuLength = function() { return lengthAccs; }
|
|
static getLength = function() { return lengthTotal; }
|
|
static getSegmentCount = function() { return 1; }
|
|
static getLineCount = function() { return 1; }
|
|
|
|
static getTangentRatio = function(_rat) { return 0; }
|
|
static getPointDistance = function(_seg) { return new __vec2(0, 0); }
|
|
static getPointSegment = function(_seg) { return new __vec2(0, 0); }
|
|
static getPointRatio = function(_rat) { return new __vec2(0, 0); }
|
|
}
|
|
|
|
function PathSegment() : Path() constructor {
|
|
segments = [];
|
|
|
|
static getBoundary = function() {
|
|
if(getSegmentCount() == 0) return new BoundingBox( 0, 0, 0, 0 );
|
|
|
|
var minx = segments[0].x, maxx = segments[0].x;
|
|
var miny = segments[0].y, maxy = segments[0].y;
|
|
|
|
for( var i = 0, n = array_length(segments); i < n; i++ ) {
|
|
var s = segments[i];
|
|
|
|
minx = min(minx, s.x);
|
|
maxx = max(maxx, s.x);
|
|
miny = min(miny, s.y);
|
|
maxy = max(maxy, s.y);
|
|
}
|
|
return new BoundingBox( minx, miny, maxx, maxy );
|
|
}
|
|
static getSegmentCount = function() { return array_length(segments); }
|
|
static getLineCount = function() { return 1; }
|
|
|
|
static setSegment = function(segment) {
|
|
self.segments = segment;
|
|
lengths = [];
|
|
lengthAccs = [];
|
|
lengthTotal = 0;
|
|
|
|
var op, np;
|
|
for( var i = 0, n = array_length(segment); i < n; i++ ) {
|
|
np = segment[i];
|
|
|
|
if(i) {
|
|
lengths[i] = point_distance(op.x, op.y, np.x, np.y);
|
|
lengthTotal += lengths[i];
|
|
lengthAccs[i] = lengthTotal;
|
|
}
|
|
|
|
op = np;
|
|
}
|
|
}
|
|
|
|
static getPointDistance = function(_dist) {
|
|
for( var i = 1; i < array_length(lengths); i += 1 ) {
|
|
if(_dist <= lengths[i]) {
|
|
var rat = _dist / lengths[i];
|
|
return segments[i - 1].lerpTo(segments[i], rat);
|
|
}
|
|
|
|
_dist -= lengths[i];
|
|
}
|
|
|
|
return new __vec2(0, 0);
|
|
}
|
|
|
|
static getPointSegment = function(_seg) {
|
|
var fr = (floor(_seg)) % getSegmentCount();
|
|
var to = (fr + 1) % getSegmentCount();
|
|
var st = frac(_seg);
|
|
|
|
return segments[fr].lerpTo(segments[to], st);
|
|
}
|
|
|
|
static getPointRatio = function(_rat) {
|
|
return getPointSegment(frac(_rat) * lengthTotal);
|
|
}
|
|
|
|
static getTangentRatio = function(_rat) {
|
|
_rat = frac(_rat);
|
|
var l = _rat * lengthTotal;
|
|
|
|
for( var i = 1; i < array_length(lengths); i += 1 ) {
|
|
if(l <= lengths[i]) {
|
|
var rat = l / lengths[i];
|
|
return segments[i - 1].directionTo(segments[i]);
|
|
}
|
|
|
|
l -= lengths[i];
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
} |