Honeycomb  0.1
Component-Model Framework
BisectN.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
5 
6 namespace honey
7 {
8 
10 
14 template<class Real, int Dim>
15 class BisectN
16 {
17  typedef typename Numeral<Real>::Real_ Real_;
18  typedef Alge_<Real> Alge;
19 
20 public:
22  typedef function<Real (Vec)> Func;
23  typedef array<Func, Dim> Funcs;
24 
25  static const int dim = Dim;
26 
31  BisectN(Real tol = Real_::zeroTol, int depthMax = 30) : _tol(tol), _depthMax(depthMax) { _nodes.reserve(_depthMax); }
32 
34 
41  tuple<bool,Vec> root(const Funcs& funcs, const Vec& min, const Vec& max);
42 
43 private:
44  static const int childCount = 1 << dim;
45 
46  struct Node
47  {
48  Vec min;
49  Vec max;
50  Vec center;
51  };
52 
54  bool root();
55 
57  static Vec corner(const Vec& min, const Vec& max, int index);
58  static tuple<Vec,Vec> child(const Vec& min, const Vec& max, const Vec& center, int index);
59 
60  Real _tol;
61  int _depthMax;
62  const Funcs* _funcs;
63  Vec _root;
64  Real _minRes;
65  vector<Node> _nodes;
66  array<Vec, childCount> _corners;
67  array<array<Real, childCount>, dim> _funcsCorners;
68 };
69 
70 extern template class BisectN<Float, 2>;
71 extern template class BisectN<Float, 3>;
72 extern template class BisectN<Double, 2>;
73 extern template class BisectN<Double, 3>;
74 
75 }
76 
Algebra.
Definition: Alge.h:13
Vec< Dim, Real > Vec
Definition: BisectN.h:21
BisectN(Real tol=Real_::zeroTol, int depthMax=30)
Definition: BisectN.h:31
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Numeric type information, use numeral() to get instance safely from a static context.
Definition: Numeral.h:17
function< Real(Vec)> Func
Definition: BisectN.h:22
Find the root of a set of functions by the bisection method. ie. Finds (x,y,...) where all functions ...
Definition: BisectN.h:15
static const int dim
Definition: BisectN.h:25
array< Func, Dim > Funcs
Definition: BisectN.h:23
Global Honeycomb namespace.