Esempio n. 1
0
bool flip_till_1()
{
    if (status == rows*cols -1)
    {
        if (is_it_check())
            return true;
        mat[status/cols][status%cols] ^= 1; // try flipping
        flipped(status);
        solution[status] = true;
        if (is_it_check())
            return true;
        mat[status/cols][status%cols] ^= 1; // revert
        flipped(status);
        solution[status] = false;
        return false;
    }
    if(can_i_flip(status))
    {
        mat[status/cols][status%cols] ^= 1 ; // flip it damn you
        flipped(status);
        solution[status] = true;
        status++;
        if(flip_till_1())
            return true;
        status--;
        mat[status/cols][status%cols] ^= 1 ; // revert!!!!!!
        flipped(status);
        solution[status] = false;
    }
    status++;
    return flip_till_1();
}
Esempio n. 2
0
 void write_chunk(uint32 type, uint32 length, void const* data, File& f) {
   flip(type);
   f.write32(flipped(length));
   f.write32(type);
   f.write(data, length);
   uint32 crc = update_crc(0xFFFFFFFF, &type, 4);
   crc = ~update_crc(crc, data, length);
   f.write32(flipped(crc));
 }
Esempio n. 3
0
/**
 * Returns a new stamp where all variations have been flipped in the given
 * \a direction.
 */
TileStamp TileStamp::flipped(FlipDirection direction) const
{
    TileStamp flipped(*this);
    flipped.d.detach();

    for (const TileStampVariation &variation : flipped.variations()) {
        TileLayer *layer = variation.tileLayer();

        if (variation.map->isStaggered()) {
            Map::StaggerAxis staggerAxis = variation.map->staggerAxis();

            if (staggerAxis == Map::StaggerY) {
                if ((direction == FlipVertically && !(layer->height() & 1)) || direction == FlipHorizontally)
                    variation.map->invertStaggerIndex();

            } else {
                if ((direction == FlipHorizontally && !(layer->width() & 1)) || direction == FlipVertically)
                    variation.map->invertStaggerIndex();
            }
        }

        if (variation.map->orientation() == Map::Hexagonal)
            layer->flipHexagonal(direction);
        else
            layer->flip(direction);
    }

    return flipped;
}
Esempio n. 4
0
	glm::quat transform_sensor_rotation(const glm::quat& q)
	{
		// this bit of code converts the coordinate system of the BNO055
		// to that of gemini.
		glm::quat flipped(q.w, q.x, -q.z, -q.y);
		glm::quat y = glm::quat(glm::vec3(0, mathlib::degrees_to_radians(180), 0));
		return glm::inverse(y * flipped);
	}
Esempio n. 5
0
void screenshot (const char* filename) {
  cv::Mat img(HEIGHT, WIDTH, CV_8UC3);
  cv::Mat flipped(HEIGHT, WIDTH, CV_8UC3);
  glPixelStorei(GL_PACK_ALIGNMENT, (img.step & 3) ? 1 : 4);
  glPixelStorei(GL_PACK_ROW_LENGTH, img.step/img.elemSize());
  glReadPixels(0, 0, img.cols, img.rows, GL_BGR, GL_UNSIGNED_BYTE, img.data);
  cv::flip(img, flipped, 0);
  imwrite(filename, flipped);
}
Esempio n. 6
0
void pd::player::move_right()
{
    m_stoped = false;
    m_ticks_until_stop = SDL_GetTicks();
    flipped(false);
    pd::vec2 vec = linear_velocity();
    if (vec.x < (airborne() ? max_airborne_velocity : max_velocity))
        apply_force(movement_force, 0.0f);
}
Esempio n. 7
0
void screenshot (const int width, const int height, const char* filename, const int buffer) {
  glReadBuffer(buffer);
  cv::Mat img(height, width, CV_8UC3);
  cv::Mat flipped(height, width, CV_8UC3);
  glPixelStorei(GL_PACK_ALIGNMENT, (img.step & 3) ? 1 : 4);
  glPixelStorei(GL_PACK_ROW_LENGTH, img.step/img.elemSize());
  glReadPixels(0, 0, img.cols, img.rows, GL_BGR, GL_UNSIGNED_BYTE, img.data);
  cv::flip(img, flipped, 0);
  imwrite(filename, flipped);
  return;
}
Esempio n. 8
0
	TextureRegion TextureRegion::flipped(const bool doFlip) const
	{
		if (doFlip)
		{
			return flipped();
		}
		else
		{
			return *this;
		}
	}
