void LfGrid::MoveSite(int id, int x, int y) { auto row = get_coordinate(y); auto col = get_coordinate(x); if (grid[col][row]->is_full()) { auto new_bucket = make_unique<LfBucket>(); new_bucket->next_ = move(grid[col][row]); grid[col][row] = move(new_bucket); } auto added = grid[col][row]->Add(id, x, y); auto & index = IdIndex::get_mutable_instance(); auto p = index.find(id); if (p != index.end()) { if (p->second.col != col || p->second.row != row) { grid[p->second.col][p->second.row]->Del(id, x, y); p->second.col = col; p->second.row = row; } p->second.p_bucket_ = added.first; p->second.index = added.second; } else index.emplace(make_pair(id, IdElement(added.first, added.second, col, row))); }
void LfGrid::Query(vector<SiteValue>& result, int x1, int y1, int x2, int y2, int tq) { int cx1 = get_coordinate(x1); int cy1 = get_coordinate(y1); int cx2 = get_coordinate(x2); int cy2 = get_coordinate(y2); for (int ax = cx1 + 1; ax < cx2; ax++) for (int ay = cy1 + 1; ay < cy2; ay++) RetrieveAllSitesInCell(result, ax, ay); for (int x = cx1 + 1; x < cx2; x++) { RetrieveSitesInCell(result, x, cy1, x1, y1, x2, y2, tq); RetrieveSitesInCell(result, x, cy2, x1, y1, x2, y2, tq); } for (int y = cy1; y <= cy2; y++) { RetrieveSitesInCell(result, cx1, y, x1, y1, x2, y2, tq); RetrieveSitesInCell(result, cx2, y, x1, y1, x2, y2, tq); } vector<SiteValue> unique_result_sites; for (auto& r : result) { bool found_one = false; for (auto& u : unique_result_sites) { if (u.id == r.id) { if (u.tu < 0) u = r; found_one = true; break; } } if (!found_one) unique_result_sites.push_back(r); } result.swap(unique_result_sites); }
void Grid::MoveSite(int id, int x, int y) { auto& si = SecondaryIndex::get_mutable_instance(); auto p = si.find(id); if (p == si.end()) { AddSite(id, x, y); return; } int row = get_coordinate(y); int col = get_coordinate(x); lock_guard<mutex>{s_mutex[id]}; auto ptr = &p->second; if (ptr->col == col && ptr->row == row) {// local update auto p_site = ptr->p_bucket->sites_.begin() + ptr->index; p_site->SetValue(x, y, static_cast<int>(time(nullptr))); } else {// non-local update if (ptr->row_ld >= 0) // ReSharper disable once CppPossiblyErroneousEmptyStatements while (RemoveFromCell(id, ptr->col_ld, ptr->row_ld) == false); auto added = AddToCell(id, x, y, col, row); ptr->p_bucket->sites_[ptr->index].NegateTime(); ptr->RollInValues(added.first, added.second, col, row); } }
void Grid::AddSite(int id, int x, int y) { int col = get_coordinate(x); int row = get_coordinate(y); auto added = AddToCell(id, x, y, col, row); auto& si = SecondaryIndex::get_mutable_instance(); assert(si.find(id) == si.end()); si.emplace(make_pair(id, SecondaryElement(added.first, added.second, col, row))); }
void clique::create_grid(void) { clique::data_info info; get_data_info(info); const std::size_t dimension = m_data_ptr->at(0).size(); const std::size_t amount_blocks = static_cast<std::size_t>(std::pow(m_intervals, dimension)); m_result_ptr->blocks().reserve(amount_blocks); auto iterator = coordinate_iterator(dimension, m_intervals); std::vector<bool> point_availability(m_data_ptr->size(), true); for (std::size_t i = 0; i < amount_blocks; ++i) { clique_block_location logical_location = iterator.get_coordinate(); ++iterator; clique_spatial_block spatial_block; get_spatial_location(logical_location, info, spatial_block); clique_block cell(logical_location, std::move(spatial_block)); cell.capture_points(*m_data_ptr, point_availability); m_result_ptr->blocks().push_back(std::move(cell)); m_cells_map.insert({ location_to_key(m_result_ptr->blocks().back().get_logical_location()), &(m_result_ptr->blocks().back()) }); } }
static int ctrl_tool_response_click(p_void_data_t p_void_data, p_void_ctrl_tool_t p_void_ctrl_tool, const m_evt_code_t *p_m_evt_code) { int i=0; int cur_item=-1; coordinate_t coordinate; p_void_data_t pvd=p_void_data; ctrl_tool_t *ctrl_tool=(ctrl_tool_t *)p_void_ctrl_tool; const m_evt_code_t *m_evt_code=p_m_evt_code; if((NULL==pvd)||(NULL==ctrl_tool)||(NULL==m_evt_code)){ return cur_item; } if(NULL==get_coordinate(&coordinate,&m_evt_code->m_evt_param.mouse_t.mouse)){ return cur_item; } for(i=0; i<ctrl_tool->total_item; i++){ if(FALSE==ctrl_tool->p_ctrl_tool_resource[i].visible){ continue; } if(FALSE!=point_in_rect(&ctrl_tool->left_vertex,&ctrl_tool->p_ctrl_tool_resource[i].ctrl_tool_res.rect,&coordinate)){ ctrl_tool->cur_item=i; if((FALSE!=ctrl_tool->p_ctrl_tool_resource[ctrl_tool->cur_item].visible)&&(NULL!=ctrl_tool->p_ctrl_tool_callback->pf_event_pen_down)){ ctrl_tool->p_ctrl_tool_callback->pf_event_pen_down(pvd,m_evt_code,ctrl_tool->cur_item); cur_item=ctrl_tool->cur_item; } } } return cur_item; }
S8 ADS7843::update_state() { static U8 preTouchState = 0; static int preTouchStateNum = 0; touchState.isTouch = ADS7483_IS_PRESSED(); //获取本次的按下状态 //如果本次和上次都没有按下, 直接返回 if(preTouchState == 0 && touchState.isTouch == 0) { touchState.free = true; return -1; } else touchState.free = false; //本次没有按下 if(touchState.isTouch == 0) { preTouchStateNum = 0; touchState.isHold = 0; } else { bool b; do { b = get_coordinate(&touchState.touchPoint); } while(!b && ADS7483_IS_PRESSED()); //Out::printl(0, 8, "%d %d %d" , touchState.touchPoint.x, touchState.touchPoint.y, i); } if(touchState.isTouch && preTouchState) preTouchStateNum ++; if(preTouchStateNum >= N) touchState.isHold = 1; preTouchState = touchState.isTouch; return touchState.isTouch; //返回当前的按下状态 }