コード例 #1
0
ファイル: CircleSelector.cpp プロジェクト: Former/CircleWorld
	void CrossNearSelector::FillNearData(const CONearPtr& a_NearData, const CircleObjectPtr& a_Obj, const CONearPtr& a_ObjNear)
	{
		CoordinateType radius = (a_ObjNear) ? a_ObjNear->RadiusMoveArea : a_Obj->Radius;
		if (IsNear(a_NearData->LastCenter, a_NearData->RadiusNearArea + radius, a_Obj->Center))
		{
			a_NearData->NearObjects.push_back(a_Obj);
			a_NearData->NearArray.push_back(a_ObjNear);
		}
	}
コード例 #2
0
ファイル: lsh.cpp プロジェクト: EDzhangjianyu/snap
TVec<TFltV> TLSHash::GetNearPoints(TFltV Datum) {
  TVec<TFltV> Candidates = GetCandidates(Datum);
  TVec<TFltV> NearPoints;

  for (int i=0; i<Candidates.Len(); i++) {
    if (IsNear(Datum, Candidates[i]))
      NearPoints.Add(Candidates[i]);
  }
  return NearPoints;
}
コード例 #3
0
ファイル: Quaternion.hpp プロジェクト: PhilCK/vortex
inline Vector3 QuaternionGetEulerAnglesInRadians(const Quaternion &quat)
{
	const float poleTest = 2.f * (quat.y * quat.w - quat.x * quat.z);
	
	const float errorMarginTest = 0.0001f;
	
	if(IsNear(poleTest, 1.f, errorMarginTest))
	{
		const float x = 0;
		const float y = QuartTau();
		const float z = -2.f * ATan2(quat.x, quat.w);

		const Vector3 retVec = {x, y, z};

		return retVec;
	}
	else if(IsNear(poleTest, -1.f, errorMarginTest))
	{
		const float x = 0;
		const float y = -QuartTau();
		const float z = 2.f * ATan2(quat.x, quat.w);

		const Vector3 retVec = {x, y, z};

		return retVec;
	}
	else
	{
		const float wSq = quat.w * quat.w;
		const float xSq = quat.x * quat.x;
		const float ySq = quat.y * quat.y;
		const float zSq = quat.z * quat.z;

		const float x = ATan2(2.f * (quat.y * quat.z + quat.x * quat.w), (-xSq - ySq + zSq + wSq));
		const float y = ASin(Clamp(poleTest, -1.f, 1.f));
		const float z = ATan2(2.f * (quat.x * quat.y + quat.z * quat.w), (xSq - ySq - zSq + wSq));

		const Vector3 retVec = {x, y, z};

		return retVec;
	}
}
コード例 #4
0
ファイル: lsh.cpp プロジェクト: EDzhangjianyu/snap
TVec<TPair<TFltV, TFltV> > TLSHash::GetAllNearPairs() {
  TVec<TPair<TFltV, TFltV> > CandidatePairs = GetAllCandidatePairs();
  TVec<TPair<TFltV, TFltV> > NearPairs;

  for (int i=0; i<CandidatePairs.Len(); i++) {
    if (IsNear(CandidatePairs[i].GetVal1(), CandidatePairs[i].GetVal2())) {
      NearPairs.Add(CandidatePairs[i]);
    }
  }
  return NearPairs;
}
コード例 #5
0
void OBConformerSearch::Search()
{
    int identicalGenerations = 0;
    double last_score = 0.0;
    for (int i = 0; i < 1000; i++) {
        std::cout << "Generation #" << i + 1 << "  " << last_score << std::endl;
        // keep copy of rotor keys if next generation is less fit
        RotorKeys rotorKeys = m_rotorKeys;
        // create the children
        NextGeneration();
        // make the selection
        double score = MakeSelection();

        if (IsNear(last_score, score)) {
            identicalGenerations++;
            last_score = score;
        } else {
            if (score < last_score) {
                m_rotorKeys = rotorKeys;
                identicalGenerations++;
            } else {
                last_score = score;
                identicalGenerations = 0;
            }
        }

//      if (i)
        //      std::cerr << ";";
        //  std::cerr << last_score;

        if (identicalGenerations > m_convergence)
            break;
    }
//    std::cerr << std::endl;


    for (unsigned int i = 0; i < m_rotorKeys.size(); ++i) {
        for (unsigned int j = 1; j < m_rotorKeys[i].size(); ++j)
            std::cout << m_rotorKeys[i][j] << " ";
        std::cout << std::endl;
    }


}
コード例 #6
0
ファイル: CircleSelector.cpp プロジェクト: Former/CircleWorld
	void CrossNearSelector::CalculateNear(const CONearPtr& a_NearData, size_t a_CurIndex)
	{
		static int s_AllCount = 0;
		static int s_NearCount = 0;
		//CalculateNearFromAllObject(a_NearData, a_CurIndex);
		//return;

		const CircleObjectPtr& curObj 	= m_Objects[a_CurIndex];
		const CONearPtr& curNear 				= a_NearData;
		
		// Попробуем вычислить с  помощью ближайших объектов
		Point peaks[8]; // Вершины новой границы  видимости
		peaks[0] = curObj->Center + Point(curNear->RadiusNearArea, curNear->RadiusNearArea, curNear->RadiusNearArea);
		peaks[1] = curObj->Center + Point(curNear->RadiusNearArea, curNear->RadiusNearArea, -curNear->RadiusNearArea);
		peaks[2] = curObj->Center + Point(curNear->RadiusNearArea, -curNear->RadiusNearArea, curNear->RadiusNearArea);
		peaks[3] = curObj->Center + Point(curNear->RadiusNearArea, -curNear->RadiusNearArea, -curNear->RadiusNearArea);
		peaks[4] = curObj->Center + Point(-curNear->RadiusNearArea, curNear->RadiusNearArea, curNear->RadiusNearArea);
		peaks[5] = curObj->Center + Point(-curNear->RadiusNearArea, curNear->RadiusNearArea, -curNear->RadiusNearArea);
		peaks[6] = curObj->Center + Point(-curNear->RadiusNearArea, -curNear->RadiusNearArea, curNear->RadiusNearArea);
		peaks[7] = curObj->Center + Point(-curNear->RadiusNearArea, -curNear->RadiusNearArea, -curNear->RadiusNearArea);
		
		bool usePeaks[8] = {0}; // Покрыты ли вершины
		size_t usePeaksCount = 0;
		size_t nearIndex[8] = {0}; // Индексы соседьних объектов которые перекрыли вершины
		size_t nearIndexCount = 0;
		
		for (size_t i = 0; i < curNear->NearObjects.size(); i++)
		{
			CalculateNearFromAllObject(a_NearData, a_CurIndex);
			return;
			
			const CircleObjectPtr& obj 	= curNear->NearObjects[i];
			// должен обязательно перекрывать центр
			if (!IsNear(curObj->Center, curNear->RadiusNearArea, obj->Center))
				continue;
			
			const CONearPtr& near 		= curNear->NearArray[i];
			if (!near)
				continue;

			// Перекрывает ли вершины?
			bool isNearUsePeaks = false;
			for (size_t j = 0; j < 8; j++)
			{
				if (usePeaks[j])
					continue;
				
				if (IsNear(obj->Center, near->RadiusNearArea, peaks[j]))
				{
					usePeaks[j] = true;
					usePeaksCount++;
					isNearUsePeaks = true;
				}
			}
			
			if (isNearUsePeaks)
			{
				nearIndex[nearIndexCount] = i;
				nearIndexCount++;
			}
			
			if (usePeaksCount == 8)
				break;
		}
		
		if (usePeaksCount != 8)
		{
			s_AllCount++;
			// С помощью ближайших не удалось. Берем все объекты
			CalculateNearFromAllObject(a_NearData, a_CurIndex);
			return;
		}
		s_NearCount++;
		
		std::vector<CONearPtr> curNearArray = curNear->NearArray;
		a_NearData->NearObjects.resize(0);
		a_NearData->NearArray.resize(0);
		
		std::set<size_t> allIds;
		for (size_t i = 0; i < nearIndexCount; i++)
		{
			const CONearPtr& near 				= curNearArray[nearIndex[i]];
			for (size_t j = 0; j < near->NearObjects.size(); j++)
			{
				const CircleObjectPtr& obj 	= near->NearObjects[j];
				const CONearPtr& near1 		= near->NearArray[j];

				if (obj->GetID() == curObj->GetID())
					continue;
				
				if (allIds.find(obj->GetID()) != allIds.end())
					continue;
				
				allIds.insert(obj->GetID());
				FillNearData(a_NearData, obj, near1);
			}
		}		
	}
