Returns true iff the record is within max_distance of the given position.
        Note: chromosome name not checked, so that's up to you to do first.
437973
def near_to_position(self, position, max_distance):
        ''''''
        end = self.ref_end_pos()
        return self.POS <= position <= end or abs(position - self.POS) <= max_distance or abs(position - end) <= max_distance
671669
function check_bounds(buf, offset, len) {
    if (offset < 0 || offset + len > buf.length) {
        throw new RangeError("Index out of range");
    }
}
13963
def is_within(self, cutoff_dist, point, ligands=True):
        """"""
        return find_atoms_within_distance(self.get_atoms(ligands=ligands), cutoff_dist, point)
377201
def distance_between(self, string, start, end):
        """"""
        count = 0
        started = False

        for line in string.split("\n"):

            if self.scan_line(line, start) and not started:
                started = True

            if self.scan_line(line, end):
                return count

            if started:
                count += 1

        return count
351996
private static final void checkComparators(int[] pos1, int[] pos2, 
							Class<? extends Key<?>>[] types1, Class<? extends Key<?>>[] types2)
	{
		if (pos1.length != pos2.length || types1.length != types2.length) {
			throw new IllegalArgumentException(
				"The given pair of RecordComparators does not operate on the same number of fields.");
		}
		for (int i = 0; i < types1.length; i++) {
			if (!types1[i].equals(types2[i])) {
				throw new IllegalArgumentException(
				"The given pair of RecordComparators does not operates on different data types.");
			}
		}
	}
964444
def distance(self, piecex, piecey):
        ''''''
        return max(abs(piecex[0] - piecey[0]), abs(piecex[1], piecey[1]))
424013
def is_within_hour_range(ref_time, start_time, end_time):
    
    str_ref_time = ref_time.strftime('%Y%m%d')
    start_time_ = mktime(strptime(str_ref_time + '-' + start_time, '%Y%m%d-%H:%M'))
    end_time_ = mktime(strptime(str_ref_time + '-' + end_time, '%Y%m%d-%H:%M'))
    ref_time_ = mktime(ref_time.timetuple())
    if start_time_ <= ref_time_ <= end_time_:
        return True
    else:
        return False
971589
private boolean
toWire(DNSOutput out, int maxLength) {
	if (maxLength < Header.LENGTH)
		return false;

	Header newheader = null;

	int tempMaxLength = maxLength;
	if (tsigkey != null)
		tempMaxLength -= tsigkey.recordLength();

	int startpos = out.current();
	header.toWire(out);
	Compression c = new Compression();
	for (int i = 0; i < 4; i++) {
		int skipped;
		if (sections[i] == null)
			continue;
		skipped = sectionToWire(out, i, c, tempMaxLength);
		if (skipped != 0) {
			if (newheader == null)
				newheader = (Header) header.clone();
			if (i != Section.ADDITIONAL)
				newheader.setFlag(Flags.TC);
			int count = newheader.getCount(i);
			newheader.setCount(i, count - skipped);
			for (int j = i + 1; j < 4; j++)
				newheader.setCount(j, 0);

			out.save();
			out.jump(startpos);
			newheader.toWire(out);
			out.restore();
			break;
		}
	}

	if (tsigkey != null) {
		TSIGRecord tsigrec = tsigkey.generate(this, out.toByteArray(),
						      tsigerror, querytsig);

		if (newheader == null)
			newheader = (Header) header.clone();
		tsigrec.toWire(out, Section.ADDITIONAL, c);
		newheader.incCount(Section.ADDITIONAL);

		out.save();
		out.jump(startpos);
		newheader.toWire(out);
		out.restore();
	}

	return true;
}
162001
def near(self, x, y, max_distance=None):
        
        expr = {
            self : {'$near' : [x, y]}
        }
        if max_distance is not None:
            expr[self]['$maxDistance'] = max_distance
        # if bucket_size is not None:
        #     expr['$bucketSize'] = max_distance
        return QueryExpression(expr)
641012
def maximum_distance(value):
    
    dic = floatdict(value)
    for trt, magdists in dic.items():
        if isinstance(magdists, list):  # could be a scalar otherwise
            magdists.sort()  # make sure the list is sorted by magnitude
            for mag, dist in magdists:  # validate the magnitudes
                magnitude(mag)
    return IntegrationDistance(dic)
