Like cpPolyValueOnAxis(), but for segments.
505876
function(seg, n, d)
{
    var a = vdot(n, seg.ta) - seg.r;
    var b = vdot(n, seg.tb) - seg.r;
    return min(a, b) - d;
}
301097
private Double pixelValueToValue(GriddedTile griddedTile, Double pixelValue) {

		Double value = pixelValue;

		if (griddedCoverage != null
				&& griddedCoverage.getDataType() == GriddedCoverageDataType.INTEGER) {

			if (griddedTile != null) {
				value *= griddedTile.getScale();
				value += griddedTile.getOffset();
			}
			value *= griddedCoverage.getScale();
			value += griddedCoverage.getOffset();

		}

		return value;
	}
1365274
public static void setDouble(MemorySegment[] segments, int offset, double value) {
		if (inFirstSegment(segments, offset, 8)) {
			segments[0].putDouble(offset, value);
		} else {
			setDoubleMultiSegments(segments, offset, value);
		}
	}
490139
function getIntersection(segment1, segment2) {
  var p0X = segment1[0][0];
  var p0Y = segment1[0][1];
  var p1X = segment1[1][0];
  var p1Y = segment1[1][1];
  var p2X = segment2[0][0];
  var p2Y = segment2[0][1];
  var p3X = segment2[1][0];
  var p3Y = segment2[1][1];

  var s1X, s1Y, s2X, s2Y;
  s1X = p1X - p0X;
  s1Y = p1Y - p0Y;
  s2X = p3X - p2X;
  s2Y = p3Y - p2Y;
  var s, t;
  s = (-s1Y * (p0X - p2X) + s1X * (p0Y - p2Y)) / (-s2X * s1Y + s1X * s2Y);
  t = (s2X * (p0Y - p2Y) - s2Y * (p0X - p2X)) / (-s2X * s1Y + s1X * s2Y);
  if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
    return {
      x: p0X + (t * s1X),
      y: p0Y + (t * s1Y)
    };
  }
  return null; // No collision
}
557688
def segments_touch_2D(ab, cd):
    '''
    
    '''
    return segments_colinear(ab, cd) | np.isfinite(segment_intersection_2D(ab, cd)[0])
