public CancellationTokenSource()
{
m_state = NOT_CANCELED;
}
public CancellationTokenSource(TimeSpan delay)
{
long totalMilliseconds = (long)delay.TotalMilliseconds;
if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue)
{
throw new ArgumentOutOfRangeException("delay");
}
InitializeWithTimer((int)totalMilliseconds);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (m_disposed)
return;
if (m_timer != null) m_timer.Dispose();
var linkingRegistrations = m_linkingRegistrations;
if (linkingRegistrations != null)
{
m_linkingRegistrations = null; // free for GC once we're done enumerating
for (int i = 0; i < linkingRegistrations.Length; i++)
{
linkingRegistrations[i].Dispose();
}
}
// registered callbacks are now either complete or will never run, due to guarantees made by ctr.Dispose()
// so we can now perform main disposal work without risk of linking callbacks trying to use this CTS.
m_registeredCallbacksLists = null; // free for GC.
if (m_kernelEvent != null)
{
m_kernelEvent.Close(); // the critical cleanup to release an OS handle
m_kernelEvent = null; // free for GC.
}
m_disposed = true;
}
}
function bezierCurveLength(x1, y1, x2, y2, x3, y3, x4, y4) {
const n = 100; // Количество сегментов для интегрирования
let length = 0;
let px = x1;
let py = y1;
for (let i = 1; i <= n; i++) {
const t = i / n;
const cx = (3 * x2 - 3 * x1) * t * t * t + (3 * x1 - 6 * x2 + 3 * x3) * t * t + (3 * x2 - 3 * x3) * t + x4 - x1;
const cy = (3 * y2 - 3 * y1) * t * t * t + (3 * y1 - 6 * y2 + 3 * y3) * t * t + (3 * y2 - 3 * y3) * t + y4 - y1;
length += Math.sqrt((cx - px) * (cx - px) + (cy - py) * (cy - py));
px = cx;
py = cy;
}
return length;
}
//Вычисляем точки на кривой безье по формуле 4х точеченой кривой
//P = (1−t)3P1 + 3(1−t)2tP2 +3(1−t)t2P3 + t3P4
//Подробнее https://learn.javascript.ru/bezier-curve
function getCordOnCurve(t,x0,y0,x1,y1,x2,y2,x3,y3){//t[0-1]
var x = Math.pow(1-t,3)*x0 + 3* Math.pow(1-t,2)*t*x1 + 3 * (1-t) * Math.pow(t,2)* x2 + Math.pow(t,3)*x3;
var y = Math.pow(1-t,3)*y0 + 3* Math.pow(1-t,2)*t*y1 + 3 * (1-t) * Math.pow(t,2)* y2 + Math.pow(t,3)*y3;
return {x:x,y:y};
}
function calcControlPoints(x0,y0,x1,y1,x2,y2,x3,y3){
//Вычисляем промежуточные точки между двумя точками, по методу Maxim Shemanarev Interpolation with Bezier Curves
//Подробнее http://agg.sourceforge.net/antigrain.com/research/bezier_interpolation/index.html
var xc1 = (x0 + x1) / 2.0;
var yc1 = (y0 + y1) / 2.0;
var xc2 = (x1 + x2) / 2.0;
var yc2 = (y1 + y2) / 2.0;
var xc3 = (x2 + x3) / 2.0;
var yc3 = (y2 + y3) / 2.0;
var len1 = Math.sqrt((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0));
var len2 = Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
var len3 = Math.sqrt((x3-x2) * (x3-x2) + (y3-y2) * (y3-y2));
var k1 = len1 / (len1 + len2);
var k2 = len2 / (len2 + len3);
var xm1 = xc1 + (xc2 - xc1) * k1;
var ym1 = yc1 + (yc2 - yc1) * k1;
var xm2 = xc2 + (xc3 - xc2) * k2;
var ym2 = yc2 + (yc3 - yc2) * k2;
var smooth_value = 1;//КОЭФИЦИЕНТ СГЛАЖИВАНИЯ ОТ 0 ДО 1
ctrl1_x = xm1 + (xc2 - xm1) * smooth_value + x1 - xm1;
ctrl1_y = ym1 + (yc2 - ym1) * smooth_value + y1 - ym1;
ctrl2_x = xm2 + (xc2 - xm2) * smooth_value + x2 - xm2;
ctrl2_y = ym2 + (yc2 - ym2) * smooth_value + y2 - ym2;
return {cx1:ctrl1_x, cy1: ctrl1_y, cx2:ctrl2_x, cy2:ctrl2_y};
}