コード例 #7
0
ファイル: delaunay.cpp プロジェクト: dreamsxin/ultimatepp
void Delaunay::Build(const Array<Pointf>& p, double e)
{
	epsilon = e;
	epsilon2 = e * e;
	points <<= p;
	order = GetSortOrder(points, &PointOrder);
	tihull = -1;
	int npoints = p.GetCount();

#ifdef DELDUMP
	RLOG("Delaunay(" << npoints << " points)");
	for(int dd = 0; dd < npoints; dd++)
		RLOG("[" << dd << "] = " << points[dd]);
#endif

	triangles.Clear();
	if(order.IsEmpty())
		return;
	const Pointf *p0 = &points[order[0]];
	int xi = 0;
	do
		if(++xi >= points.GetCount())
			return;
	while(IsNear(*p0, points[order[xi]]));

	// pass 1: create pair of improper triangles
	CreatePair(order[0], order[xi]);
	while(++xi < npoints)
		AddHull(order[xi]);

#ifdef DELDUMP
	RLOG("//Delaunay: " << triangles.GetCount() << " triangles");
	for(int td = 0; td < triangles.GetCount(); td++)
	{
		const Triangle& t = triangles[td];
		RLOG(NFormat("[%d] = [%d, %d, %d] (%4v)",
			td, t[0], t[1], t[2],
			t.IsProper() ? (At(t, 1) - At(t, 0)) % (At(t, 2) - At(t, 1)) : double(Null))
			<< NFormat(" -> [%d & %d, %d & %d, %d & %d]",
			t.Next(0), t.NextIndex(0),
			t.Next(1), t.NextIndex(1),
			t.Next(2), t.NextIndex(2)));
	}
	RLOG("");
#endif

	int clean = 0;
	do
	{
		int old_clean = clean;
		clean = triangles.GetCount();
		for(int i = clean; --i >= old_clean;)
			if(triangles[i].IsProper())
			{
				Triangle& t = triangles[i];
				for(int x = 0; x < 3; x++)
				{
					int j = t.Next(x);
					Triangle& u = triangles[j];
					if(u.IsProper())
					{
						int x1 = x + 1, x2 = x + 2;
						if(x1 >= 3) x1 -= 3;
						if(x2 >= 3) x2 -= 3;
						Pointf A = At(t, x);
						Pointf B = At(t, x1);
						Pointf C = At(t, x2);
						int y = t.NextIndex(x);
						Pointf D = At(u, y);
						double t1 = (A - C) ^ (B - A);
						double t2 = (B - C) % (B - A);
						double u1 = (D - C) ^ (B - D);
						double u2 = (B - C) % (B - D);
						if(t1 * u2 < t2 * u1)
						{ // not locally Delaunay, flip
							int y1 = y + 1, y2 = y + 2;
							if(y1 >= 3) y1 -= 3;
							if(y2 >= 3) y2 -= 3;
#ifdef DELDUMP
							RLOG("Delaunay flip (" << i << " / " << x << ", " << j << " / " << y << ")");
							RLOG(i << ": " << t[x] << " - " << A << ", " << t[x1] << " - " << B << ", " << t[x2] << " - " << C);
							RLOG(j << ": " << u[y] << " - " << D << ", " << u[y1] << " - " << At(u, y1) << ", " << u[y2] << " - " << At(u, y2));
							RLOG("t1 = " << t1 << ", t2 = " << t2 << ", t = " << t1 / t2);
							RLOG("u1 = " << u1 << ", u2 = " << u2 << ", u = " << u1 / u2);
#endif
							Triangle ot = t;
							Triangle ou = u;
							ASSERT(ot[x1] == ou[y2] && ot[x2] == ou[y1]);
							t.Set(ot[x1], ou[y], ot[x]);
							u.Set(ou[y1], ot[x], ou[y]);
							Link(i, 0, j, 0);
							Link(i, 1, ot.Next(x2), ot.NextIndex(x2));
							Link(i, 2, ou.Next(y1), ou.NextIndex(y1));
							Link(j, 1, ou.Next(y2), ou.NextIndex(y2));
							Link(j, 2, ot.Next(x1), ot.NextIndex(x1));
							clean = i;
#ifdef DELDUMP
							RLOG("After flip: [" << i << "] = " << t[x] << ", " << t[x1] << ", " << t[y2]
								<< "; [" << j << "] = " << u[y] << ", " << u[y1] << ", " << u[y2]);
#endif
						}
					}
				}
			}
	}
	while(clean < triangles.GetCount());
}
コード例 #8
0
/*----------------------------------------------------------------------
 *       Class:  AmayaTransformEvtHandler
 *      Method:  OnMouseDown
 * Description:  handle mouse button down events
 -----------------------------------------------------------------------*/