155232
function SegmentChainer(segments, eps, buildLog){
	var chains = [];
	var regions = [];

	segments.forEach(function(seg){
		var pt1 = seg.start;
		var pt2 = seg.end;
		if (eps.pointsSame(pt1, pt2)){
			console.warn('PolyBool: Warning: Zero-length segment detected; your epsilon is ' +
				'probably too small or too large');
			return;
		}

		if (buildLog)
			buildLog.chainStart(seg);

		// search for two chains that this segment matches
		var first_match = {
			index: 0,
			matches_head: false,
			matches_pt1: false
		};
		var second_match = {
			index: 0,
			matches_head: false,
			matches_pt1: false
		};
		var next_match = first_match;
		function setMatch(index, matches_head, matches_pt1){
			// return true if we've matched twice
			next_match.index = index;
			next_match.matches_head = matches_head;
			next_match.matches_pt1 = matches_pt1;
			if (next_match === first_match){
				next_match = second_match;
				return false;
			}
			next_match = null;
			return true; // we've matched twice, we're done here
		}
		for (var i = 0; i < chains.length; i++){
			var chain = chains[i];
			var head  = chain[0];
			var head2 = chain[1];
			var tail  = chain[chain.length - 1];
			var tail2 = chain[chain.length - 2];
			if (eps.pointsSame(head, pt1)){
				if (setMatch(i, true, true))
					break;
			}
			else if (eps.pointsSame(head, pt2)){
				if (setMatch(i, true, false))
					break;
			}
			else if (eps.pointsSame(tail, pt1)){
				if (setMatch(i, false, true))
					break;
			}
			else if (eps.pointsSame(tail, pt2)){
				if (setMatch(i, false, false))
					break;
			}
		}

		if (next_match === first_match){
			// we didn't match anything, so create a new chain
			chains.push([ pt1, pt2 ]);
			if (buildLog)
				buildLog.chainNew(pt1, pt2);
			return;
		}

		if (next_match === second_match){
			// we matched a single chain

			if (buildLog)
				buildLog.chainMatch(first_match.index);

			// add the other point to the apporpriate end, and check to see if we've closed the
			// chain into a loop

			var index = first_match.index;
			var pt = first_match.matches_pt1 ? pt2 : pt1; // if we matched pt1, then we add pt2, etc
			var addToHead = first_match.matches_head; // if we matched at head, then add to the head

			var chain = chains[index];
			var grow  = addToHead ? chain[0] : chain[chain.length - 1];
			var grow2 = addToHead ? chain[1] : chain[chain.length - 2];
			var oppo  = addToHead ? chain[chain.length - 1] : chain[0];
			var oppo2 = addToHead ? chain[chain.length - 2] : chain[1];

			if (eps.pointsCollinear(grow2, grow, pt)){
				// grow isn't needed because it's directly between grow2 and pt:
				// grow2 ---grow---> pt
				if (addToHead){
					if (buildLog)
						buildLog.chainRemoveHead(first_match.index, pt);
					chain.shift();
				}
				else{
					if (buildLog)
						buildLog.chainRemoveTail(first_match.index, pt);
					chain.pop();
				}
				grow = grow2; // old grow is gone... new grow is what grow2 was
			}

			if (eps.pointsSame(oppo, pt)){
				// we're closing the loop, so remove chain from chains
				chains.splice(index, 1);

				if (eps.pointsCollinear(oppo2, oppo, grow)){
					// oppo isn't needed because it's directly between oppo2 and grow:
					// oppo2 ---oppo--->grow
					if (addToHead){
						if (buildLog)
							buildLog.chainRemoveTail(first_match.index, grow);
						chain.pop();
					}
					else{
						if (buildLog)
							buildLog.chainRemoveHead(first_match.index, grow);
						chain.shift();
					}
				}

				if (buildLog)
					buildLog.chainClose(first_match.index);

				// we have a closed chain!
				regions.push(chain);
				return;
			}

			// not closing a loop, so just add it to the apporpriate side
			if (addToHead){
				if (buildLog)
					buildLog.chainAddHead(first_match.index, pt);
				chain.unshift(pt);
			}
			else{
				if (buildLog)
					buildLog.chainAddTail(first_match.index, pt);
				chain.push(pt);
			}
			return;
		}

		// otherwise, we matched two chains, so we need to combine those chains together

		function reverseChain(index){
			if (buildLog)
				buildLog.chainReverse(index);
			chains[index].reverse(); // gee, that's easy
		}

		function appendChain(index1, index2){
			// index1 gets index2 appended to it, and index2 is removed
			var chain1 = chains[index1];
			var chain2 = chains[index2];
			var tail  = chain1[chain1.length - 1];
			var tail2 = chain1[chain1.length - 2];
			var head  = chain2[0];
			var head2 = chain2[1];

			if (eps.pointsCollinear(tail2, tail, head)){
				// tail isn't needed because it's directly between tail2 and head
				// tail2 ---tail---> head
				if (buildLog)
					buildLog.chainRemoveTail(index1, tail);
				chain1.pop();
				tail = tail2; // old tail is gone... new tail is what tail2 was
			}

			if (eps.pointsCollinear(tail, head, head2)){
				// head isn't needed because it's directly between tail and head2
				// tail ---head---> head2
				if (buildLog)
					buildLog.chainRemoveHead(index2, head);
				chain2.shift();
			}

			if (buildLog)
				buildLog.chainJoin(index1, index2);
			chains[index1] = chain1.concat(chain2);
			chains.splice(index2, 1);
		}

		var F = first_match.index;
		var S = second_match.index;

		if (buildLog)
			buildLog.chainConnect(F, S);

		var reverseF = chains[F].length < chains[S].length; // reverse the shorter chain, if needed
		if (first_match.matches_head){
			if (second_match.matches_head){
				if (reverseF){
					// <<<< F <<<< --- >>>> S >>>>
					reverseChain(F);
					// >>>> F >>>> --- >>>> S >>>>
					appendChain(F, S);
				}
				else{
					// <<<< F <<<< --- >>>> S >>>>
					reverseChain(S);
					// <<<< F <<<< --- <<<< S <<<<   logically same as:
					// >>>> S >>>> --- >>>> F >>>>
					appendChain(S, F);
				}
			}
			else{
				// <<<< F <<<< --- <<<< S <<<<   logically same as:
				// >>>> S >>>> --- >>>> F >>>>
				appendChain(S, F);
			}
		}
		else{
			if (second_match.matches_head){
				// >>>> F >>>> --- >>>> S >>>>
				appendChain(F, S);
			}
			else{
				if (reverseF){
					// >>>> F >>>> --- <<<< S <<<<
					reverseChain(F);
					// <<<< F <<<< --- <<<< S <<<<   logically same as:
					// >>>> S >>>> --- >>>> F >>>>
					appendChain(S, F);
				}
				else{
					// >>>> F >>>> --- <<<< S <<<<
					reverseChain(S);
					// >>>> F >>>> --- >>>> S >>>>
					appendChain(F, S);
				}
			}
		}
	});

	return regions;
}
956715
function(length, opt) {

        var numSegments = this.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 i;
        var segment;

        // identify the segment to divide:

        var l = 0; // length so far
        var divided;
        var dividedSegmentIndex;
        var lastValidSegment; // visible AND differentiable
        var lastValidSegmentIndex;
        var t;
        for (i = 0; i < numSegments; i++) {
            var index = (fromStart ? i : (numSegments - 1 - i));

            segment = this.getSegment(index);
            var subdivisions = segmentSubdivisions[index];
            var d = segment.length({ precision: precision, subdivisions: subdivisions });

            if (segment.isDifferentiable()) { // segment is not just a point
                lastValidSegment = segment;
                lastValidSegmentIndex = index;

                if (length <= (l + d)) {
                    dividedSegmentIndex = index;
                    divided = segment.divideAtLength(((fromStart ? 1 : -1) * (length - l)), {
                        precision: precision,
                        subdivisions: subdivisions
                    });
                    break;
                }
            }

            l += d;
        }

        if (!lastValidSegment) { // no valid segment found
            return null;
        }

        // else: the path contains at least one valid segment

        if (!divided) { // the desired length is greater than the length of the path
            dividedSegmentIndex = lastValidSegmentIndex;
            t = (fromStart ? 1 : 0);
            divided = lastValidSegment.divideAtT(t);
        }

        // create a copy of this path and replace the identified segment with its two divided parts:

        var pathCopy = this.clone();
        pathCopy.replaceSegment(dividedSegmentIndex, divided);

        var divisionStartIndex = dividedSegmentIndex;
        var divisionMidIndex = dividedSegmentIndex + 1;
        var divisionEndIndex = dividedSegmentIndex + 2;

        // do not insert the part if it looks like a point
        if (!divided[0].isDifferentiable()) {
            pathCopy.removeSegment(divisionStartIndex);
            divisionMidIndex -= 1;
            divisionEndIndex -= 1;
        }

        // insert a Moveto segment to ensure secondPath will be valid:
        var movetoEnd = pathCopy.getSegment(divisionMidIndex).start;
        pathCopy.insertSegment(divisionMidIndex, g.Path.createSegment('M', movetoEnd));
        divisionEndIndex += 1;

        // do not insert the part if it looks like a point
        if (!divided[1].isDifferentiable()) {
            pathCopy.removeSegment(divisionEndIndex - 1);
            divisionEndIndex -= 1;
        }

        // ensure that Closepath segments in secondPath will be assigned correct subpathStartSegment:

        var secondPathSegmentIndexConversion = divisionEndIndex - divisionStartIndex - 1;
        for (i = divisionEndIndex; i < pathCopy.segments.length; i++) {

            var originalSegment = this.getSegment(i - secondPathSegmentIndexConversion);
            segment = pathCopy.getSegment(i);

            if ((segment.type === 'Z') && !originalSegment.subpathStartSegment.end.equals(segment.subpathStartSegment.end)) {
                // pathCopy segment's subpathStartSegment is different from original segment's one
                // convert this Closepath segment to a Lineto and replace it in pathCopy
                var convertedSegment = g.Path.createSegment('L', originalSegment.end);
                pathCopy.replaceSegment(i, convertedSegment);
            }
        }

        // distribute pathCopy segments into two paths and return those:

        var firstPath = new Path(pathCopy.segments.slice(0, divisionMidIndex));
        var secondPath = new Path(pathCopy.segments.slice(divisionMidIndex));

        return [firstPath, secondPath];
    }
