/*
抽取pathSegment中的关键点
M,L,A,Q,H,V一个端点
Q, S抽取一个端点，一个控制点
C抽取一个端点，两个控制点
357267
function _getSegmentPoints(segment) {
  var points = [];
  switch (segment[0]) {
    case 'M':
      points.push([segment[1], segment[2]]);
      break;
    case 'L':
      points.push([segment[1], segment[2]]);
      break;
    case 'A':
      points.push([segment[6], segment[7]]);
      break;
    case 'Q':
      points.push([segment[3], segment[4]]);
      points.push([segment[1], segment[2]]);
      break;
    case 'T':
      points.push([segment[1], segment[2]]);
      break;
    case 'C':
      points.push([segment[5], segment[6]]);
      points.push([segment[1], segment[2]]);
      points.push([segment[3], segment[4]]);
      break;
    case 'S':
      points.push([segment[3], segment[4]]);
      points.push([segment[1], segment[2]]);
      break;
    case 'H':
      points.push([segment[1], segment[1]]);
      break;
    case 'V':
      points.push([segment[1], segment[1]]);
      break;
    default:

  }
  return points;
}
1291735
private static List<Segmentation> getSegmentations(String str, int begin, int end, int nbMaxComponents, int minComponentSize, List<CuttingPoint> cuttingPoints) {
		List<Segmentation> s = new ArrayList<Segmentation>(nbMaxComponents);
		for(CuttingPoint cp:getPossibleCuttingPoints(str, begin, end, nbMaxComponents, minComponentSize)) {
			s.add(new Segmentation(str, addToDuplicate(cuttingPoints, cp, nbMaxComponents - 1)));
			if(nbMaxComponents > 2) {
				if(cp.isHypen())
					// recursivity on the left part only if the cp was an hypen
					if((cp.getIndex() - begin) >= 2*minComponentSize)
						s.addAll(getSegmentations(str, begin, cp.getIndex(), nbMaxComponents -1, minComponentSize, addToDuplicate(cuttingPoints, cp, nbMaxComponents - 1)));
				
				if((end - (cp.getIndex() + cp.getOffset())) >= 2*minComponentSize)
					s.addAll(getSegmentations(str, cp.getIndex() + cp.getOffset(), end, nbMaxComponents -1, minComponentSize, addToDuplicate(cuttingPoints, cp, nbMaxComponents - 1)));
			}
		}
		return s;
	}
514131
public SDVariable unsortedSegmentSqrtN(SDVariable data, SDVariable segmentIds, int numSegments) {
        return unsortedSegmentSqrtN(null, data, segmentIds, numSegments);
    }
1303723
private static int copyPathFragment(char[] input, int beginIndex, StringBuilder output)
	{
		int inputCharIndex = beginIndex;
		while (inputCharIndex < input.length)
		{
			final char inputChar = input[inputCharIndex];
			if (inputChar == '/')
			{
				break;
			}

			output.append(inputChar);
			inputCharIndex += 1;
		}

		return inputCharIndex;
	}
864704
function _removeDotSegments(path, hasAuthority) {
  var rval = '';

  if(path.indexOf('/') === 0) {
    rval = '/';
  }

  // RFC 3986 5.2.4 (reworked)
  var input = path.split('/');
  var output = [];
  while(input.length > 0) {
    if(input[0] === '.' || (input[0] === '' && input.length > 1)) {
      input.shift();
      continue;
    }
    if(input[0] === '..') {
      input.shift();
      if(hasAuthority ||
        (output.length > 0 && output[output.length - 1] !== '..')) {
        output.pop();
      }
      // leading relative URL '..'
      else {
        output.push('..');
      }
      continue;
    }
    output.push(input.shift());
  }

  return rval + output.join('/');
}
471341
private Set<LineString> getSegments(Collection<LineString> lines) {
        Set<LineString> set = new HashSet<>();
        for (LineString line : lines) {
            Coordinate[] cc = line.getCoordinates();
            for (int i = 1; i < cc.length; i++) {
                if (!cc[i - 1].equals(cc[i])) {
                    LineString segment = line.getFactory().createLineString(
                            new Coordinate[]{new Coordinate(cc[i - 1]), new Coordinate(cc[i])});
                    set.add(segment);
                }
            }
        }
        return set;
    }
277230
function normalizePathParts(parts) {

        // IMPORTANT: It is assumed that parts[0] === "" because this method is used to
        // join an absolute path to a relative path
        var i;
        var len = 0;

        var numParts = parts.length;

        for (i = 0; i < numParts; i++) {
            var part = parts[i];

            if (part === '.') {
                // ignore parts with just "."
                /*
                // if the "." is at end of parts (e.g. ["a", "b", "."]) then trim it off
                if (i === numParts - 1) {
                    //len--;
                }
                */
            } else if (part === '..') {
                // overwrite the previous item by decrementing length
                len--;
            } else {
                // add this part to result and increment length
                parts[len] = part;
                len++;
            }
        }

        if (len === 1) {
            // if we end up with just one part that is empty string
            // (which can happen if input is ["", "."]) then return
            // string with just the leading slash
            return '/';
        } else if (len > 2) {
            // parts i s
            // ["", "a", ""]
            // ["", "a", "b", ""]
            if (parts[len - 1].length === 0) {
                // last part is an empty string which would result in trailing slash
                len--;
            }
        }

        // truncate parts to remove unused
        parts.length = len;
        return parts.join('/');
    }
