static double compress(info * nl, int nn) { info *p = nl; info *q; int i, j; double s, sc = 0; pointf pt; for (i = 0; i < nn; i++) { q = p + 1; for (j = i + 1; j < nn; j++) { if (overlap(p->bb, q->bb)) return 0; if (p->pos.x == q->pos.x) pt.x = HUGE_VAL; else { pt.x = (p->wd2 + q->wd2) / fabs(p->pos.x - q->pos.x); } if (p->pos.y == q->pos.y) pt.y = HUGE_VAL; else { pt.y = (p->ht2 + q->ht2) / fabs(p->pos.y - q->pos.y); } if (pt.y < pt.x) s = pt.y; else s = pt.x; if (s > sc) sc = s; q++; } p++; } return sc; }
int main() { while(scanf("%d",&n) && n!=-1) { for(int i=0;i<n;++i) ring[i].get(); for(int i=0;i<n;++i) for(int j=0;j<n;++j) map[i][j] = false; for(int i=0;i<n;++i) for(int j=i+1;j<n;++j) if(overlap(i,j)) map[i][j] = map[j][i] = true; int Max=0; memset(used,false,sizeof(used)); for(int i=0;i<n;++i) if(!used[i]) { count = 0; go(i); if(count > Max) Max = count; } if(Max == 1) printf("The largest component contains %d ring.\n",1); else printf("The largest component contains %d rings.\n",Max); } return 0; }
void rotpc() { struct piece pc = brd.pc; pc.rotid = (pc.rotid+1) % pc.tet->rotcount; if (!overlap(pc)) brd.pc = pc; }
ShardChunkManager* ShardChunkManager::clonePlus( const BSONObj& min , const BSONObj& max , const ShardChunkVersion& version ) { // it is acceptable to move version backwards (e.g., undoing a migration that went bad during commit) // but only cloning away the last chunk may reset the version to 0 uassert( 13591 , "version can't be set to zero" , version.isSet() ); if ( ! _chunksMap.empty() ) { // check that there isn't any chunk on the interval to be added RangeMap::const_iterator it = _chunksMap.lower_bound( max ); if ( it != _chunksMap.begin() ) { --it; } if ( overlap( min , max , it->first , it->second ) ) { ostringstream os; os << "ranges overlap, " << "requested: " << min << " -> " << max << " " << "existing: " << it->first.toString() + " -> " + it->second.toString(); uasserted( 13588 , os.str() ); } } auto_ptr<ShardChunkManager> p( new ShardChunkManager ); p->_key = this->_key; p->_chunksMap = this->_chunksMap; p->_chunksMap.insert( make_pair( min.getOwned() , max.getOwned() ) ); p->_version = version; if( version > _collVersion ) p->_collVersion = version; else p->_collVersion = this->_collVersion; p->_fillRanges(); return p.release(); }
void mvpcleft() { struct piece pc = brd.pc; pc.pos.x -= 1; if (!overlap(pc)) brd.pc = pc; }
void mvpcright() { struct piece pc = brd.pc; pc.pos.x += 1; if (!overlap(pc)) brd.pc = pc; }
inline ValueType spatialaggregate::OcTreeNode< CoordType, ValueType >::getValueInVolume( const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, CoordType minimumSearchVolumeSize ) { if( type == OCTREE_LEAF_NODE ) { if( inRegion( minPosition, maxPosition ) ) return value; return ValueType(0); } else { if( !overlap( minPosition, maxPosition ) ) return ValueType(0); if( containedInRegion( minPosition, maxPosition ) ) return value; if( (this->maxPosition[0] - this->minPosition[0]) - minimumSearchVolumeSize <= -OCTREE_EPSILON*minimumSearchVolumeSize ) { return value; } ValueType value = ValueType(0); for( unsigned int i = 0; i < 8; i++ ) { if(!siblings[i]) continue; value += siblings[i]->getValueInVolume( minPosition, maxPosition, minimumSearchVolumeSize ); } return value; } }
bool TrackerTLDImpl::Nexpert::operator()(Rect2d box) { if( overlap(resultBox_, box) < NEXPERT_THRESHOLD ) return false; else return true; }
ExecStatus Nq<View0,View1>::propagate(Space& home, const ModEventDelta&) { if (x0.assigned() && x1.assigned()) { return overlap(x0.val(),x1.val()) ? ES_FAILED : home.ES_SUBSUMED(*this); } return ES_FIX; }
PyObject* PyBobIpBase_blockOutputShape(PyObject*, PyObject* args, PyObject* kwds) { BOB_TRY /* Parses input arguments in a single shot */ char** kwlist = s_blockOutputShape.kwlist(); PyBlitzArrayObject* input = 0; blitz::TinyVector<int,2> size, overlap(0,0); PyObject* flat_ = 0; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&(ii)|(ii)O!", kwlist, &PyBlitzArray_Converter, &input, &size[0], &size[1], &overlap[0], &overlap[1], &PyBool_Type, &flat_)) return 0; auto input_ = make_safe(input); if (input->ndim != 2) { PyErr_Format(PyExc_TypeError, "block shape can only be computed from and to 2D arrays"); return 0; } if (f(flat_)){ auto shape = block_shape3(input, size, overlap); return Py_BuildValue("(iii)", shape[0], shape[1], shape[2]); } else { auto shape = block_shape4(input, size, overlap); return Py_BuildValue("(iiii)", shape[0], shape[1], shape[2], shape[3]); } BOB_CATCH_FUNCTION("in block_output_shape", 0) }
void getS(int nbf, int *nprim, int *istart, double *xcenter, double *ycenter, double *zcenter, int *lpower,int *mpower, int *npower, int n2, double *coef, double *alpha, double *S){ int i,j,iprim,jprim,jindex,iindex; for (j=0; j<nbf; j++){ for (i=0; i<nbf; i++){ S[i+j*nbf] = 0.; for (jprim=0; jprim<nprim[j]; jprim++){ jindex = istart[j]+jprim; for (iprim=0; iprim<nprim[i]; iprim++){ iindex = istart[i]+iprim; S[i+j*nbf] += coef[iindex]*coef[jindex] *overlap(alpha[iindex],lpower[i],mpower[i], npower[i],xcenter[i],ycenter[i], zcenter[i], alpha[jindex],lpower[j],mpower[j], npower[j],xcenter[j],ycenter[j], zcenter[j]); } } } } }
TBOX TBOX::intersection( //shared area box const TBOX &box) const { inT16 left; inT16 bottom; inT16 right; inT16 top; if (overlap (box)) { if (box.bot_left.x () > bot_left.x ()) left = box.bot_left.x (); else left = bot_left.x (); if (box.top_right.x () < top_right.x ()) right = box.top_right.x (); else right = top_right.x (); if (box.bot_left.y () > bot_left.y ()) bottom = box.bot_left.y (); else bottom = bot_left.y (); if (box.top_right.y () < top_right.y ()) top = box.top_right.y (); else top = top_right.y (); } else { left = MAX_INT16; bottom = MAX_INT16; top = -MAX_INT16; right = -MAX_INT16; } return TBOX (left, bottom, right, top); }
Vector3d GJKSimplex::computeClosestPointForSubset(Bits subset) { // Closest point v = sum(lambda_i * points[i]) Vector3d v; m_maxLengthSquare = 0.0; // deltaX = sum of all det[subset][i] double deltaX = 0.0; int i; Bits bit; // For each four point in the possible simplex set for (i=0, bit=0x1; i<4; i++, bit <<= 1) { // If the current point is in the subset if (overlap(subset, bit)) { // deltaX = sum of all det[subset][i] deltaX += m_det[subset][i]; if (m_maxLengthSquare < m_pointsLengthSquare[i]) { m_maxLengthSquare = m_pointsLengthSquare[i]; } // Closest point v = sum(lambda_i * points[i]) v += m_det[subset][i] * m_points[i]; } } assert(deltaX > 0.0); // Return the closest point "v" in the convex hull for the given subset return (double(1.0) / deltaX) * v; }
point2<T> overlap( const point2<T>& pt, const polygon2<T>& poly ) { // check if either is null if( pt == point2<T>::null( ) || poly == polygon2<T>::null( ) ) { return point2<T>::null( ); } // check bounding box first if( overlap( pt, poly.m_bounding_box ) == point2<T>::null( ) ) { return point2<T>::null( ); } // check actual polygon // the point should be on the same side of every line making // up the polygon if it is inside float dir = poly.direction( poly.m_hull[0], poly.m_hull[1], pt ); bool side = dir > std::numeric_limits<T>::epsilon( ); for( unsigned int i = 1; i < poly.m_hull.size( ); ++i ) { // check last element w/ first if( i == poly.m_hull.size( ) - 1 ) { dir = poly.direction( poly.m_hull[i], poly.m_hull[0], pt ); } else { dir = poly.direction( poly.m_hull[i], poly.m_hull[i+1], pt ); } // different side, can't be inside if( side != (dir > std::numeric_limits<T>::epsilon( )) ) { return point2<T>::null( ); } } return pt; }
void GJKSimplex::addPoint(const Vector3d& point, const Vector3d& suppPointA, const Vector3d& suppPointB) { assert(!isFull()); m_lastFound = 0; m_lastFoundBit = 0x1; // Look for the bit corresponding to one of the four point that is not in // the current simplex while (overlap(m_bitsCurrentGJKSimplex, m_lastFoundBit)) { m_lastFound++; m_lastFoundBit <<= 1; } assert(m_lastFound >= 0 && m_lastFound < 4); // Add the point into the simplex m_points[m_lastFound] = point; m_pointsLengthSquare[m_lastFound] = point * point; m_allBits = m_bitsCurrentGJKSimplex | m_lastFoundBit; // Update the cached values updateCache(); // Compute the cached determinant values computeDeterminants(); // Add the support points of objects A and B m_suppPointsA[m_lastFound] = suppPointA; m_suppPointsB[m_lastFound] = suppPointB; }
ExecStatus NqFloat<View>::propagate(Space& home, const ModEventDelta&) { if (x0.assigned()) { return (overlap(x0.val(),c)) ? ES_FAILED : home.ES_SUBSUMED(*this); } return ES_FIX; }
PyObject* PyBobIpBase_block(PyObject*, PyObject* args, PyObject* kwds) { BOB_TRY /* Parses input arguments in a single shot */ char** kwlist = s_block.kwlist(); PyBlitzArrayObject* input = 0,* output = 0; blitz::TinyVector<int,2> size, overlap(0,0); PyObject* flat_ = 0; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&(ii)|(ii)O&O!", kwlist, &PyBlitzArray_Converter, &input, &size[0], &size[1], &overlap[0], &overlap[1], &PyBlitzArray_OutputConverter, &output, &PyBool_Type, &flat_)) return 0; auto input_ = make_safe(input), output_ = make_xsafe(output); bool flat = f(flat_); if (input->ndim != 2) { PyErr_Format(PyExc_TypeError, "blocks can only be extracted from and to 2D arrays"); return 0; } bool return_out = false; if (output){ if (output->type_num != input->type_num){ PyErr_Format(PyExc_TypeError, "``input`` and ``output`` must have the same data type"); return 0; } if (output->ndim != 3 && output->ndim != 4){ PyErr_Format(PyExc_TypeError, "``output`` must have either three or four dimensions, not %" PY_FORMAT_SIZE_T "d", output->ndim); return 0; } flat = output->ndim == 3; } else { return_out = true; // generate output in the desired shape if (flat){ auto res = block_shape3(input, size, overlap); Py_ssize_t osize[] = {res[0], res[1], res[2]}; output = (PyBlitzArrayObject*)PyBlitzArray_SimpleNew(input->type_num, 3, osize); } else { auto res = block_shape4(input, size, overlap); Py_ssize_t osize[] = {res[0], res[1], res[2], res[3]}; output = (PyBlitzArrayObject*)PyBlitzArray_SimpleNew(input->type_num, 4, osize); } output_ = make_safe(output); } switch (input->type_num){ case NPY_UINT8: if (flat) block_inner<uint8_t,3>(input, size, overlap, output); else block_inner<uint8_t,4>(input, size, overlap, output); break; case NPY_UINT16: if (flat) block_inner<uint16_t,3>(input, size, overlap, output); else block_inner<uint16_t,4>(input, size, overlap, output); break; case NPY_FLOAT64: if (flat) block_inner<double,3>(input, size, overlap, output); else block_inner<double,4>(input, size, overlap, output); break; default: PyErr_Format(PyExc_TypeError, "block does not work on 'input' images of type %s", PyBlitzArray_TypenumAsString(input->type_num)); } if (return_out){ return PyBlitzArray_AsNumpyArray(output, 0); } else Py_RETURN_NONE; BOB_CATCH_FUNCTION("in block", 0) }
point2<T> overlap( const point2<T>& pt, const segment2<T>& segment ) { // check if either is null if( pt == point2<T>::null( ) || segment == segment2<T>::null( ) ) { return point2<T>::null( ); } // not working?? return overlap( pt, make_line( segment ) ); }
bool canAttendMeetings(vector<Interval>& intervals) { sort(intervals.begin(), intervals.end(), compare); int n = intervals.size(); for (int i = 0; i < n - 1; i++) if (overlap(intervals[i], intervals[i + 1])) return false; return true; }
bool overlap_any(struct nobjs *pv, struct obj *p, int pad) { int n, m; struct obj *l; for (l = pv->p, m = pv->n, n = 0; n < m; ++n, ++l) if (overlap(l, p, pad)) return true; return false; }
void MonotoneChainOverlapAction::overlap(MonotoneChain& mc1, size_t start1, MonotoneChain& mc2, size_t start2) { mc1.getLineSegment(start1, overlapSeg1); mc2.getLineSegment(start2, overlapSeg2); overlap(overlapSeg1, overlapSeg2); }
void Detection::trainNegative(cv::Mat const & integral) { cv::Point currentSize; cv::Point2d doubleBox; doubleBox.x = static_cast<double>(m_boxSize.x); doubleBox.y = static_cast<double>(m_boxSize.y); // Create a list of bounding boxes to search through for( int scaleIdx = 0; scaleIdx < 5; ++scaleIdx) { // Calculate the scale for this index double scale = static_cast<double>(scaleIdx)/4.0 + 0.5; // Determine the x values currentSize.x = static_cast<int>(scale*doubleBox.x); int xMax = m_size.x - currentSize.x; int xStep = xMax / 19; if( xStep <= 0) { xMax = 0; xStep = 1; } // Loop over the x-values and generate the y-values for( int x = 0; x <= xMax; x += xStep) { currentSize.y = static_cast<int>(scale*doubleBox.y); int yMax = m_size.y - currentSize.y; int yStep = yMax / 19; if( yStep <= 0 ) { yMax = 0; yStep = 1; } // Loop over y and build the boxes for( int y = 0; y <= yMax; y += yStep) { // Create a new contact Contact newBox; newBox.position.x = x; newBox.position.y = y; newBox.dims.x = currentSize.x; newBox.dims.y = currentSize.y; if(overlap(newBox) == 0.) { m_classifier->train(integral,newBox.position, newBox.dims,0); } } } } }
void PARTICLE::ClipParticles(VERTEX * rect) { //return; float height = 0; int j; for (j = 0; j < 4; j++) { height += rect[j].y; } height /= 4.0f; height += 0.2f; int i; for (i = 0; i < MAX_PARTICLES; i++) { if (particle[i].active) { VERTEX drawpos; drawpos = particle[i].start_position; float age = curtime - particle[i].timestamp; VERTEX offset = particle[i].direction.ScaleR(age*particle[i].speed); drawpos = drawpos + offset; float dimension = 0.5f; VERTEX dprect[4]; dprect[0] = drawpos; dprect[0].x -= dimension; dprect[0].z -= dimension; dprect[1] = drawpos; dprect[1].x -= dimension; dprect[1].z += dimension; dprect[2] = drawpos; dprect[2].x += dimension; dprect[2].z += dimension; dprect[3] = drawpos; dprect[3].x += dimension; dprect[3].z -= dimension; //if (inrect(rect, drawpos))// && drawpos.y > height) if (overlap(rect, dprect) && drawpos.y > height) { if (drawpos.y - height <= 0.2) { float age = (curtime - particle[i].timestamp); particle[i].start_position = drawpos; particle[i].start_position.y = height; particle[i].longevity = particle[i].longevity - age; particle[i].timestamp = curtime; particle[i].transparency = particle[i].transparency*(1.0f-age/particle[i].longevity)*1.0f/((float)NUM_ROTATIONS+1.0f); } else particle[i].active = false; } } } }
int test(int x, int y){ int curr = start[x]; while (curr){ node n = squares[curr]; if (overlap(n.y, y)) return 0; curr = n.next; } return 1; }
// NOTE: This assumes that free variables are sorted. bool FreeVarGroup::isDisjoint(FreeVarGroup *other) { std::vector< omxFreeVar* > overlap(std::max(vars.size(), other->vars.size())); std::vector< omxFreeVar* >::iterator it = std::set_intersection(vars.begin(), vars.end(), other->vars.begin(), other->vars.end(), overlap.begin(), freeVarComp); return it - overlap.begin() == 0; }
bool overlap(const rectangle& ir, const size& valid_input_area, const rectangle & dr, const size& valid_dst_area, rectangle& op_ir, rectangle& op_dr) { if(overlap(ir, rectangle(0, 0, valid_input_area.width, valid_input_area.height), op_ir) == false) return false; rectangle good_dr; if(overlap(dr, rectangle(0, 0, valid_dst_area.width, valid_dst_area.height), good_dr) == false) return false; zoom(ir, op_ir, dr, op_dr); if(false == covered(op_dr, good_dr)) { op_dr = good_dr; zoom(dr, good_dr, ir, op_ir); } return true; }
ExecStatus NqFloat<View>::post(Home home, View x, FloatVal c){ if (x.assigned()) { if (overlap(x.val(),c)) return ES_FAILED; } else { (void) new (home) NqFloat<View>(home,x,c); } return ES_OK; }
// Cycle the current and next piece and check if the board is topped. void cyclepcs(bool holdset) { brd.pc = (holdset ? brd.holdpc : newpc()); brd.holdpc = newpc(); brd.pc.pos.y = pcheight(brd.pc); brd.pc.pos.x = brd.width/2; brd.holdpc.pos.y = 0; brd.holdpc.pos.x = 2; if (brd.grid) brd.topped = overlap(brd.pc); }
/*! A temporary Draw (during move/copy operations) of the container contents on the screen using the virtual quadTree::tmp_draw() method of the parent object. */ void laydata::tdtlayer::motion_draw(const layprop::DrawProperties& drawprop, ctmqueue& transtack) const { // check the entire layer for clipping... DBbox clip = drawprop.clipRegion(); if (empty()) return; DBbox areal = overlap().overlap(transtack.front()); if ( clip.cliparea(areal) == 0 ) return; else if (!areal.visible(drawprop.ScrCTM())) return; quadTree::motion_draw(drawprop, transtack); }
void ba81NormalQuad::layer::detectTwoTier(Eigen::ArrayBase<T1> ¶m, Eigen::MatrixBase<T2> &mean, Eigen::MatrixBase<T3> &cov) { if (mean.rows() < 3) return; std::vector<int> orthogonal; Eigen::Matrix<Eigen::DenseIndex, Eigen::Dynamic, 1> numCov((cov.array() != 0.0).matrix().colwise().count()); std::vector<int> candidate; for (int fx=0; fx < numCov.rows(); ++fx) { if (numCov(fx) == 1) candidate.push_back(fx); } if (candidate.size() > 1) { std::vector<bool> mask(numItems()); for (int cx=candidate.size() - 1; cx >= 0; --cx) { std::vector<bool> loading(numItems()); for (int ix=0; ix < numItems(); ++ix) { loading[ix] = param(candidate[cx], itemsMap[ix]) != 0; } std::vector<bool> overlap(loading.size()); std::transform(loading.begin(), loading.end(), mask.begin(), overlap.begin(), std::logical_and<bool>()); if (std::find(overlap.begin(), overlap.end(), true) == overlap.end()) { std::transform(loading.begin(), loading.end(), mask.begin(), mask.begin(), std::logical_or<bool>()); orthogonal.push_back(candidate[cx]); } } } std::reverse(orthogonal.begin(), orthogonal.end()); if (orthogonal.size() == 1) orthogonal.clear(); if (orthogonal.size() && orthogonal[0] != mean.rows() - int(orthogonal.size())) { mxThrow("Independent specific factors must be given after general dense factors"); } numSpecific = orthogonal.size(); if (numSpecific) { Sgroup.assign(numItems(), 0); for (int ix=0; ix < numItems(); ix++) { for (int dx=orthogonal[0]; dx < mean.rows(); ++dx) { if (param(dx, itemsMap[ix]) != 0) { Sgroup[ix] = dx - orthogonal[0]; continue; } } } //Eigen::Map< Eigen::ArrayXi > foo(Sgroup.data(), param.cols()); //mxPrintMat("sgroup", foo); } }