Esempio n. 9
0
arma::field<arma::Cube<double>> Utils::flipCubes(const arma::field<arma::Cube<double>>& f) {
	arma::field<arma::Cube<double>> flipped(f.size());
	for (unsigned int i=0; i<f.size(); ++i) {
		arma::Cube<double> flippedCube(f[i].n_rows, f[i].n_cols, f[i].n_slices);
		for (unsigned int j=0; j<f[i].n_slices; ++j) {
			flippedCube.slice(j) = arma::fliplr(arma::flipud(f[i].slice(j)));
		}
		flipped[i] = flippedCube;
	}
	return flipped;
}
Esempio n. 10
0
/**
 * Returns a new stamp where all variations have been flipped in the given
 * \a direction.
 */
TileStamp TileStamp::flipped(FlipDirection direction) const
{
    TileStamp flipped(*this);
    flipped.d.detach();

    foreach (const TileStampVariation &variation, flipped.variations()) {
        TileLayer *layer = static_cast<TileLayer*>(variation.map->layerAt(0));
        layer->flip(direction);
    }

    return flipped;
}
Esempio n. 11
0
 /**
  * Flip this mapping and return a new mapping for the other strand, with
  * contexts swapped.
  */
 inline Mapping flip(size_t contigLength) const {
     if(is_mapped) {
         // If we're mapped, flip the location and exchange the contexts.
         TextPosition newLocation = location;
         newLocation.flip(contigLength);
         Mapping flipped(newLocation);
         flipped.setMaxContext(rightMaxContext, leftMaxContext);
         return flipped;
     } else {
         // If we are unmapped, just continue being exactly the same.
         return *this;
     }
 }
Esempio n. 12
0
void tft_t::setVerticalScrollingArea(const uint16_t tfa, const uint16_t bfa)
{
	uint16_t vsa = SIZE_H - tfa - bfa;
	cmd(0x33);	// Vertical Scrolling Definition
	if (flipped()) {
		write16(bfa);	// Top Fixed Area
		write16(vsa);	// Vertical Scrolling Area
		write16(tfa);	// Bottom Fixed Area
	} else {
		write16(tfa);	// Top Fixed Area
		write16(vsa);	// Vertical Scrolling Area
		write16(bfa);	// Bottom Fixed Area
	}
	d.tfa = tfa;
	d.bfa = bfa;
}
Esempio n. 13
0
//Sorts energies from largest to smallest
vector<pair<int, double> > energySort(vector<pair<int, double> > shower)
{
  std::vector<std::pair<double, int> > energy;
  for (VP_iterator=shower.begin(); VP_iterator!=shower.end(); VP_iterator++)
    {
      pair<double, int> flipped(VP_iterator->second, VP_iterator->first);
      energy.push_back(flipped);
    }
  std::map<double, int> myMap(energy.begin(), energy.end());
  map<double, int>::iterator m;
  vector<pair<int, double> > sorted;
  for (m=myMap.end(); m!=myMap.begin(); --m)
    {
     pair<int, double> orderHit(m->second, m->first);
     sorted.push_back(orderHit);
    }
  sorted.erase(sorted.begin(), sorted.begin()+1);
  return sorted;
}
Esempio n. 14
0
/**
 * Returns a new stamp where all variations have been flipped in the given
 * \a direction.
 */