575328
function parseSliceString(path, l) {
  var _path$split$map = path.split(':').map(function (s) {
    return parseNumber(s);
  }),
      _path$split$map2 = _slicedToArray(_path$split$map, 3),
      start = _path$split$map2[0],
      end = _path$split$map2[1],
      step = _path$split$map2[2];
  // 异常的时候默认值


  start = isNaN(start) ? 0 : start < 0 ? l + start : start;

  end = isNaN(end) ? l : end < 0 ? l + end : // 小于 0 转成正数
  end > l ? l : end; // 最大为长度

  step = isNaN(step) ? 1 : step;

  invariant(step !== 0, 'Step can not be zero!');

  return [start, end, step];
}
605981
private String getSubPath(String[] pathElements, int begin) {

        String result = "";
        for (int i = begin; i < pathElements.length; i++) {
            result += pathElements[i] + "/";
        }
        if (result.length() > 0) {
            result = result.substring(0, result.length() - 1);
        }
        return result;
    }
749079
function(length, opt) {

            var segments = this.segments;
            var numSegments = segments.length;
            if (numSegments === 0) return null; // if segments is an empty array

            var fromStart = true;
            if (length < 0) {
                fromStart = false; // negative lengths mean start calculation from end point
                length = -length; // absolute value
            }

            opt = opt || {};
            var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
            var segmentSubdivisions = (opt.segmentSubdivisions === undefined) ? this.getSegmentSubdivisions({ precision: precision }) : opt.segmentSubdivisions;
            // not using localOpt

            var lastVisibleSegmentIndex = null;
            var l = 0; // length so far
            for (var i = (fromStart ? 0 : (numSegments - 1)); (fromStart ? (i < numSegments) : (i >= 0)); (fromStart ? (i++) : (i--))) {

                var segment = segments[i];
                var subdivisions = segmentSubdivisions[i];
                var d = segment.length({ precision: precision, subdivisions: subdivisions });

                if (segment.isVisible) {
                    if (length <= (l + d)) return i;
                    lastVisibleSegmentIndex = i;
                }

                l += d;
            }

            // if length requested is higher than the length of the path, return last visible segment index
            // if no visible segment, return null
            return lastVisibleSegmentIndex;
        }
