Esempio n. 1
0
bool ViewWidget::accept_drag() const
{
	const vector< shared_ptr<TimeItem> > items(view_.time_items());
	const vector< shared_ptr<TraceTreeItem> > trace_tree_items(
		view_.list_by_type<TraceTreeItem>());

	const bool any_row_items_selected = any_of(
		trace_tree_items.begin(), trace_tree_items.end(),
		[](const shared_ptr<TraceTreeItem> &r) { return r->selected(); });

	const bool any_time_items_selected = any_of(items.begin(), items.end(),
		[](const shared_ptr<TimeItem> &i) { return i->selected(); });

	if (any_row_items_selected && !any_time_items_selected) {
		// Check all the drag items share a common owner
		TraceTreeItemOwner *item_owner = nullptr;
		for (shared_ptr<TraceTreeItem> r : trace_tree_items)
			if (r->dragging()) {
				if (!item_owner)
					item_owner = r->owner();
				else if (item_owner != r->owner())
					return false;
			}

		return true;
	} else if (any_time_items_selected && !any_row_items_selected) {
		return true;
	}

	// A background drag is beginning
	return true;
}
Esempio n. 2
0
 static constexpr auto apply(Set set) {
     return make_infinite_set([=](auto p) {
         return set.find([=](auto set) {
             return any_of(set, p);
         }).find(p);
     });
 }
Esempio n. 3
0
bool DiffTraversal::View::shouldTraverseElement(const EntityTreeElement& element) const {
    if (!usesViewFrustums()) {
        return true;
    }

    const auto& cube = element.getAACube();

    auto center = cube.calcCenter(); // center of bounding sphere
    auto radius = 0.5f * SQRT_THREE * cube.getScale(); // radius of bounding sphere


    return any_of(begin(viewFrustums), end(viewFrustums), [&](const ConicalViewFrustum& frustum) {
        auto position = center - frustum.getPosition(); // position of bounding sphere in view-frame
        float distance = glm::length(position); // distance to center of bounding sphere

        // Check the size of the entity, it's possible that a "too small to see" entity is included in a
        // larger octree cell because of its position (for example if it crosses the boundary of a cell it
        // pops to the next higher cell. So we want to check to see that the entity is large enough to be seen
        // before we consider including it.
        float angularSize = frustum.getAngularSize(distance, radius);

        return angularSize > lodScaleFactor * MIN_ELEMENT_ANGULAR_DIAMETER &&
               frustum.intersects(position, distance, radius);
    });
}
bool DomainContentBackupManager::process() {
    if (isStillRunning()) {
        constexpr int64_t MSECS_TO_USECS = 1000;
        constexpr int64_t USECS_TO_SLEEP = 10 * MSECS_TO_USECS;  // every 10ms
        std::this_thread::sleep_for(std::chrono::microseconds(USECS_TO_SLEEP));

        if (_isRecovering) {
            bool isStillRecovering = any_of(begin(_backupHandlers), end(_backupHandlers), [](const BackupHandlerPointer& handler) {
                return handler->getRecoveryStatus().first;
            });

            if (!isStillRecovering) {
                _isRecovering = false;
                _recoveryFilename = "";
                emit recoveryCompleted();
            }
        }

        auto now = p_high_resolution_clock::now();
        auto sinceLastSave = now - _lastCheck;
        if (sinceLastSave > _persistInterval) {
            _lastCheck = now;

            if (!_isRecovering) {
                backup();
            }
        }
    }

    return isStillRunning();
}
bool GCodeInterpreter::IsMovementFunction(GFunction& f)
{
	const float movementTable[] = {0, 1, 2, 3};//Temp definition for current version, needs to be endhanced
	if(f.first != 'G')
		return false;
	return any_of(movementTable, movementTable + sizeof(movementTable), [&] (float p)->bool{return p==f.second;});
}
Esempio n. 6
0
bool isRecursiveType(const Type& type) {

    struct visitor : public VisitOnceTypeVisitor<bool> {
        const Type& trg;
        visitor(const Type& trg) : trg(trg) {}
        bool visit(const Type& type) const {
            if (trg == type) return true;
            return VisitOnceTypeVisitor<bool>::visit(type);
        }
        bool visitUnionType(const UnionType& type) const {
            auto reachesTrg = [&](const Type* cur) { return this->visit(*cur); };
            return any_of(type.getElementTypes(), reachesTrg);
        }
        bool visitRecordType(const RecordType& type) const {
            auto reachesTrg = [&](const RecordType::Field& cur) { return this->visit(cur.type); };
            return any_of(type.getFields(), reachesTrg);
        }
    };

    // record types are recursive if they contain themselves
    if (const RecordType* r = dynamic_cast<const RecordType*>(&type)) {
        auto reachesOrigin = visitor(type);
        return any_of(r->getFields(), [&](const RecordType::Field& field)->bool { return reachesOrigin(field.type); });
    }

    return false;
}
Esempio n. 7
0
bool ProcessList::any_of_process_is_running(const list<wstring> & processes)
{
	auto running_processes = get_processes();

	return any_of(processes.cbegin(), processes.cend(),
		[&](auto process) { return find(running_processes.cbegin(), running_processes.cend(), process) != running_processes.cend(); });
}
Esempio n. 8
0
 static constexpr auto apply(Set set) {
     return searchable_set([=](auto p) {
         return set.find([=](auto set) {
             return any_of(set, p);
         }).find(p);
     });
 }
