math.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. $axure.internal(function($ax) {
  2. $ax.public.fn.matrixMultiply = function(matrix, vector) {
  3. if(!matrix.tx) matrix.tx = 0;
  4. if(!matrix.ty) matrix.ty = 0;
  5. var outX = matrix.m11 * vector.x + matrix.m12 * vector.y + matrix.tx;
  6. var outY = matrix.m21 * vector.x + matrix.m22 * vector.y + matrix.ty;
  7. return { x: outX, y: outY };
  8. }
  9. $ax.public.fn.matrixInverse = function(matrix) {
  10. if(!matrix.tx) matrix.tx = 0;
  11. if(!matrix.ty) matrix.ty = 0;
  12. var determinant = matrix.m11*matrix.m22 - matrix.m12*matrix.m21;
  13. //var threshold = (M11 * M11 + M22 *M22 + M12 *M12+ M21 *M21) / 100000;
  14. //if(determinant.DeltaEquals(0, threshold) && determinant < 0.01) {
  15. // return Invalid;
  16. //}
  17. return {
  18. m11 : matrix.m22/determinant,
  19. m12 : -matrix.m12/determinant,
  20. tx : (matrix.ty*matrix.m12 - matrix.tx*matrix.m22)/determinant,
  21. m21: -matrix.m21 / determinant,
  22. m22: matrix.m11 / determinant,
  23. ty: (matrix.tx * matrix.m21 - matrix.ty * matrix.m11) / determinant
  24. };
  25. }
  26. $ax.public.fn.matrixMultiplyMatrix = function (matrix1, matrix2) {
  27. if (!matrix1.tx) matrix1.tx = 0;
  28. if (!matrix1.ty) matrix1.ty = 0;
  29. if (!matrix2.tx) matrix2.tx = 0;
  30. if (!matrix2.ty) matrix2.ty = 0;
  31. return {
  32. m11: matrix1.m12*matrix2.m21 + matrix1.m11*matrix2.m11,
  33. m12: matrix1.m12*matrix2.m22 + matrix1.m11*matrix2.m12,
  34. tx: matrix1.m12 * matrix2.ty + matrix1.m11 * matrix2.tx + matrix1.tx,
  35. m21: matrix1.m22 * matrix2.m21 + matrix1.m21 * matrix2.m11,
  36. m22: matrix1.m22 * matrix2.m22 + matrix1.m21 * matrix2.m12,
  37. ty: matrix1.m22 * matrix2.ty + matrix1.m21 * matrix2.tx + matrix1.ty,
  38. };
  39. }
  40. $ax.public.fn.transformFromElement = function (element) {
  41. var st = window.getComputedStyle(element, null);
  42. var tr = st.getPropertyValue("-webkit-transform") ||
  43. st.getPropertyValue("-moz-transform") ||
  44. st.getPropertyValue("-ms-transform") ||
  45. st.getPropertyValue("-o-transform") ||
  46. st.getPropertyValue("transform");
  47. if (tr.indexOf('none') < 0) {
  48. var matrix = tr.split('(')[1];
  49. matrix = matrix.split(')')[0];
  50. matrix = matrix.split(',');
  51. for (var l = 0; l < matrix.length; l++) {
  52. matrix[l] = Number(matrix[l]);
  53. }
  54. } else { matrix = [1.0, 0.0, 0.0, 1.0, 0.0, 0.0]; }
  55. return matrix;
  56. // matrix[0] = cosine, matrix[1] = sine.
  57. // Assuming the element is still orthogonal.
  58. }
  59. $ax.public.fn.vectorMinus = function(vector1, vector2) { return { x: vector1.x - vector2.x, y: vector1.y - vector2.y }; }
  60. $ax.public.fn.vectorPlus = function (vector1, vector2) { return { x: vector1.x + vector2.x, y: vector1.y + vector2.y }; }
  61. $ax.public.fn.vectorMidpoint = function (vector1, vector2) { return { x: (vector1.x + vector2.x) / 2.0, y: (vector1.y + vector2.y) / 2.0 }; }
  62. $ax.public.fn.fourCornersToBasis = function (fourCorners) {
  63. return {
  64. widthVector: $ax.public.fn.vectorMinus(fourCorners.widgetTopRight, fourCorners.widgetTopLeft),
  65. heightVector: $ax.public.fn.vectorMinus(fourCorners.widgetBottomLeft, fourCorners.widgetTopLeft)
  66. };
  67. }
  68. $ax.public.fn.matrixString = function(m11, m21, m12, m22, tx, ty) {
  69. return "Matrix(" + m11 + "," + m21 + "," + m12 + "," + m22 + ", " + tx + ", " + ty + ")";
  70. }
  71. //$ax.public.fn.getWidgetBoundingRect = function (widgetId) {
  72. // var emptyRect = { left: 0, top: 0, centerPoint: { x: 0, y: 0 }, width: 0, height: 0 };
  73. // var element = document.getElementById(widgetId);
  74. // if (!element) return emptyRect;
  75. // var object = $obj(widgetId);
  76. // if (object && object.type && $ax.public.fn.IsLayer(object.type)) {
  77. // var layerChildren = _getLayerChildrenDeep(widgetId);
  78. // if (!layerChildren) return emptyRect;
  79. // else return _getBoundingRectForMultipleWidgets(layerChildren);
  80. // }
  81. // return _getBoundingRectForSingleWidget(widgetId);
  82. //};
  83. var _getLayerChildrenDeep = $ax.public.fn.getLayerChildrenDeep = function (layerId, includeLayers, includeHidden) {
  84. var deep = [];
  85. var children = $ax('#' + layerId).getChildren()[0].children;
  86. for (var index = 0; index < children.length; index++) {
  87. var childId = children[index];
  88. if(!includeHidden && !$ax.visibility.IsIdVisible(childId)) continue;
  89. if ($ax.public.fn.IsLayer($obj(childId).type)) {
  90. if (includeLayers) deep.push(childId);
  91. var recursiveChildren = _getLayerChildrenDeep(childId, includeLayers, includeHidden);
  92. for (var j = 0; j < recursiveChildren.length; j++) deep.push(recursiveChildren[j]);
  93. } else deep.push(childId);
  94. }
  95. return deep;
  96. };
  97. //var _getBoundingRectForMultipleWidgets = function (widgetsIdArray, relativeToPage) {
  98. // if (!widgetsIdArray || widgetsIdArray.constructor !== Array) return undefined;
  99. // if (widgetsIdArray.length == 0) return { left: 0, top: 0, centerPoint: { x: 0, y: 0 }, width: 0, height: 0 };
  100. // var widgetRect = _getBoundingRectForSingleWidget(widgetsIdArray[0], relativeToPage, true);
  101. // var boundingRect = { left: widgetRect.left, right: widgetRect.right, top: widgetRect.top, bottom: widgetRect.bottom };
  102. // for (var index = 1; index < widgetsIdArray.length; index++) {
  103. // widgetRect = _getBoundingRectForSingleWidget(widgetsIdArray[index], relativeToPage);
  104. // boundingRect.left = Math.min(boundingRect.left, widgetRect.left);
  105. // boundingRect.top = Math.min(boundingRect.top, widgetRect.top);
  106. // boundingRect.right = Math.max(boundingRect.right, widgetRect.right);
  107. // boundingRect.bottom = Math.max(boundingRect.bottom, widgetRect.bottom);
  108. // }
  109. // boundingRect.centerPoint = { x: (boundingRect.right + boundingRect.left) / 2.0, y: (boundingRect.bottom + boundingRect.top) / 2.0 };
  110. // boundingRect.width = boundingRect.right - boundingRect.left;
  111. // boundingRect.height = boundingRect.bottom - boundingRect.top;
  112. // return boundingRect;
  113. //};
  114. //var _getBoundingRectForSingleWidget = function (widgetId, relativeToPage, justSides) {
  115. // var element = document.getElementById(widgetId);
  116. // var boundingRect, tempBoundingRect, position;
  117. // var displayChanged = _displayHackStart(element);
  118. // if (_isCompoundVectorHtml(element)) {
  119. // //tempBoundingRect = _getCompoundImageBoundingClientSize(widgetId);
  120. // //position = { left: tempBoundingRect.left, top: tempBoundingRect.top };
  121. // position = $(element).position();
  122. // tempBoundingRect = {};
  123. // tempBoundingRect.left = position.left; //= _getCompoundImageBoundingClientSize(widgetId);
  124. // tempBoundingRect.top = position.top;
  125. // tempBoundingRect.width = Number(element.getAttribute('data-width'));
  126. // tempBoundingRect.height = Number(element.getAttribute('data-height'));
  127. // } else {
  128. // var boundingElement = element;
  129. // if($ax.dynamicPanelManager.isIdFitToContent(widgetId)) {
  130. // var stateId = $ax.visibility.GetPanelState(widgetId);
  131. // if(stateId != '') boundingElement = document.getElementById(stateId);
  132. // }
  133. // tempBoundingRect = boundingElement.getBoundingClientRect();
  134. // var jElement = $(element);
  135. // position = jElement.position();
  136. // if(jElement.css('position') == 'fixed') {
  137. // position.left += Number(jElement.css('margin-left').replace("px", ""));
  138. // position.top += Number(jElement.css('margin-top').replace("px", ""));
  139. // }
  140. // }
  141. // var layers = $ax('#' + widgetId).getParents(true, ['layer'])[0];
  142. // var flip = '';
  143. // var mirrorWidth = 0;
  144. // var mirrorHeight = 0;
  145. // for (var i = 0; i < layers.length; i++) {
  146. // //should always be 0,0
  147. // var layerPos = $jobj(layers[i]).position();
  148. // position.left += layerPos.left;
  149. // position.top += layerPos.top;
  150. // var outer = $ax.visibility.applyWidgetContainer(layers[i], true, true);
  151. // if (outer.length) {
  152. // var outerPos = outer.position();
  153. // position.left += outerPos.left;
  154. // position.top += outerPos.top;
  155. // }
  156. // //when a group is flipped we find the unflipped position
  157. // var inner = $jobj(layers[i] + '_container_inner');
  158. // var taggedFlip = inner.data('flip');
  159. // if (inner.length && taggedFlip) {
  160. // //only account for flip if transform is applied
  161. // var matrix = taggedFlip && (inner.css("-webkit-transform") || inner.css("-moz-transform") ||
  162. // inner.css("-ms-transform") || inner.css("-o-transform") || inner.css("transform"));
  163. // if (matrix !== 'none') {
  164. // flip = taggedFlip;
  165. // mirrorWidth = $ax.getNumFromPx(inner.css('width'));
  166. // mirrorHeight = $ax.getNumFromPx(inner.css('height'));
  167. // }
  168. // }
  169. // }
  170. // //Now account for flip
  171. // if (flip == 'x') position.top = mirrorHeight - position.top - element.getBoundingClientRect().height;
  172. // else if (flip == 'y') position.left = mirrorWidth - position.left - element.getBoundingClientRect().width;
  173. // boundingRect = {
  174. // left: position.left,
  175. // right: position.left + tempBoundingRect.width,
  176. // top: position.top,
  177. // bottom: position.top + tempBoundingRect.height
  178. // };
  179. // _displayHackEnd(displayChanged);
  180. // if (justSides) return boundingRect;
  181. // boundingRect.width = boundingRect.right - boundingRect.left;
  182. // boundingRect.height = boundingRect.bottom - boundingRect.top;
  183. // boundingRect.centerPoint = {
  184. // x: boundingRect.width / 2 + boundingRect.left,
  185. // y: boundingRect.height / 2 + boundingRect.top
  186. // };
  187. // return boundingRect;
  188. //};
  189. var _getPointAfterRotate = $ax.public.fn.getPointAfterRotate = function (angleInDegrees, pointToRotate, centerPoint) {
  190. var displacement = $ax.public.fn.vectorMinus(pointToRotate, centerPoint);
  191. var rotationMatrix = $ax.public.fn.rotationMatrix(angleInDegrees);
  192. rotationMatrix.tx = centerPoint.x;
  193. rotationMatrix.ty = centerPoint.y;
  194. return $ax.public.fn.matrixMultiply(rotationMatrix, displacement);
  195. };
  196. $ax.public.fn.getBoundingSizeForRotate = function(width, height, rotation) {
  197. // point to rotate around doesn't matter since we just care about size, if location matter we need more args and location matters.
  198. var origin = { x: 0, y: 0 };
  199. var corner1 = { x: width, y: 0 };
  200. var corner2 = { x: 0, y: height };
  201. var corner3 = { x: width, y: height };
  202. corner1 = _getPointAfterRotate(rotation, corner1, origin);
  203. corner2 = _getPointAfterRotate(rotation, corner2, origin);
  204. corner3 = _getPointAfterRotate(rotation, corner3, origin);
  205. var left = Math.min(0, corner1.x, corner2.x, corner3.x);
  206. var right = Math.max(0, corner1.x, corner2.x, corner3.x);
  207. var top = Math.min(0, corner1.y, corner2.y, corner3.y);
  208. var bottom = Math.max(0, corner1.y, corner2.y, corner3.y);
  209. return { width: right - left, height: bottom - top };
  210. }
  211. $ax.public.fn.getBoundingRectForRotate = function (boundingRect, rotation) {
  212. var centerPoint = boundingRect.centerPoint;
  213. var corner1 = { x: boundingRect.left, y: boundingRect.top };
  214. var corner2 = { x: boundingRect.right, y: boundingRect.top };
  215. var corner3 = { x: boundingRect.right, y: boundingRect.bottom };
  216. var corner4 = { x: boundingRect.left, y: boundingRect.bottom };
  217. corner1 = _getPointAfterRotate(rotation, corner1, centerPoint);
  218. corner2 = _getPointAfterRotate(rotation, corner2, centerPoint);
  219. corner3 = _getPointAfterRotate(rotation, corner3, centerPoint);
  220. corner4 = _getPointAfterRotate(rotation, corner4, centerPoint);
  221. var left = Math.min(corner1.x, corner2.x, corner3.x, corner4.x);
  222. var right = Math.max(corner1.x, corner2.x, corner3.x, corner4.x);
  223. var top = Math.min(corner1.y, corner2.y, corner3.y, corner4.y);
  224. var bottom = Math.max(corner1.y, corner2.y, corner3.y, corner4.y);
  225. return { left: left, top: top, width: right - left, height: bottom - top };
  226. }
  227. //$ax.public.fn.getPositionRelativeToParent = function (elementId) {
  228. // var element = document.getElementById(elementId);
  229. // var list = _displayHackStart(element);
  230. // var position = $(element).position();
  231. // _displayHackEnd(list);
  232. // return position;
  233. //};
  234. //var _displayHackStart = $ax.public.fn.displayHackStart = function (element) {
  235. // // TODO: Options: 1) stop setting display none. Big change for this late in the game. 2) Implement our own bounding.
  236. // // TODO: 3) Current method is look for any parents that are set to none, and and temporarily unblock. Don't like it, but it works.
  237. // var parent = element;
  238. // var displays = [];
  239. // while (parent) {
  240. // if (parent.style.display == 'none') {
  241. // displays.push(parent);
  242. // //use block to overwrites default hidden objects' display
  243. // parent.style.display = 'block';
  244. // }
  245. // parent = parent.parentElement;
  246. // }
  247. // return displays;
  248. //};
  249. //var _displayHackEnd = $ax.public.fn.displayHackEnd = function (displayChangedList) {
  250. // for (var i = 0; i < displayChangedList.length; i++) displayChangedList[i].style.display = 'none';
  251. //};
  252. var _isCompoundVectorHtml = $ax.public.fn.isCompoundVectorHtml = function(hElement) {
  253. return hElement.hasAttribute('compoundmode') && hElement.getAttribute('compoundmode') == "true";
  254. }
  255. $ax.public.fn.removeCompound = function (jobj) { if(_isCompoundVectorHtml(jobj[0])) jobj.removeClass('compound'); }
  256. $ax.public.fn.restoreCompound = function (jobj) { if (_isCompoundVectorHtml(jobj[0])) jobj.addClass('compound'); }
  257. $ax.public.fn.compoundIdFromComponent = function(id) {
  258. var pPos = id.indexOf('p');
  259. var dashPos = id.indexOf('-');
  260. if (pPos < 1) return id;
  261. else if (dashPos < 0) return id.substring(0, pPos);
  262. else return id.substring(0, pPos) + id.substring(dashPos);
  263. }
  264. $ax.public.fn.l2 = function (x, y) { return Math.sqrt(x * x + y * y); }
  265. $ax.public.fn.convertToSingleImage = function (jobj) {
  266. if(!jobj[0]) return;
  267. var widgetId = jobj[0].id;
  268. var object = $obj(widgetId);
  269. if ($ax.public.fn.IsLayer(object.type)) {
  270. var recursiveChildren = _getLayerChildrenDeep(widgetId, true);
  271. for (var j = 0; j < recursiveChildren.length; j++)
  272. $ax.public.fn.convertToSingleImage($jobj(recursiveChildren[j]));
  273. return;
  274. }
  275. //var layer =
  276. if(!_isCompoundVectorHtml(jobj[0])) return;
  277. $('#' + widgetId).removeClass("compound");
  278. $('#' + widgetId + '_img').removeClass("singleImg");
  279. $('#' + widgetId + '_div').removeClass("singleImg");
  280. jobj[0].setAttribute('compoundmode', 'false');
  281. var components = object.compoundChildren;
  282. delete object.generateCompound;
  283. if(!components) return;
  284. for (var i = 0; i < components.length; i++) {
  285. var componentJobj = $jobj($ax.public.fn.getComponentId(widgetId, components[i]));
  286. componentJobj.css('display', 'none');
  287. componentJobj.css('visibility', 'hidden');
  288. }
  289. }
  290. $ax.public.fn.getContainerDimensions = function(query) {
  291. // returns undefined if no containers found.
  292. var containerDimensions;
  293. for (var i = 0; i < query[0].children.length; i++) {
  294. var node = query[0].children[i];
  295. if (node.id.indexOf(query[0].id) >= 0 && node.id.indexOf('container') >= 0) {
  296. containerDimensions = node.style;
  297. }
  298. }
  299. return containerDimensions;
  300. }
  301. $ax.public.fn.rotationMatrix = function (angleInDegrees) {
  302. var angleInRadians = angleInDegrees * (Math.PI / 180);
  303. var cosTheta = Math.cos(angleInRadians);
  304. var sinTheta = Math.sin(angleInRadians);
  305. return { m11: cosTheta, m12: -sinTheta, m21: sinTheta, m22: cosTheta, tx: 0.0, ty: 0.0 };
  306. }
  307. $ax.public.fn.GetFieldFromStyle = function (query, field) {
  308. var raw = query[0].style[field];
  309. if (!raw) raw = query.css(field);
  310. return Number(raw.replace('px', ''));
  311. }
  312. $ax.public.fn.setTransformHowever = function (transformString) {
  313. return {
  314. '-webkit-transform': transformString,
  315. '-moz-transform': transformString,
  316. '-ms-transform': transformString,
  317. '-o-transform': transformString,
  318. 'transform': transformString
  319. };
  320. }
  321. $ax.public.fn.inversePathLengthFunction = function (pathFunction) {
  322. // these are for computing the inverse functions of path integrals.
  323. var makeDivisionNode = function(node1, node2) {
  324. var param = 0.5 * (node1.Param + node2.Param);
  325. var inBetweenNode = {
  326. LowerStop: node1,
  327. HigherStop: node2,
  328. Param: param,
  329. Position: pathFunction(param),
  330. Cumulative: 0.0
  331. };
  332. var lowerDisplacement = $ax.public.fn.vectorMinus(node1.Position, inBetweenNode.Position);
  333. inBetweenNode.LowerInterval = {
  334. Length: $ax.public.fn.l2(lowerDisplacement.x, lowerDisplacement.y),
  335. Node: inBetweenNode,
  336. IsHigher: false
  337. };
  338. var higherDisplacement = $ax.public.fn.vectorMinus(node2.Position, inBetweenNode.Position);
  339. inBetweenNode.HigherInterval = {
  340. Length: $ax.public.fn.l2(higherDisplacement.x, higherDisplacement.y),
  341. Node: inBetweenNode,
  342. IsHigher: true
  343. };
  344. return inBetweenNode;
  345. };
  346. var expandLower = function(node) {
  347. node.LowerChild = makeDivisionNode(node.LowerStop, node);
  348. node.LowerChild.Parent = node;
  349. };
  350. var expandHigher = function(node) {
  351. node.HigherChild = makeDivisionNode(node, node.HigherStop);
  352. node.HigherChild.Parent = node;
  353. };
  354. // for this function, cumulative is a global variable
  355. var cumulative = 0.0;
  356. var labelCumulativeLength = function(node) {
  357. if(!node.LowerChild) {
  358. node.LowerStop.Cumulative = cumulative;
  359. cumulative += node.LowerInterval.Length;
  360. node.Cumulative = cumulative;
  361. } else labelCumulativeLength(node.LowerChild);
  362. if(!node.HigherChild) {
  363. node.Cumulative = cumulative;
  364. cumulative += node.HigherInterval.Length;
  365. node.HigherStop.Cumulative = cumulative;
  366. } else labelCumulativeLength(node.HigherChild);
  367. };
  368. var getIntervalFromPathLength = function(node, length) {
  369. if(length < node.Cumulative) {
  370. return node.LowerChild ? getIntervalFromPathLength(node.LowerChild, length) : node.LowerInterval;
  371. } else return node.HigherChild ? getIntervalFromPathLength(node.HigherChild, length) : node.HigherInterval;
  372. };
  373. var intervalLowerEnd = function(interval) {
  374. return interval.IsHigher ? interval.Node : interval.Node.LowerStop;
  375. };
  376. var intervalHigherEnd = function(interval) {
  377. return interval.IsHigher ? interval.Node.HigherStop : interval.Node;
  378. };
  379. var getParameterFromPathLength = function (node, length) {
  380. var interval = getIntervalFromPathLength(node, length);
  381. var lowerNode = intervalLowerEnd(interval);
  382. var higherNode = intervalHigherEnd(interval);
  383. return lowerNode.Param + (higherNode.Param - lowerNode.Param) * (length - lowerNode.Cumulative) / (higherNode.Cumulative - lowerNode.Cumulative);
  384. };
  385. var insertIntoSortedList = function (longer, shorter, toInsert) {
  386. while (true) {
  387. if (!longer) {
  388. longer = shorter;
  389. shorter = shorter.NextLongest;
  390. continue;
  391. } else if (!shorter) longer.NextLongest = toInsert;
  392. else {
  393. if (longer.Length >= toInsert.Length && shorter.Length <= toInsert.Length) {
  394. longer.NextLongest = toInsert;
  395. toInsert.NextLongest = shorter;
  396. } else {
  397. longer = shorter;
  398. shorter = shorter.NextLongest;
  399. continue;
  400. }
  401. }
  402. break;
  403. }
  404. }
  405. var head = {Param: 0.0, Position: pathFunction(0.0) };
  406. var tail = { Param: 1.0, Position: pathFunction(1.0) };
  407. var root = makeDivisionNode(head, tail);
  408. var currentCurveLength = root.LowerInterval.Length + root.HigherInterval.Length;
  409. var longestInterval;
  410. if (root.LowerInterval.Length < root.HigherInterval.Length) {
  411. longestInterval = root.HigherInterval;
  412. longestInterval.NextLongest = root.LowerInterval;
  413. } else {
  414. longestInterval = root.LowerInterval;
  415. longestInterval.NextLongest = root.HigherInterval;
  416. }
  417. while (longestInterval.Length * 100.0 > currentCurveLength) {
  418. var newNode;
  419. if (longestInterval.IsHigher) {
  420. expandHigher(longestInterval.Node);
  421. newNode = longestInterval.Node.HigherChild;
  422. } else {
  423. expandLower(longestInterval.Node);
  424. newNode = longestInterval.Node.LowerChild;
  425. }
  426. currentCurveLength += (newNode.LowerInterval.Length + newNode.HigherInterval.Length - longestInterval.Length);
  427. insertIntoSortedList(null, longestInterval, newNode.LowerInterval);
  428. insertIntoSortedList(null, longestInterval, newNode.HigherInterval);
  429. longestInterval = longestInterval.NextLongest;
  430. }
  431. labelCumulativeLength(root);
  432. return function(lengthParam) {
  433. return getParameterFromPathLength(root, lengthParam * cumulative);
  434. };
  435. }
  436. });