1182489
function join(/*varags*/) {
	var segs = Array.prototype.slice.call(arguments);
	var path = [];
	for (var i=0; i < segs.length; i++) {
		var segment = segs[i];
		// This is kind of cheesy: avoid double-slashes
		var last = segment.length-1;
		if (i > 0 && segment[0] === '/') segment = segment.substring(1);
		if (segment[last] === '/') segment = segment.substring(0, last);
		path.push(segment);
	}
	return path.join('/');
}
292422
function buildSegmentRows(segments) {
		var rowCnt = getRowCnt();
		var segmentRows = [];
		var segmentI;
		var segment;
		var rowI;

		// group segments by row
		for (segmentI=0; segmentI<segments.length; segmentI++) {
			segment = segments[segmentI];
			rowI = segment.row;
			if (segment.element) { // was rendered?
				if (segmentRows[rowI]) {
					// already other segments. append to array
					segmentRows[rowI].push(segment);
				}
				else {
					// first segment in row. create new array
					segmentRows[rowI] = [ segment ];
				}
			}
		}

		// sort each row
		for (rowI=0; rowI<rowCnt; rowI++) {
			segmentRows[rowI] = sortSegmentRow(
				segmentRows[rowI] || [] // guarantee an array, even if no segments
			);
		}

		return segmentRows;
	}
327442
function path() {
  var p = _.random(1);
  var words = choose(above);

  words += fragment(s[p], (choose(trans)+s[(p+1)%2]));

  words += ['', 'the', choose(below)].join(' ') + choose(s) + ".";
  return words;
}
288048
public SDVariable unsortedSegmentProd(SDVariable data, SDVariable segmentIds, int numSegments) {
        return unsortedSegmentProd(null, data, segmentIds, numSegments);
    }
710221
function path2contours(path) {

        if (!path || !path.length) {
            return null;
        }

        path = path.trim();

        // 修正头部不为`m`的情况
        if (path[0] !== 'M' && path[0] !== 'm') {
            path = 'M 0 0' + path;
        }

        // 修复中间没有结束符`z`的情况
        path = path.replace(/(\d+)\s*(m|$)/gi, '$1z$2');

        // 获取segments
        var segments = [];
        var cmd;
        var relative = false;
        var lastIndex;
        var args;

        for (var i = 0, l = path.length; i < l; i++) {
            var c = path[i].toUpperCase();
            var r = c !== path[i];

            switch (c) {
                case 'M':
                    /*jshint -W086 */
                    if (i === 0) {
                        cmd = c;
                        lastIndex = 1;
                        break;
                    }
                case 'Q':
                case 'T':
                case 'C':
                case 'S':
                case 'H':
                case 'V':
                case 'L':
                case 'A':
                case 'Z':
                    if (cmd === 'Z') {
                        segments.push({cmd: 'Z'});
                    }
                    else {
                        args = path.slice(lastIndex, i);
                        segments.push({
                            cmd: cmd,
                            relative: relative,
                            args: parseParams(args)
                        });
                    }

                    cmd = c;
                    relative = r;
                    lastIndex = i + 1;
                    break;

            }
        }

        segments.push({cmd: 'Z'});

        return segments2Contours(segments);
    }
902575
function splitUpParagraph(segment, resultStr, stack, tokens, tokenIndex) {
	let startOfWord = resultStr.indexOf(stack[0].complete) + 1;
	let textBeforeSelected = resultStr.slice(0, startOfWord);
	let startToken = tokens[2][tokenIndex];
	let selected = resultStr.slice(startOfWord + segment.length - 1, resultStr.indexOf(segment));
	let endToken = tokens[3][tokenIndex];
	let textAfterSelected = resultStr.slice(resultStr.indexOf(segment) + segment.length - 1);
	return textBeforeSelected + startToken + selected + endToken + textAfterSelected;
}
72470
function(index) {

            var segments = this.segments;
            var numSegments = segments.length;
            if (numSegments === 0) throw new Error('Path has no segments.');

            if (index < 0) index = numSegments + index; // convert negative indices to positive
            if (index >= numSegments || index < 0) throw new Error('Index out of range.');

            var removedSegment = segments.splice(index, 1)[0];
            var previousSegment = removedSegment.previousSegment;
            var nextSegment = removedSegment.nextSegment;

            // link the previous and next segments together (if present)
            if (previousSegment) previousSegment.nextSegment = nextSegment; // may be null
            if (nextSegment) nextSegment.previousSegment = previousSegment; // may be null

            // if removed segment used to start a subpath, update all subsequent segments until another subpath start segment is reached
            if (removedSegment.isSubpathStart && nextSegment) this.updateSubpathStartSegment(nextSegment);
        }