TileStamp TileStamp::flipped(FlipDirection direction) const
{
    TileStamp flipped(*this);
    flipped.d.detach();

    for (const TileStampVariation &variation : flipped.variations()) {
        const QRect mapRect(QPoint(), variation.map->size());

        for (auto layer : variation.map->tileLayers()) {
            TileLayer *tileLayer = static_cast<TileLayer*>(layer);

            // Synchronize tile layer size to map size (assumes map contains all layers)
            if (tileLayer->rect() != mapRect) {
                tileLayer->resize(mapRect.size(), tileLayer->position());
                tileLayer->setPosition(0, 0);
            }

            if (variation.map->orientation() == Map::Hexagonal)
                tileLayer->flipHexagonal(direction);
            else
                tileLayer->flip(direction);
        }

        if (variation.map->isStaggered()) {
            Map::StaggerAxis staggerAxis = variation.map->staggerAxis();

            if (staggerAxis == Map::StaggerY) {
                if ((direction == FlipVertically && !(variation.map->height() & 1)) || direction == FlipHorizontally)
                    variation.map->invertStaggerIndex();

            } else {
                if ((direction == FlipHorizontally && !(variation.map->width() & 1)) || direction == FlipVertically)
                    variation.map->invertStaggerIndex();
            }
        }
    }

    return flipped;
}
Esempio n. 15
0
char *
ovOverlap::toString(char                  *str,
                    ovOverlapDisplayType   type,
                    bool                   newLine) {

  switch (type) {
    case ovOverlapAsHangs:
      sprintf(str, "%10"F_U32P" %10"F_U32P"  %c  %6"F_S32P" %6"F_U32P" %6"F_S32P"  %7.6f%s%s",
              a_iid, b_iid,
              flipped() ? 'I' : 'N',
              a_hang(), span(), b_hang(),
              erate(),
              (overlapIsDovetail()) ? "" : "  PARTIAL",
              (newLine) ? "\n" : "");
      break;

    case ovOverlapAsCoords:
      sprintf(str, "%10"F_U32P" %10"F_U32P"  %c  %6"F_U32P"  %6"F_U32P" %6"F_U32P"  %6"F_U32P" %6"F_U32P"  %7.6f%s",
              a_iid, b_iid,
              flipped() ? 'I' : 'N',
              span(),
              a_bgn(), a_end(),
              b_bgn(), b_end(),
              erate(),
              (newLine) ? "\n" : "");
      break;

    case ovOverlapAsRaw:
      sprintf(str, "%10"F_U32P" %10"F_U32P"  %c  %6"F_U32P"  %6"F_U64P" %6"F_U64P"  %6"F_U64P" %6"F_U64P"  %7.6f %s %s %s%s",
              a_iid, b_iid,
              flipped() ? 'I' : 'N',
              span(),
              dat.ovl.ahg5, dat.ovl.ahg3,
              dat.ovl.bhg5, dat.ovl.bhg3,
              erate(),
              dat.ovl.forOBT ? "OBT" : "   ",
              dat.ovl.forDUP ? "DUP" : "   ",
              dat.ovl.forUTG ? "UTG" : "   ",
              (newLine) ? "\n" : "");
      break;

    case ovOverlapAsCompat:
      sprintf(str, "%8"F_U32P" %8"F_U32P"  %c  %6d  %6d  %5.2f  %5.2f%s",
              a_iid,
              b_iid,
              dat.ovl.flipped ? 'I' : 'N',
              a_hang(), b_hang(),
              erate() * 100.0,
              erate() * 100.0,
              (newLine) ? "\n" : "");
      break;
    case ovOverlapAsPaf:
      // miniasm/map expects entries to be separated by tabs
      // no padding spaces on names we don't confuse read identifiers
      sprintf(str, "%"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%c\t%"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P"\t%6"F_U32P" %s",
              a_iid,
              (g->gkStore_getRead(a_iid)->gkRead_sequenceLength()), a_bgn(), a_end(),
              flipped() ? '-' : '+',
              b_iid,
              (g->gkStore_getRead(b_iid)->gkRead_sequenceLength()), flipped() ? b_end() : b_bgn(), flipped() ? b_bgn() : b_end(),
              (uint32)floor(span() == 0 ? (1-erate() * (a_end()-a_bgn())) : (1-erate()) * span()),
              span() == 0 ? a_end() - a_bgn() : span(),
              255,
              (newLine) ? "\n" : "");
      break;

  }

  return(str);
}
Esempio n. 16
0
void tft_t::setVerticalScrolling(const uint16_t vsp)
{
	cmd(0x37);	// Vertical Scrolling Start Address
	write16(flipped() ? vsMaximum() - vsp : vsp);
	d.vsp = vsp;
}
Esempio n. 17
0
double Schlüssellöcher::Key::meanDifferenceWithFlipped(const Key & other) const
{
	const Key& a = *this, b = flipped(), c = other, d = other.flipped();
	return (a.differenceToKey(c) + a.differenceToKey(d) + b.differenceToKey(c) + b.differenceToKey(d)) / 4;
}
Esempio n. 18
0
bool PathFinderManager::getSpawnPointInArea(const Sphere& area, Zone *zone, Vector3& point, bool checkPath) {
	SortedVector<ManagedReference<NavArea*>> areas;
	float radius = area.getRadius();
	const Vector3& center = area.getCenter();
	Vector3 flipped(center.getX(), center.getZ(), -center.getY());
	float extents[3] = {3, 5, 3};

	dtNavMeshQuery* query = getNavQuery();

	if (zone == NULL)
		return false;

	zone->getInRangeNavMeshes(center.getX(), center.getY(), &areas, true);

	if (areas.size() == 0) {
		Vector3 temp((frand() * 2.0f) - 1.0f, (frand() * 2.0f) - 1.0f, 0);
		Vector3 result = temp * (frand() * radius);
		point = center + result;
		point.setZ(CollisionManager::getWorldFloorCollision(point.getX(), point.getY(), zone, false));
		return true;
	}

	for (const auto& navArea : areas) {
		Vector3 polyStart;
		dtPolyRef startPoly;
		dtPolyRef ref;
		int status = 0;
		float pt[3];

		RecastNavMesh *mesh = navArea->getNavMesh();
		if (mesh == NULL)
			continue;

		ReadLocker rLocker(navArea);

		dtNavMesh *dtNavMesh = mesh->getNavMesh();
		if (dtNavMesh == NULL)
			continue;

		query->init(dtNavMesh, MAX_QUERY_NODES);

		if (!((status = query->findNearestPoly(flipped.toFloatArray(), extents, &m_spawnFilter, &startPoly, polyStart.toFloatArray())) & DT_SUCCESS))
			continue;

		for (int i=0; i<50; i++) {
			try {
				if (!((status = query->findRandomPointAroundCircle(startPoly, polyStart.toFloatArray(), radius, &m_spawnFilter,
																   frand, &ref, pt)) & DT_SUCCESS)) {
					continue;
				} else {
					point = Vector3(pt[0], -pt[2], CollisionManager::getWorldFloorCollision(pt[0], -pt[2], zone, false));

					Vector3 temp = point - center;
					float len = temp.length();
					if (len > radius) {
						float multiplier = (frand() * radius) / len;
						temp.setX(temp.getX() * multiplier);
						temp.setY(temp.getY() * multiplier);
						point = center + temp;

						point.setZ(CollisionManager::getWorldFloorCollision(point.getX(), point.getY(), zone, false));
					}

					if (checkPath) {
						if (!getRecastPath(center, point, navArea, nullptr, len, false)) {
							continue;
						}
					}

					return true;
				}
			} catch (Exception& exc) {
				error(exc.getMessage());
			}
		}
	}

	return false;
}