10 Haziran 2020 Çarşamba

geometry convex_hull metodu

Giriş
Convex Hull belli bir nokta setinin tamamını içeren polygon'dur. Convex Hull hesaplaması için çeşitli yöntemler var. Şeklen şöyledir


Örnek
Şöyle yaparız.
bool is_convex(const polygon& convex_polygon) noexcept
{
  const auto n = convex_polygon.size();
  if(n <= 2) return false;

  auto sense = side::center;

  for(auto i = 0u; i < n; ++i)
  {
    auto new_sense = determine_side(line{convex_polygon[i], convex_polygon[(i + 2) % n]},
      convex_polygon[(i + 1) % n]);

      if(sense == side::center)
      {
        sense = new_sense;
      }
      else if(new_sense != side::center && new_sense != sense)
      {
        return false;
      }
  }

  return sense != side::center;
}

4 Mart 2020 Çarşamba

mp11

mp_filter metodu
Örnek
Elimizde şöyle bir kod olsun.
using V = std::variant<bool, char, std::string, int, float, double, std::vector<int>>;
Bu variant'ı ikiye ayırmak isteyelim. Yani şunu isteyelim
using V1 = std::variant<bool, char, int, float, double>;
using V2 = std::variant<std::string, std::vector<int>>;
Şöyle yaparız
using V1 = mp_filter<std::is_arithmetic, V>;
using V2 = mp_remove_if<V, std::is_arithmetic>;
mp_remove_if metodu
Örnek ver

mp_partition metodu
Elimizde şöyle bir kod olsun.
using V = std::variant<bool, char, std::string, int, float, double, std::vector<int>>;
Şöyle yaparız
using P = mp_partition<V, std::is_arithmetic>;
using V1 = mp_first<P>;
using V2 = mp_second<P>;
mp_product metodu
Elimizde 3 tane liste olsun
using type_list_1 = type_list<int, somestructA>;
using type_list_2 = type_list<somestructB>;
using type_list_3 = type_list<double, short>;
Şöyle yaparız
using result = mp_product<
    type_list,
    type_list_1, type_list_2, type_list_3>;
Çıktı olarak şunu alırız
result = type_list<
type_list<int, somestructB, double>,
type_list<int, somestructB, short>,
type_list<somestructA, somestructB, double>,
type_list<somestructA, somestructB, short>
>;