Esempio n. 9
0
string HardwareDevice::display_name(
	const DeviceManager &device_manager) const {
	const auto hw_dev = hardware_device();

	// If we can find another device with the same model/vendor then
	// we have at least two such devices and need to distinguish them.
	const auto &devices = device_manager.devices();
	const bool multiple_dev = hw_dev && any_of(
		devices.begin(), devices.end(),
		[&](shared_ptr<devices::HardwareDevice> dev) {
			return dev->hardware_device()->vendor() ==
					hw_dev->vendor() &&
				dev->hardware_device()->model() ==
					hw_dev->model() &&
				dev->device_ != device_;
		});

	vector<string> parts = {device_->vendor(), device_->model()};

	if (multiple_dev) {
		parts.push_back(device_->version());
		parts.push_back(device_->serial_number());

		if ((device_->serial_number().length() == 0) &&
			(device_->connection_id().length() > 0))
			parts.push_back("(" + device_->connection_id() + ")");
	}

	return join(parts, " ");
}
Esempio n. 10
0
bool
union_shape::is_inside (const vec3f& p) const
{
    return    hexa::is_inside(p, bounding_box())
           && any_of(shapes_, [&](const std::unique_ptr<shape>& s)
                                        { return s->is_inside(p); });
}
Esempio n. 11
0
void ObjectSet::boundingSphere(QVector3D *center, float *radius)
{
    DisplayObject::m.lock();

    if (DisplayObject::begin() == DisplayObject::end())
    {
        *center = QVector3D(0,0,0);
        *radius = 0.0;
        DisplayObject::m.unlock();
        return;
    }

    bool hasSelection = any_of(DisplayObject::begin(), DisplayObject::end(),
                               [] (std::pair<const uint, DisplayObject *> &i) {
                                   return i.second->hasSelection();
                               });

    DisplayObject *a = DisplayObject::begin()->second, *b;
    farthestPointFrom(a, &b, hasSelection);
    farthestPointFrom(b, &a, hasSelection);

    *center = (a->center() + b->center()) / 2;
    *radius = (a->center() - b->center()).length() / 2;

    ritterSphere(center, radius, hasSelection);

    float maxRadius = 0.0;
    for (auto i = DisplayObject::begin(); i != DisplayObject::end(); i++)
        if (i->second->radius() > maxRadius && (!hasSelection || i->second->hasSelection()))
            maxRadius = i->second->radius();

    *radius += 2 * maxRadius;

    DisplayObject::m.unlock();
}
Esempio n. 12
0
int main()
{
    if constexpr(any_of(1, 2, 3).is(4))
    {
        std::cout << 1 << std::endl;
    }
    else
    {
Esempio n. 13
0
void testSamplingCommon(Project &p, Func samplingFunc) {
    vector<vector<int>> orders(10);
    for(int i=0; i<10; i++) {
        orders[i] = samplingFunc(p);
        ASSERT_TRUE(p.isOrderFeasible(orders[i]));
    }
    ASSERT_TRUE(any_of(orders.begin(), orders.end(), [&p](vector<int> &order) { return !equal(order.begin(), order.end(), p.topOrder.begin(), p.topOrder.end()); }));
}
Esempio n. 14
0
bool CBaseControl::OnEvent(sf::Event const & event)
{
	auto HandledEvent = [&](auto & child) {
		return child->OnEvent(event);
	};

	return any_of(m_children.rbegin(), m_children.rend(), HandledEvent)
		|| DispatchOwnEvent(event);
}
Esempio n. 15
0
   /// <summary>Check whether listBox contains a specified string</summary>
   /// <param name="str">The string.</param>
   /// <param name="matchCase">match case.</param>
   /// <returns></returns>
   bool  FindComboBox::Contains(const wstring& str, bool matchCase) const
   {
      auto list = GetAllStrings();

      // Query strings in listBox
      return any_of(list.begin(), list.end(), [&str,matchCase](const wstring& s) {
         return matchCase ? s == str : StrCmpI(s.c_str(), str.c_str()) == 0;
      });
   }
Esempio n. 16
0
bool ObjectSet::hasSelection()
{
    DisplayObject::m.lock();

    bool ret = any_of(DisplayObject::begin(), DisplayObject::end(),
                      [] (std::pair<const uint, DisplayObject *> &i) {
                          return i.second->hasSelection();
                      });

    DisplayObject::m.unlock();

    return ret;
}
Esempio n. 17
0
int main(void){
    std::ifstream in;
    in.open("program.txt");
    std::ofstream log;
    log.open("calculator.log");
    std::ofstream err;
    err.open("debug.log");
    Scanner scan{in};
    Calculator calc{scan};
    std::streambuf *logbuff = std::clog.rdbuf(log.rdbuf());
    std::streambuf *errbuff = std::cerr.rdbuf(err.rdbuf());
    while(calc.run(std::cout, std::clog));

    auto vars = calc.get_table();
    auto var_end = remove_if(begin(vars), end(vars), [](Calculator::symbol_t& a){return !a.writen;});
    //std::cout << vars << std::endl;

    std::cout << std::endl << "Variable Statistics: " << std::endl;

    // print the things in alphabetical order
    sort(begin(vars), var_end);
    for_each(begin(vars), var_end, [](Calculator::symbol_t& a){std::cout << a << std::endl;});

    std::cout << "Number of variable names > m: " << count_if(begin(vars), var_end, [](Calculator::symbol_t& a){return a.name > "m";}) << std::endl;
    std::cout << "Minimum element value: "     << *min_element(begin(vars), var_end, val_comp)    << std::endl;
    std::cout << "Maximum element value: "     << *max_element(begin(vars), var_end, val_comp)    << std::endl;
    std::cout << "Any of the elements have a value > 50? " <<std::boolalpha<< any_of(begin(vars), var_end, [](Calculator::symbol_t& a){return a.val > 50;})  << std::endl;
    std::cout << "Print the first variable found between i and n: " << *find_if(begin(vars), var_end, [](Calculator::symbol_t& a){return a.name > "i"&&a.name<"n";}) << std::endl;
    std::cout << "Increase every value of the table by 5: "  << std::endl;// (hint transform)
    for_each(begin(vars), var_end, [](Calculator::symbol_t& a){a.val+=5;});
    for_each(begin(vars), var_end, [](Calculator::symbol_t& a){std::cout << a << std::endl;});
    std::cout << "Sort the table entries by value (not by variable name): "  << std::endl;
    sort(begin(vars), var_end, val_comp);
    for_each(begin(vars), var_end, [](Calculator::symbol_t& a){std::cout << a << std::endl;});
    std::cout << "Show the partial sum of all values in the table: " << std::endl;
    std::vector<Calculator::symbol_t> part_sums;
    partial_sum(begin(vars), var_end, back_inserter(part_sums));
    for_each(begin(part_sums), end(part_sums), [](Calculator::symbol_t& a){std::cout << a << std::endl;});


    in.close();
    log.close();
    err.close();
    std::clog.rdbuf(logbuff);
    std::cerr.rdbuf(errbuff);
    return 0;
}
Esempio n. 18
0
bool CharacterController::checkForObstacles() {
    // We can't drive without a vehicle
    VehicleObject *vehicle = character->getCurrentVehicle();
    if (vehicle == nullptr) {
        return false;
    }

    HitTest test{*vehicle->engine->dynamicsWorld};

    auto[center, halfSize] = vehicle->obstacleCheckVolume();
    const auto rotation = vehicle->getRotation();
    center = vehicle->getPosition() + rotation * center;
    auto results = test.boxTest(center, halfSize, vehicle->getRotation());

    return any_of(results.begin(), results.end(),
                  [&](const auto &hit) {
                      return !(hit.object == vehicle ||
                               hit.body->isStaticObject());
                  });
}
Esempio n. 19
0
        void action(iscore::ActionManager& mgr, iscore::MaybeDocument doc) override
        {
            if(!doc)
            {
                setEnabled(mgr, false);
                return;
            }

            auto focus = doc->focus.get();
            if(!focus)
            {
                setEnabled(mgr, false);
                return;
            }

            auto lm = dynamic_cast<const Process::LayerModel*>(focus);
            if(!lm)
            {
                setEnabled(mgr, false);
                return;
            }

            auto proc = dynamic_cast<const Scenario::ScenarioInterface*>(&lm->processModel());
            if(!proc)
            {
                setEnabled(mgr, false);
                return;
            }

            const auto& sel = doc->selectionStack.currentSelection();
            auto res = any_of(sel, [] (auto obj) {
                auto ptr = obj.data();
                return bool(dynamic_cast<const Scenario::ConstraintModel*>(ptr))
                    || bool(dynamic_cast<const Scenario::EventModel*>(ptr))
                    || bool(dynamic_cast<const Scenario::StateModel*>(ptr));
            });

            setEnabled(mgr, res);
        }
Esempio n. 20
0
TypeSet getLeastCommonSupertypes(const Type& a, const Type& b) {

    // make sure they are in the same type environment
    assert(a.getTypeEnvironment().isType(a) && a.getTypeEnvironment().isType(b));

    // if they are equal it is easy
    if (a == b) {
        return TypeSet(a);
    }

    // equally simple - check whether one is a sub-type of the other
    if (isSubtypeOf(a,b)) {
        return TypeSet(b);
    }
    if (isSubtypeOf(b,a)) {
        return TypeSet(a);
    }

    // harder: no obvious relation => hard way
    TypeSet superTypes;
    TypeSet all = a.getTypeEnvironment().getAllTypes();
    for(const Type& cur : all) {
        if (isSubtypeOf(a, cur) && isSubtypeOf(b, cur)) {
            superTypes.insert(cur);
        }
    }

    // filter out non-least super types
    TypeSet res;
    for(const Type& cur : superTypes) {
        bool least = !any_of(superTypes, [&](const Type& t) {
                return t != cur && isSubtypeOf(t, cur);
                });
        if (least) res.insert(cur);
    }

    return res;

}
Esempio n. 21
0
int main()
{
	vector<int> coll;
	vector<int>::iterator pos;

	insert_elements(coll, 1, 9);
	print_elements(coll, "coll: ");

	// define an object for the predicate (using a lambda)
	auto isEven = [](int elem) {
		return elem % 2 == 0;
	};

	// print whether all, any, or none of the elements are/is even
	cout << boolalpha << "all even?:  "
		<< all_of(coll.cbegin(), coll.cend(), isEven) << endl;
	cout << "any even?:  "
		<< any_of(coll.cbegin(), coll.cend(), isEven) << endl;
	cout << "none even?: "
		<< none_of(coll.cbegin(), coll.cend(), isEven) << endl;


}
 int minDeletionSize(vector<string>& A) {
     int result = 0;
     unordered_set<int> unsorted;
     for (int i = 0; i < A.size() - 1; ++i) {
         unsorted.emplace(i);
     }
     for (int j = 0; j < A[0].size(); ++j) {
         if (any_of(unsorted.begin(), unsorted.end(),
                    [&](int i) {
                        return A[i][j] > A[i + 1][j];
                    })
            ) {
             ++result;
         } else {
             unordered_set<int> tmp(unsorted);
             for (const auto& i : tmp) {
                 if (A[i][j] < A[i + 1][j]) {
                     unsorted.erase(i);
                 }
             }
         }
     }
     return result;
 }
Esempio n. 23
0
  /*
   * Takes a directed graph and converts it to an
   * undirected graph, then finds the Articulation Points
   * in the graph.
   * 
   * An articulation point is a vertex in the graph that
   * if it were to be removed would disconnect the graph.
   *
   * id est: a node in a network s.t. if the node went down,
   * a portion of the network (other than that node) would
   * also go down.
   */
  void solve( vector<vector<int> >& graph ) {
    static int graph_num = 1;
    graph.push_back( vector<int>(0) ); // just for convience, fill in the last vertex
    const int graph_sz = static_cast<int>( graph.size() );
    vector<vector<int> > full_graph;
    full_graph.reserve( graph_sz );

    //
    // Since the graph is undirected, it is more efficient to one time,
    // fill in the missing values, i.e. if a is adjacent to b, then add
    // b adjacent to a
    //
    for( int v = 0; v < graph_sz; ++v ) {
      auto row = graph.at(v);
      vector<int> adj_list;
      for_each( row.begin(), row.end(), [&](int n) { if( n != 0 ) { adj_list.push_back(n); } } );
      int count = 1;
      for( auto& it : graph ) {
	if( any_of( it.begin(), it.end(), [&](int n) { return (n == static_cast<int>(v+1)); } ) ) {
	  adj_list.push_back(count);
	}
	count++;
      }
      full_graph.push_back( adj_list );
    }

    //
    // Create the auxillary information vector that is needed for each vertex
    //
    vector<Vertex> aux;
    for( int i = 0; i < graph_sz; ++i ) {
      aux.emplace_back( false, INT_MAX, INT_MAX, -1 );
    }

    vector<int> ArtPoints;
    int counter = 1; // since passing by reference, have to have an actual variable
    //
    // if the graph is unconnected, then need to run several times with different
    // roots
    //
    for( int i = 1; i <= graph_sz; ++i ) {
      if(! aux.at(i-1).visited ) {
	FindArt( i, full_graph, aux, ArtPoints, counter );
      }
    }

    //
    // Output Results
    //
    cout << "Graph #" << graph_num++ << endl;
    if(! ArtPoints.empty() ) {
      sort( ArtPoints.begin(), ArtPoints.end() );
      for( auto& it : ArtPoints ) {
	cout << it << " is an articulation point." << endl;
      }
      cout << endl;
    } else {
      cout << "No articulation points (the graph is bi-connected)." << endl;
      cout << endl;
    }
  }
Esempio n. 24
0
/**
* split and trim comma-separated list of values (other delimiters can be used too, ie: semicolon).
*
* RFC 4180 difference: it does skip space-only lines and trim values unless it is " quoted ".
*
* @param[in] i_values         source string of comma separated values.
* @param[in,out] io_resultLst source string of comma separated values.
* @param[in] i_delimiters     list of delimiters, default: comma.
* @param[in] i_isUnquote      if true then do "unquote ""csv"" ", default: false.
* @param[in] i_quote          quote character, default: sql single ' quote.
* @param[in] i_locale         locale to trim space characters, defaut: user default locale.
*/
void openm::splitCsv(
    const string & i_values, 
    list<string> & io_resultLst, 
    const char * i_delimiters, 
    bool i_isUnquote, 
    char i_quote, 
    const locale & i_locale)
{ 
    // if source is empty then return empty result
    string::size_type nSrcLen = i_values.length();
    if (nSrcLen <= 0) {         
        io_resultLst.clear();   // source string is empty: return empty list
        return;
    }
        
    // no delimiters: return entire source string as first element of result list
    size_t nDelimLen = (i_delimiters != nullptr) ? strnlen(i_delimiters, OM_STRLEN_MAX) : 0;
    if (0 == nDelimLen) {
        io_resultLst.clear();
        io_resultLst.push_back(trim(i_values));
        return;
    }

    // position and size in already existing list to set new values
    size_t lstSize = io_resultLst.size();
    size_t lstPos = 0;
    list<string>::iterator lstIt = io_resultLst.begin();

    // find delimiter(s) and append values into output list
    string::size_type nStart = 0;
    bool isInside = false;
    bool isDelim = false;

    for (string::size_type nPos = 0; nPos < nSrcLen; nPos++) {

        char chNow = i_values[nPos];

        // if unquote required and this is quote then toogle 'inside '' quote' status
        if (i_isUnquote && chNow == i_quote) {
            isInside = !isInside;
        }

        // if not 'inside' of quoted value then check for any of delimiters
        if (!isInside) {
            isDelim = any_of(
                i_delimiters,
                i_delimiters + nDelimLen,
                [chNow](const char i_delim) -> bool { return chNow == i_delim; }
            );
        }

        // if this is delimiter or end of string then unquote value and append to the list
        if (isDelim || nPos == nSrcLen - 1) {

            // column size: until end of line or until next delimiter
            size_t nLen = (nPos == nSrcLen - 1 && !isDelim) ? nSrcLen - nStart : nPos - nStart;

            // if previous list had enough columns then use it else append new column
            // trim spaces and unquote value if required
            if (lstPos < lstSize) {
                lstIt->clear();     // clear previous value
                lstIt->append((
                    i_isUnquote ?
                    toUnQuoted(i_values.substr(nStart, nLen), i_quote, i_locale) :
                    trim(i_values.substr(nStart, nLen), i_locale)
                    ));
                ++lstIt;    // next column in existing list buffer
            }
            else {  // append new column
                io_resultLst.emplace_back((
                    i_isUnquote ?
                    toUnQuoted(i_values.substr(nStart, nLen), i_quote, i_locale) :
                    trim(i_values.substr(nStart, nLen), i_locale)
                    ));
            }
            ++lstPos;   // column count in the current list

            // if this is like: a,b, where delimiter at the end of line then append empty "" value
            if (nPos == nSrcLen - 1 && isDelim) {
                if (lstPos < lstSize) {
                    lstIt->clear();     // clear previous column value
                    ++lstIt;
                }
                else {
                    io_resultLst.emplace_back("");  // append new empty column
                }
                ++lstPos;
            }

            nStart = nPos + 1;  // skip delimiter and continue
            isDelim = false;
        }
    }

    // if current line have less columns than previous buffer then trim extra columns from result
    if (lstPos < lstSize) {
        io_resultLst.resize(lstPos);
    }
}
Esempio n. 25
0
File: main.cpp Progetto: CCJY/coliru
int main() {
    if(any_of(10, {1,2,3,4,5,10,14})) {
        std::cout << "...";
    }
}
Esempio n. 26
0
 bool visitRecordType(const RecordType& type) const {
     auto reachesTrg = [&](const RecordType::Field& cur) { return this->visit(cur.type); };
     return any_of(type.getFields(), reachesTrg);
 }
Esempio n. 27
0
 bool visitUnionType(const UnionType& type) const {
     auto reachesTrg = [&](const Type* cur) { return this->visit(*cur); };
     return any_of(type.getElementTypes(), reachesTrg);
 }
    QRect QtDistanceFieldFontTextureGenerator::calculateAutocrop(const QImage& image)
    {
        typedef vector<QPoint> line;
        /*
         *Binary search for all-black scanlines.
         */
        auto blackScanline = [&](line scanline) {
            return !(any_of(scanline.begin(), scanline.end(), [&](QPoint point){return image.pixel(point) != QColor(Qt::black).rgb();}));
        };

        auto buildHorizontalScanline = [&](int lineNumber){
            line scanline;
            for (int i = 0; i < image.width(); ++i)
            {
                scanline.push_back(QPoint(i, lineNumber));
            }
            return scanline;
        };

        auto buildVerticalScanline = [&](int lineNumber){
            line scanline;
            for (int j = 0; j < image.height(); ++j)
            {
                scanline.push_back(QPoint(lineNumber, j));
            }
            return scanline;
        };

        // Scan between blackLimit and middleLimit, either horizontally or vertically, and return the result.
        auto binarySearch = [&](int blackLimit, int middleLimit, bool horizontal_scan, bool increasingLine) {

            int testLineNumber = middleLimit;
            int allBlackScanline = blackLimit;
            int hasWhiteScanline = middleLimit;
            int delta;
            while (abs(allBlackScanline - hasWhiteScanline) > 1)
            {
                line scanline = horizontal_scan ? buildHorizontalScanline(testLineNumber) : buildVerticalScanline(testLineNumber);
                bool isBlack = blackScanline(scanline);
                if (isBlack){
                    allBlackScanline = testLineNumber;
                    delta = abs((allBlackScanline - hasWhiteScanline) / 2);
                    //increasingLine means black scanline moving positive.
                    testLineNumber = increasingLine ? allBlackScanline + delta : allBlackScanline - delta;
                } else {
                    hasWhiteScanline = testLineNumber;
                    delta = abs((allBlackScanline - hasWhiteScanline) / 2);
                    // It's met by a negative scanline.
                    testLineNumber = increasingLine ? hasWhiteScanline - delta : hasWhiteScanline + delta;
                }
            }
            return allBlackScanline;
        };

        // Recall in Qt land, 0 = top, height = bottom.
        int topCrop = binarySearch(0, image.height() / 2, true, true);
        int leftCrop = binarySearch(0, image.width() / 2, false, true);
        int bottomCrop = binarySearch(image.height(), image.height() / 2, true, false);
        int rightCrop = binarySearch(image.width(), image.width() / 2, false, false);

        QRect rect(leftCrop, topCrop, rightCrop - leftCrop, bottomCrop - topCrop);
        cout << StrCon(rect).to_s();
        return rect;

    }
Esempio n. 29
0
bool AudioTimingControllerKaraoke::IsNearbyMarker(int ms, int sensitivity) const {
	TimeRange range(ms - sensitivity, ms + sensitivity);
	return any_of(markers.begin(), markers.end(), [&](KaraokeMarker const& km) {
		return range.contains(km);
	});
}
bool GCodeInterpreter::IsAxis(char c)
{
	static const string axis("XYZIJK");
	c = toupper(c);
	return any_of(axis.begin(), axis.end(), [&](char a)->bool{return a == c;});
}