/* returns tile number between 0 and 8
returns - 1 if out of any tile, function does
not depend on objFct!
549361
public int findTileSYMPART(double x1, double x2)
   {
      int dim;
      double[] x = new double[2];
      double h1;
      double omega =  Math.PI / 4.0;
      double si = Math.sin(omega);
      double co = Math.cos(omega);
      x[0] = x1;
      x[1] = x2;
      //rotate( 2, x );
      for( dim=0; dim+1 < 2; dim+=2 )
      {
         h1 = x[dim];
         x[dim] = co * h1 - si * x[dim+1];
         x[dim+1] = si * h1 + co * x[dim+1];
      }
      TupleTwo<Integer, Integer> tt = findTile(x[0], x[1]);
      int i = tt._1();
      int j = tt._2();
      // restrict to 9 tiles
      if (Math.abs(i) > 1 || Math.abs(j) > 1) return -1;
      return (i + 1) * 3 + (j + 1);
   }
170028
public Double getValue(GriddedTile griddedTile, short pixelValue) {
		int unsignedPixelValue = getUnsignedPixelValue(pixelValue);
		Double value = getValue(griddedTile, unsignedPixelValue);
		return value;
	}
774300
function() {
        if (arguments.length > 0) {
            var bounds = this.adjustBounds(arguments[0]);
            var res = this.getServerResolution();
            var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
            var y = Math.round((this.tileOrigin.lat - bounds.top) / (res * this.tileSize.h));
            var z = this.getZoomForResolution( res );
            var w = this.standardTileSize;
            var h = this.standardTileSize;
            if (x == this.tierSizeInTiles[z].w -1 ) {
                var w = this.tierImageSize[z].w % this.standardTileSize;
            }
            if (y == this.tierSizeInTiles[z].h -1 ) {
                var h = this.tierImageSize[z].h % this.standardTileSize;
            }
            return (new OpenLayers.Size(w, h));
        } else {
            return this.tileSize;
        }
    }
210498
private int calcFuByJanto() {
        Tile jantoTile = comp.getJanto().getTile();
        int tmp = 0;
        if (jantoTile == generalSituation.getBakaze()) {
            tmp += 2;
        }
        if (jantoTile == personalSituation.getJikaze()) {
            tmp += 2;
        }
        if (jantoTile.getType() == SANGEN) {
            tmp += 2;
        }
        return tmp;
    }
982366
private long getPixelNumber(long fileOffset) {
		assert fileOffset >= 0;
		long result = Math.round(fileOffset / bytesPerPixel());
		assert result >= 0;
		return result;
	}
299253
function getLithuanianForm (c) {
    if (c === 1 || (c % 10 === 1 && c % 100 > 20)) {
      return 0
    } else if (Math.floor(c) !== c || (c % 10 >= 2 && c % 100 > 20) || (c % 10 >= 2 && c % 100 < 10)) {
      return 1
    } else {
      return 2
    }
  }
1254807
function getIntFromBuffer (buffer, start, end) {
  var sum = 0
  var sign = 1

  for (var i = start; i < end; i++) {
    var num = buffer[i]

    if (num < 58 && num >= 48) {
      sum = sum * 10 + (num - 48)
      continue
    }

    if (i === start && num === 43) { // +
      continue
    }

    if (i === start && num === 45) { // -
      sign = -1
      continue
    }

    if (num === 46) { // .
      // its a float. break here.
      break
    }

    throw new Error('not a number: buffer[' + i + '] = ' + num)
  }

  return sum * sign
}
471365
function numClose(x, y) {
  return (Number.isNaN(x) && Number.isNaN(y)) ||
    Math.abs(x - y) <= 1e-7;
}
354727
function getFuzzyTimezoneFromTile(tile) {
  if (tile[2] === z) {
    var key = tile.join('/');
    if (key in tiles) return tiles[key];
    else throw new Error('tile not found');

  } else if (tile[2] > z) {
    // higher zoom level (9, 10, 11, ...)
    key = _getParent(tile).join('/');
    if (key in tiles) return tiles[key];
    else throw new Error('tile not found');

  } else {
    // lower zoom level (..., 5, 6, 7)
    var children = _getChildren(tile);
    var votes = [];  // list of timezone abbrevations
    var abbrs = {};  // abbrevation to full name lookup table
    children.forEach(function(child) {
      key = child.join('/');
      if (key in tiles) {
        var tz = tiles[key];   // timezone name

        // Need to use timezone abbreviation becuase e.g. America/Los_Angeles
        // and America/Vancouver are the same. Use a time to determine the
        // abbreviation, in case two similar tz have slightly different
        // daylight savings schedule.
        var abbr = moment.tz(Date.now(), tz)._z.abbrs[0];
        votes.push(abbr);
        abbrs[abbr] = tz;
      }
    });

    if (votes.length > 1) return abbrs[ss.mode(votes)];
    else throw new Error('tile not found');
  }
}
777297
function getLastNumber(str){
					var retval="";
					for (var i=str.length-1;i>=0;--i)
						if (str[i]>="0"&&str[i]<="9")
							retval=str[i]+retval;
					if (retval.length==0) return "0";
					return retval;
				}
1349951
public int getTileSetID (String tileSetName)
        throws PersistenceException
    {
        Integer tsid = _map.get(tileSetName);
        if (tsid == null) {
            tsid = Integer.valueOf(++_nextTileSetID);
            _map.put(tileSetName, tsid);
        }
        return tsid.intValue();
    }
648578
function getCzechForm (c) {
    if (c === 1) {
      return 0
    } else if (Math.floor(c) !== c) {
      return 1
    } else if (c % 10 >= 2 && c % 10 <= 4 && c % 100 < 10) {
      return 2
    } else {
      return 3
    }
  }
944023
function (tiles) {
		const maxDist = 5;
		
		let t, tile, i;
		
		let topLeft = Vector._temp[0],
			topRight = Vector._temp[1],
			bottomLeft = Vector._temp[2],
			bottomRight = Vector._temp[3];
		
		// Calculate initial boundary edges
		for (t = 0; t < tiles.length; t++) {
			tile = tiles[t];
			
			// Skip over irrelevant tiles
			if (isIrrelevant(tile)) {
				continue;
			}
			
			let body = tile.physics.matterBody.body;
			let vertices = body.vertices;
			
			let left = tile.pixelX;
			let right = tile.pixelX + tile.width;
			let top = tile.pixelY;
			let bottom = tile.pixelY + tile.height;
			
			topLeft.y = top;
			topLeft.x = left;
			topRight.y = top;
			topRight.x = right;
			bottomLeft.y = bottom;
			bottomLeft.x = left;
			bottomRight.y = bottom;
			bottomRight.x = right;
			
			// Identify solid boundary edges
			for (i = 0; i < vertices.length; i++) {
				let firstVertex = vertices[i];
				let secondVertex = vertices[(i + 1) % vertices.length];
				
				// Top
				if (distance(firstVertex, topLeft) < maxDist && distance(secondVertex, topRight) < maxDist) {
					tile.physics.slopes.edges.top = Constants.SOLID;
				}
				
				// Bottom
				if (distance(firstVertex, bottomRight) < maxDist && distance(secondVertex, bottomLeft) < maxDist) {
					tile.physics.slopes.edges.bottom = Constants.SOLID;
				}
				
				// Left
				if (distance(firstVertex, bottomLeft) < maxDist && distance(secondVertex, topLeft) < maxDist) {
					tile.physics.slopes.edges.left = Constants.SOLID;
				}
				
				// Right
				if (distance(firstVertex, topRight) < maxDist && distance(secondVertex, bottomRight) < maxDist) {
					tile.physics.slopes.edges.right = Constants.SOLID;
				}
			}
		}
		
		// Compare neighbouring boundary edges
		for (t = 0; t < tiles.length; t++) {
			tile = tiles[t];
			
			// Skip over irrelevant tiles
			if (isIrrelevant(tile)) {
				continue;
			}
			
			let tileEdges = tile.physics.slopes.edges;
			let neighbours = tile.physics.slopes.neighbours;
			
			let up = neighbours.up;
			let down = neighbours.down;
			let left = neighbours.left;
			let right = neighbours.right;
			
			// Identify empty edges
			if (!isIrrelevant(up)) {
				tileEdges.top = this.compareBoundaryEdges(tileEdges.top, up.physics.slopes.edges.bottom);
				tile.collideUp = tileEdges.top !== Constants.EMPTY;
			}
			
			if (!isIrrelevant(down)) {
				tileEdges.bottom = this.compareBoundaryEdges(tileEdges.bottom, down.physics.slopes.edges.top);
				tile.collideDown = tileEdges.bottom !== Constants.EMPTY;
			}
			
			if (!isIrrelevant(left)) {
				tileEdges.left = this.compareBoundaryEdges(tileEdges.left, left.physics.slopes.edges.right);
				tile.collideLeft = tileEdges.left !== Constants.EMPTY;
			}
			
			if (!isIrrelevant(right)) {
				tileEdges.right = this.compareBoundaryEdges(tileEdges.right, right.physics.slopes.edges.left);
				tile.collideRight = tileEdges.right !== Constants.EMPTY;
			}
		}
	}
672510
function (v) {
    if (typeof v === "number")
      return 1;
    if (typeof v === "string")
      return 2;
    if (typeof v === "boolean")
      return 8;
    if (isArray(v))
      return 4;
    if (v === null)
      return 10;
    if (_.isRegExp(v))
      // note that typeof(/x/) === "object"
      return 11;
    if (typeof v === "function")
      return 13;
    if (_.isDate(v))
      return 9;
    if (EJSON.isBinary(v))
      return 5;
    if (v instanceof LocalCollection._ObjectID)
      return 7;
    return 3; // object

    // XXX support some/all of these:
    // 14, symbol
    // 15, javascript code with scope
    // 16, 18: 32-bit/64-bit integer
    // 17, timestamp
    // 255, minkey
    // 127, maxkey
  }
1060059
function isInteger(x) {
  return isNumber(x)
    && isFinite(x)
    && Math.floor(x) === x
}
856451
function(n) {
      // If number given, swap endian
      if (n.constructor == Number) {
        return crypt.rotl(n, 8) & 0x00FF00FF | crypt.rotl(n, 24) & 0xFF00FF00;
      }

      // Else, assume array and swap all items
      for (var i = 0; i < n.length; i++)
        n[i] = crypt.endian(n[i]);
      return n;
    }
536848
function(number) 
  {
    var bcd = ((number/10)<<4) + (number%10);
    var retVal = bcd.toString(16);
    if( retVal.length < 2 ){
      retVal = '0' + retVal;
    }
    return retVal;
  }