void AmayaTransformEvtHandler::OnMouseDown( wxMouseEvent& event )
{
  if (IsFinish())
    return;

  ButtonDown = true;
  lastX = mouse_x;
  lastY = mouse_y;
  switch(type)
    {
    case 2:
      /* Rotation: is the user clicking on the center ? */
      if (IsNear(cx2, cy2))
        type = 3;

      hasBeenRotated = false;
      break;

    case 1:
      /* Scaling: is the user clicking on an arrow ? */
      if (IsNear((left2+right2)/2, top2))
        type = 9;
      else if (IsNear((left2+right2)/2, bottom2))
        type = 10;
      else if (IsNear(left2, (top2+bottom2)/2))
        type = 11;
      else if (IsNear(right2, (top2+bottom2)/2))
        type = 12;
      else  if (IsNear(left2, top2))
        type = 13;
      else if (IsNear(right2, top2))
        type = 14;
      else if (IsNear(right2, bottom2))
        type = 15;
      else if (IsNear(left2, bottom2))
        type = 16;
      else Finished = true;

      /* Clear the arrows */
      DrawScalingArrows();
      break;

    case 4:
      /* Skewing: is the user clicking on an arrow ? */

      if (IsNear((left2+right2)/2, top2))
        type = 5;
      else if (IsNear((left2+right2)/2, bottom2))
        type = 6;
      else if (IsNear(left2, (top2+bottom2)/2))
        type = 7;
      else if (IsNear(right2, (top2+bottom2)/2))
        type = 8;
      else Finished = true;

      /* Clear the arrows */
      DrawSkewingArrows();
      break;
    }
}
コード例 #9
0
ファイル: patch_code_gen.hpp プロジェクト: JuJuBoSc/hadesmem
inline std::size_t
  WriteJump(Process const& process,
            void* address,
            void* target,
            bool push_ret_fallback,
            std::vector<std::unique_ptr<Allocator>>* trampolines)
{
  HADESMEM_DETAIL_TRACE_FORMAT_A(
    "Address = %p, Target = %p, Push Ret Fallback = %u.",
    address,
    target,
    static_cast<std::uint32_t>(push_ret_fallback));

  std::vector<std::uint8_t> jump_buf;

#if defined(HADESMEM_DETAIL_ARCH_X64)
  if (IsNear(address, target))
  {
    HADESMEM_DETAIL_TRACE_A("Using relative jump.");
    jump_buf = GenJmp32(address, target);
    HADESMEM_DETAIL_ASSERT(jump_buf.size() == PatchConstants::kJmpSize32);
  }
  else
  {
    std::unique_ptr<Allocator> trampoline;

    if (trampolines)
    {
      try
      {
        trampoline = AllocatePageNear(process, address);
      }
      catch (std::exception const& /*e*/)
      {
        // Don't need to do anything, we'll fall back to PUSH/RET.
      }
    }

    if (trampoline)
    {
      void* tramp_addr = trampoline->GetBase();

      HADESMEM_DETAIL_TRACE_FORMAT_A("Using trampoline jump. Trampoline = %p.",
                                     tramp_addr);

      Write(process, tramp_addr, target);

      trampolines->emplace_back(std::move(trampoline));

      jump_buf = GenJmpTramp64(address, tramp_addr);
      HADESMEM_DETAIL_ASSERT(jump_buf.size() == PatchConstants::kJmpSize64);
    }
    else
    {
      if (!push_ret_fallback)
      {
        // We're out of options...
        HADESMEM_DETAIL_THROW_EXCEPTION(
          Error{} << ErrorString{"Unable to use a relative or trampoline "
                                 "jump, and push/ret fallback is disabled."});
      }

      HADESMEM_DETAIL_TRACE_A("Using push/ret 'jump'.");

      auto const target_high = static_cast<std::uint32_t>(
        (reinterpret_cast<std::uintptr_t>(target) >> 32) & 0xFFFFFFFF);
      if (target_high)
      {
        HADESMEM_DETAIL_TRACE_A("Push/ret 'jump' is big.");
        jump_buf = GenPush64Ret(target);
        HADESMEM_DETAIL_ASSERT(jump_buf.size() ==
                               PatchConstants::kPushRetSize64);
      }
      else
      {
        HADESMEM_DETAIL_TRACE_A("Push/ret 'jump' is small.");
        jump_buf = GenPush32Ret(target);
        HADESMEM_DETAIL_ASSERT(jump_buf.size() ==
                               PatchConstants::kPushRetSize32);
      }
    }
  }
#elif defined(HADESMEM_DETAIL_ARCH_X86)
  (void)push_ret_fallback;
  (void)trampolines;
  HADESMEM_DETAIL_TRACE_A("Using relative jump.");
  jump_buf = GenJmp32(address, target);
  HADESMEM_DETAIL_ASSERT(jump_buf.size() == PatchConstants::kJmpSize32);
#else
#error "[HadesMem] Unsupported architecture."
#endif

  WriteVector(process, address, jump_buf);

  return jump_buf.size();
}