Пример #1
0
		void graveyard_builder::run_builder(unsigned int seed, rectangle const& bounds, fn::build_result &result) const
		{
			rng_type rng(seed);
			rng.discard(rng_type::state_size);

			fn::bsp<> sectors(rng, bounds, 20, 1);

			sectors.enumerate_bounds([&](rectangle sector) {

				if (std::uniform_int_distribution<int>(0, 1)(rng) == 0)
				{
					fn::build_fence(sector, fn::build_tile::wall, result, rng);
					sector.deflate(margin_size);
				}

				sector.enumerate([&](point2 const& location) {
					result.tiles[location] = fn::build_tile::no_change;
				});

				point2 tomb_align = fn::random_block_direction(rng);
				int mod_x = std::uniform_int_distribution<int>{ 3, 5 }(rng); // size of grave cell
				int mod_y = mod_x;
				int off_x = std::uniform_int_distribution<int>{ 0, mod_x - 1 }(rng);
				int off_y = std::uniform_int_distribution<int>{ 0, mod_y - 1 }(rng);

				sector.enumerate([&](point2 const& location) {
					auto d = location - sector.start();
					if (d.x() % mod_x == off_x && d.y() % mod_y == off_y)
					{
						result.tiles[location] = fn::build_tile::gravel;
						result.tiles[location.moved(tomb_align)] = fn::build_tile::doodad_tombstone;
					}
				});
			});
		}