1048075
def is_inside_bounds(point, bounds):
    
    if isinstance(point, (int, float)):
        point = [point]
    if isinstance(point, collections.Iterable) and not isinstance(point, collections.deque):
        if len(bounds) < 2 * len(point) or len(bounds) % 2 != 0:
            raise AssertionError('Bounds mismatch point dimensionality')
        point = collections.deque(point)
        bounds = collections.deque(bounds)
        return is_inside_bounds(point, bounds)
    if not isinstance(point, collections.deque):
        raise TypeError('Unknown input data type ({}).'.format(type(point)))
    if len(point) < 1:
        return True
    p = point.popleft()
    lower, upper = bounds.popleft(), bounds.popleft()
    if lower <= p <= upper:
        return is_inside_bounds(point, bounds)
    return False
1357123
def validate_geotweet(self, record):
        
        if record and  self._validate('user', record) \
                and self._validate('coordinates', record):
            return True
        return False
743436
def has_creep(self, pos: Union[Point2, Point3, Unit]) -> bool:
        
        assert isinstance(pos, (Point2, Point3, Unit))
        pos = pos.position.to2.rounded
        return self.state.creep[pos] != 0
480690
private boolean
toWire(DNSOutput out, int maxLength) {
	if (maxLength < Header.LENGTH)
		return false;

	Header newheader = null;

	int tempMaxLength = maxLength;
	if (tsigkey != null)
		tempMaxLength -= tsigkey.recordLength();

	OPTRecord opt = getOPT();
	byte [] optBytes = null;
        if (opt != null) {
		optBytes = opt.toWire(Section.ADDITIONAL);
		tempMaxLength -= optBytes.length;
	}

	int startpos = out.current();
	header.toWire(out);
	Compression c = new Compression();
	int flags = header.getFlagsByte();
	int additionalCount = 0;
	for (int i = 0; i < 4; i++) {
		int skipped;
		if (sections[i] == null)
			continue;
		skipped = sectionToWire(out, i, c, tempMaxLength);
		if (skipped != 0 && i != Section.ADDITIONAL) {
			flags = Header.setFlag(flags, Flags.TC, true);
			out.writeU16At(header.getCount(i) - skipped,
				       startpos + 4 + 2 * i);
			for (int j = i + 1; j < Section.ADDITIONAL; j++)
				out.writeU16At(0, startpos + 4 + 2 * j);
			break;
		}
		if (i == Section.ADDITIONAL)
			additionalCount = header.getCount(i) - skipped;
	}

	if (optBytes != null) {
		out.writeByteArray(optBytes);
		additionalCount++;
	}

	if (flags != header.getFlagsByte())
		out.writeU16At(flags, startpos + 2);

	if (additionalCount != header.getCount(Section.ADDITIONAL))
		out.writeU16At(additionalCount, startpos + 10);

	if (tsigkey != null) {
		TSIGRecord tsigrec = tsigkey.generate(this, out.toByteArray(),
						      tsigerror, querytsig);

		tsigrec.toWire(out, Section.ADDITIONAL, c);
		out.writeU16At(additionalCount + 1, startpos + 10);
	}

	return true;
}
640058
public long getNearestPosition(long recordNumber) {
        if (recordNumber < startingRecordNumber || recordNumber > lastRecordNumber)
            throw new IndexOutOfBoundsException();
        return index.get((int) ((recordNumber - startingRecordNumber) / step));
    }
807705
private boolean isLocalMaximum(double kdist, DBIDs neighbors, WritableDoubleDataStore kdists) {
    for(DBIDIter it = neighbors.iter(); it.valid(); it.advance()) {
      if(kdists.doubleValue(it) < kdist) {
        return false;
      }
    }
    return true;
  }
556006
def fix_location(records, max_elapsed_seconds=300):
    
    groups = itertools.groupby(records, lambda r: r.direction)
    groups = [(interaction, list(g)) for interaction, g in groups]

    def tdist(t1, t2):
            return abs((t1 - t2).total_seconds())

    for i, (interaction, g) in enumerate(groups):
        if interaction == 'in':
            continue

        prev_gps = groups[i-1][1][-1]
        next_gps = groups[i+1][1][0]

        for r in g:
            if tdist(r.datetime, prev_gps.datetime) <= max_elapsed_seconds:
                r.position = prev_gps.position
            elif tdist(r.datetime, next_gps.datetime) <= max_elapsed_seconds:
                r.position = next_gps.position