259198
def p_lvalue_partselect(self, p):
        ''
        p[0] = Lvalue(p[1], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
526104
def intersects_segment(self, seg):
		
		return any(value.intersects_segment(seg) for value in self.itervalues())
435660
def segments(seg_type=None):
    

    for index in xrange(idaapi.get_segm_qty()):
        seg = Segment(index=index)
        if (seg_type is None) or (seg.type == seg_type):
            yield Segment(index=index)
594848
def _pipe_segment_with_colons(align, colwidth):
    """"""
    w = colwidth
    if align in ["right", "decimal"]:
        return ('-' * (w - 1)) + ":"
    elif align == "center":
        return ":" + ('-' * (w - 2)) + ":"
    elif align == "left":
        return ":" + ('-' * (w - 1))
    else:
        return '-' * w
714907
function(seg, poly)
{
    var arr = [];

    var planes = poly.tPlanes;
    var numVerts = planes.length;
    
    var segD = vdot(seg.tn, seg.ta);
    var minNorm = poly.valueOnAxis(seg.tn, segD) - seg.r;
    var minNeg = poly.valueOnAxis(vneg(seg.tn), -segD) - seg.r;
    if(minNeg > 0 || minNorm > 0) return NONE;
    
    var mini = 0;
    var poly_min = segValueOnAxis(seg, planes[0].n, planes[0].d);
    if(poly_min > 0) return NONE;
    for(var i=0; i<numVerts; i++){
        var dist = segValueOnAxis(seg, planes[i].n, planes[i].d);
        if(dist > 0){
            return NONE;
        } else if(dist > poly_min){
            poly_min = dist;
            mini = i;
        }
    }
    
    var poly_n = vneg(planes[mini].n);
    
    var va = vadd(seg.ta, vmult(poly_n, seg.r));
    var vb = vadd(seg.tb, vmult(poly_n, seg.r));
    if(poly.containsVert(va.x, va.y))
        arr.push(new Contact(va, poly_n, poly_min, hashPair(seg.hashid, 0)));
    if(poly.containsVert(vb.x, vb.y))
        arr.push(new Contact(vb, poly_n, poly_min, hashPair(seg.hashid, 1)));
    
    // Floating point precision problems here.
    // This will have to do for now.
//  poly_min -= cp_collision_slop; // TODO is this needed anymore?
    
    if(minNorm >= poly_min || minNeg >= poly_min) {
        if(minNorm > minNeg)
            findPointsBehindSeg(arr, seg, poly, minNorm, 1);
        else
            findPointsBehindSeg(arr, seg, poly, minNeg, -1);
    }
    
    // If no other collision points are found, try colliding endpoints.
    if(arr.length === 0){
        var mini2 = mini * 2;
        var verts = poly.tVerts;

        var poly_a = new Vect(verts[mini2], verts[mini2+1]);
        
        var con;
        if((con = circle2circleQuery(seg.ta, poly_a, seg.r, 0, arr))) return [con];
        if((con = circle2circleQuery(seg.tb, poly_a, seg.r, 0, arr))) return [con];

        var len = numVerts * 2;
        var poly_b = new Vect(verts[(mini2+2)%len], verts[(mini2+3)%len]);
        if((con = circle2circleQuery(seg.ta, poly_b, seg.r, 0, arr))) return [con];
        if((con = circle2circleQuery(seg.tb, poly_b, seg.r, 0, arr))) return [con];
    }

//  console.log(poly.tVerts, poly.tPlanes);
//  console.log('seg2poly', arr);
    return arr;
}
821479
function divideSegment(se, p, queue)  {
    var r = new SweepEvent(p, false, se,            se.isSubject);
    var l = new SweepEvent(p, true,  se.otherEvent, se.isSubject);

    /* eslint-disable no-console */
    if (equals(se.point, se.otherEvent.point)) {

      console.warn('what is that, a collapsed segment?', se);
    }
    /* eslint-enable no-console */

    r.contourId = l.contourId = se.contourId;

    // avoid a rounding error. The left event would be processed after the right event
    if (compareEvents(l, se.otherEvent) > 0) {
      se.otherEvent.left = true;
      l.left = false;
    }

    // avoid a rounding error. The left event would be processed after the right event
    // if (compareEvents(se, r) > 0) {}

    se.otherEvent.otherEvent = l;
    se.otherEvent = r;

    queue.push(l);
    queue.push(r);

    return queue;
  }
177174
private SegmentAndOffset firstSegmentAndOffset(int segSize) {
		int segIndex = offset / segSize;
		return new SegmentAndOffset(segIndex, offset % segSize);
	}
249687
function( pfnNext )
		{
			//
			//	calculate bits value
			//
			calculateBitsValueByRoundIndexWithDeposit
			(
				oConn,
				uRoundIndex,
				fDepositBalance,
				( err, uSelfBits ) =>
				{
					if ( err )
					{
						return pfnCallback( err );
					}

					//	...
					uCurrentBitsValue = uSelfBits;
					return pfnNext();
				}
			);
		}
1013139
private void eatSplicedRange(List segments) {
        Token token = tokenizer.peekToken(0);
        if (token == null) {// ∈
            return;
        }
        switch (token.getKind()) {
            case LITERAL_STRING:
                segments.add(token.getData());
                break;
            case LSQUARE:
                tokenizer.nextToken();
                List<?> list = new ArrayList<>();
                eatRange(list);
                if (list.isEmpty()) {
                    empty = true;
                } else {
                    segments.add(list);
                }
                tokenizer.peekToken(0, TokenKind.RSQUARE);
                break;
            default:
                return;
        }
        if (tokenizer.hasMoreTokens()) {// ∈
            tokenizer.nextToken();
            eatSplicedRange(segments);
        }
    }
521043
public static void bitSet(MemorySegment[] segments, int baseOffset, int index) {
		if (segments.length == 1) {
			int offset = baseOffset + ((index & BIT_BYTE_POSITION_MASK) >>> 3);
			MemorySegment segment = segments[0];
			byte current = segment.get(offset);
			current |= (1 << (index & BIT_BYTE_INDEX_MASK));
			segment.put(offset, current);
		} else {
			bitSetMultiSegments(segments, baseOffset, index);
		}
	}