void QStationModelGraphicsItem::drawTextFields(QPainter* painter) {

	// get the sector and coordinate assignments for this wind direction
	TextSectors sectors(_dirMet, 11);

	// Draw each text field
	QString tdry = QString("%1").arg(_tDryC, 0, 'f', 1);

	QString rh = QString("%1").arg(_DP, 0, 'f', 1);

	double presOrHeight = _presOrHeight;
	if (_isPres) {
		if (_presOrHeight >= 1000.0) {
			presOrHeight = 10*(_presOrHeight - 1000.0);
		} else {
			if (_presOrHeight >= 900.0) {
				presOrHeight = 10*(_presOrHeight - 900.0);
			}
		}
	}
	QString pht = QString("%1").arg((int)round(presOrHeight), 3, 10, QLatin1Char('0'));

	// check for erroneous surface pressures
	if (_isPres && _presOrHeight != -999.0) {
		if (presOrHeight > 999.0 || presOrHeight < 0.0) {
			pht = "ERR";
		}
	}
	// check for negative heights, which can happen for downward extrapolated levels.
	if (!_isPres && _presOrHeight != -999.0 && _presOrHeight < 0.0) {
		pht = "";
	}

	int t = _hh * 100 + _mm;
	QString time = QString("%1").arg(t, 4, 10, QChar('0'));	// filled with leading 0's

	if (_tDryC != -999.0 && _parts.test(MODEL_TDRY_BIT)) {
		drawTextField(painter, sectors, TextSectors::TDRY, tdry);
	}
	if (_DP != -999.0 && _parts.test(MODEL_DP_BIT)) {
		drawTextField(painter, sectors, TextSectors::RH, rh);
	}
	if (_presOrHeight != -999.0 && _parts.test(MODEL_PRESHT_BIT)) {
		drawTextField(painter, sectors, TextSectors::PHT, pht);
	}
	if (_parts.test(MODEL_TIME_BIT)) {
		drawTextField(painter, sectors, TextSectors::TIME, time);
	}
}
Пример #3
0
void testSectors1() {
  Sectors sectors(Rectangle(7, 7));
  sectors.add(Vec2(0, 0));
  CHECK(!sectors.same(Vec2(0, 0), Vec2(0, 2)));
  sectors.add(Vec2(0, 2));
  CHECK(!sectors.same(Vec2(0, 0), Vec2(0, 2)));
  sectors.add(Vec2(0, 1));
  CHECK(sectors.same(Vec2(0, 0), Vec2(0, 1)));
  CHECK(sectors.same(Vec2(0, 0), Vec2(0, 2)));
  CHECK(sectors.same(Vec2(0, 1), Vec2(0, 2)));
  sectors.remove(Vec2(0, 1));
  CHECK(!sectors.same(Vec2(0, 0), Vec2(0, 1)));
  CHECK(!sectors.same(Vec2(0, 0), Vec2(0, 2)));
  CHECK(!sectors.same(Vec2(0, 1), Vec2(0, 2)));
  CHECK(!sectors.same(Vec2(1, 1), Vec2(1, 2)));
}
Пример #4
0
bool Track::is_repeated (const Sector &sector) const
{
	for (const auto &s : sectors())
	{
		// Ignore ourselves in the list
		if (&s == &sector)
			continue;

		// Stop if we find match for data rate, encoding, and CHRN
		if (s.datarate == sector.datarate &&
			s.encoding == sector.encoding &&
			s.header == sector.header)
			return true;
	}

	return false;
}
Пример #5
0
static int header_check_fat(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
  const struct fat_boot_sector *fat_header=(const struct fat_boot_sector *)buffer;
  uint64_t start_fat1,start_data,part_size;
  unsigned long int no_of_cluster,fat_length,fat_length_calc;
  if(!(le16(fat_header->marker)==0xAA55
        && (fat_header->ignored[0]==0xeb || fat_header->ignored[0]==0xe9)
        && (fat_header->fats==1 || fat_header->fats==2)))
    return 0;   /* Obviously not a FAT */
  if(!((fat_header->ignored[0]==0xeb && fat_header->ignored[2]==0x90)||fat_header->ignored[0]==0xe9))
    return 0;
  if(fat_sector_size(fat_header)==0 || fat_sector_size(fat_header)%512!=0)
    return 0;
  switch(fat_header->sectors_per_cluster)
  {
    case 1:
    case 2:
    case 4:
    case 8:
    case 16:
    case 32:
    case 64:
    case 128:
      break;
    default:
      return 0;
  }
  if(fat_header->fats!=1 && fat_header->fats!=2)
    return 0;
  if(fat_header->media!=0xF0 && fat_header->media<0xF8)
    return 0;
  fat_length=le16(fat_header->fat_length)>0?le16(fat_header->fat_length):le32(fat_header->fat32_length);
  part_size=(sectors(fat_header)>0?sectors(fat_header):le32(fat_header->total_sect));
  start_fat1=le16(fat_header->reserved);
  start_data=start_fat1+fat_header->fats*fat_length+(get_dir_entries(fat_header)*32+fat_sector_size(fat_header)-1)/fat_sector_size(fat_header);
  no_of_cluster=(part_size-start_data)/fat_header->sectors_per_cluster;
  if(no_of_cluster<4085)
  {
    /* FAT12 */
    if((get_dir_entries(fat_header)==0)||(get_dir_entries(fat_header)%16!=0))
      return 0;
    if((le16(fat_header->fat_length)>256)||(le16(fat_header->fat_length)==0))
      return 0;
    fat_length_calc=((no_of_cluster+2+fat_sector_size(fat_header)*2/3-1)*3/2/fat_sector_size(fat_header));
  }
  else if(no_of_cluster<65525)
  {
    /* FAT16 */
    if(le16(fat_header->fat_length)==0)
      return 0;
    if((get_dir_entries(fat_header)==0)||(get_dir_entries(fat_header)%16!=0))
      return 0;
    fat_length_calc=((no_of_cluster+2+fat_sector_size(fat_header)/2-1)*2/fat_sector_size(fat_header));
  }
  else
  {
    /* FAT32 */
    if(sectors(fat_header)!=0)
      return 0;
    if(get_dir_entries(fat_header)!=0)
      return 0;
    if((le32(fat_header->root_cluster)<2) ||(le32(fat_header->root_cluster)>=2+no_of_cluster))
      return 0;
    fat_length_calc=((no_of_cluster+2+fat_sector_size(fat_header)/4-1)*4/fat_sector_size(fat_header));
  }
  if(fat_length<fat_length_calc)
    return 0;
  reset_file_recovery(file_recovery_new);
  file_recovery_new->extension=file_hint_fat.extension;
  file_recovery_new->calculated_file_size=(uint64_t)
    (sectors(fat_header)>0?sectors(fat_header):le32(fat_header->total_sect)) *
    fat_sector_size(fat_header);
  file_recovery_new->data_check=&data_check_size;
  file_recovery_new->file_check=&file_check_size;
  return 1;
}