bool hit_test(value_type x, value_type y, double tol) const { if (cont_.size() == 1) { // Handle points double x0, y0; cont_.get_vertex(0, &x0, &y0); return distance(x, y, x0, y0) <= fabs(tol); } else if (cont_.size() > 1) { bool inside=false; double x0=0; double y0=0; rewind(0); vertex(&x0, &y0); unsigned command; double x1,y1; while (SEG_END != (command=vertex(&x1, &y1))) { if (command == SEG_MOVETO) { x0 = x1; y0 = y1; continue; } if ((((y1 <= y) && (y < y0)) || ((y0 <= y) && (y < y1))) && ( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1)) inside=!inside; x0=x1; y0=y1; } return inside; } return false; }
std::vector<triplet> copy_triplets() { std::vector<triplet> triplets(data.size()); size_type count = 0; for(size_type brow=0; brow<_brows; ++brow) { for(size_type bidx=brow_ptr[brow]; bidx<brow_ptr[brow+1]; ++bidx) { size_type bcol = bcol_index[bidx]; for(size_type i=0; i<BLOCK; ++i) { for(size_type j=0; j<BLOCK; ++j) { std::get<0>(triplets[count]) = brow*BLOCK + i; std::get<1>(triplets[count]) = bcol*BLOCK + j; std::get<2>(triplets[count]) = data[index(bidx,i,j)]; ++count; } } } } return triplets; }
static inline void add_to_hull(point_type const& p, container_type& output) { typedef typename strategy::side::services::default_strategy<cs_tag>::type side; output.push_back(p); std::size_t output_size = output.size(); while (output_size >= 3) { rev_iterator rit = output.rbegin(); point_type const last = *rit++; point_type const& last2 = *rit++; if (Factor * side::apply(*rit, last, last2) <= 0) { // Remove last two points from stack, and add last again // This is much faster then erasing the one but last. output.pop_back(); output.pop_back(); output.push_back(last); output_size--; } else { return; } } }
/* summarized distance centroid */ void label_position3(double *x, double *y) const { if (type_ == LineString || type_ == MultiLineString) { middle_point(x,y); return; } unsigned i = 0; double l = 0.0; double tl = 0.0; double cx = 0.0; double cy = 0.0; double x0 = 0.0; double y0 = 0.0; double x1 = 0.0; double y1 = 0.0; unsigned size = cont_.size(); for (i = 0; i < size-1; i++) { cont_.get_vertex(i,&x0,&y0); cont_.get_vertex(i+1,&x1,&y1); l = distance(x0,y0,x1,y1); cx += l * (x1 + x0)/2; cy += l * (y1 + y0)/2; tl += l; } *x = cx / tl; *y = cy / tl; }
inline size_type bindex_of(size_type I, size_type J, bool &in_sparsity) const { for(size_type idx=brow_ptr[I]; idx<brow_ptr[I+1]; ++idx) { if(J == bcol_index[idx]) { in_sparsity = true; return idx; } } in_sparsity=false; return data.size(); }
//[ some_helpers point_type center_of_mass( const container_type &x , const mass_type &m ) { double overall_mass = 0.0; point_type mean( 0.0 ); for( size_t i=0 ; i<x.size() ; ++i ) { overall_mass += m[i]; mean += m[i] * x[i]; } if( !x.empty() ) mean /= overall_mass; return mean; }
/* center of gravity centroid - best visually but does not work with multipolygons */ void label_position(double *x, double *y) const { if (type_ == LineString || type_ == MultiLineString) { middle_point(x,y); return; } unsigned size = cont_.size(); if (size < 3) { cont_.get_vertex(0,x,y); return; } double ai; double atmp = 0; double xtmp = 0; double ytmp = 0; double x0 =0; double y0 =0; double x1 =0; double y1 =0; double ox =0; double oy =0; unsigned i; // Use first point as origin to improve numerical accuracy cont_.get_vertex(0,&ox,&oy); for (i = 0; i < size-1; i++) { cont_.get_vertex(i,&x0,&y0); cont_.get_vertex(i+1,&x1,&y1); x0 -= ox; y0 -= oy; x1 -= ox; y1 -= oy; ai = x0 * y1 - x1 * y0; atmp += ai; xtmp += (x1 + x0) * ai; ytmp += (y1 + y0) * ai; } if (atmp != 0) { *x = (xtmp/(3*atmp)) + ox; *y = (ytmp/(3*atmp)) + oy; return; } *x=x0; *y=y0; }
void middle_point(double *x, double *y) const { // calculate mid point on path double x0=0; double y0=0; double x1=0; double y1=0; unsigned size = cont_.size(); if (size == 1) { cont_.get_vertex(0,x,y); } else if (size == 2) { cont_.get_vertex(0,&x0,&y0); cont_.get_vertex(1,&x1,&y1); *x = 0.5 * (x1 + x0); *y = 0.5 * (y1 + y0); } else { double len=0.0; for (unsigned pos = 1; pos < size; ++pos) { cont_.get_vertex(pos-1,&x0,&y0); cont_.get_vertex(pos,&x1,&y1); double dx = x1 - x0; double dy = y1 - y0; len += std::sqrt(dx * dx + dy * dy); } double midlen = 0.5 * len; double dist = 0.0; for (unsigned pos = 1; pos < size;++pos) { cont_.get_vertex(pos-1,&x0,&y0); cont_.get_vertex(pos,&x1,&y1); double dx = x1 - x0; double dy = y1 - y0; double seg_len = std::sqrt(dx * dx + dy * dy); if (( dist + seg_len) >= midlen) { double r = (midlen - dist)/seg_len; *x = x0 + (x1 - x0) * r; *y = y0 + (y1 - y0) * r; break; } dist += seg_len; } } }
double energy( const container_type &q , const container_type &p , const mass_type &masses ) { const size_t n = q.size(); double en = 0.0; for( size_t i=0 ; i<n ; ++i ) { en += 0.5 * norm( p[i] ) / masses[i]; for( size_t j=0 ; j<i ; ++j ) { double diff = abs( q[i] - q[j] ); en -= gravitational_constant * masses[j] * masses[i] / diff; } } return en; }
void operator()( const container_type &q , container_type &dpdt ) const { const size_t n = q.size(); for( size_t i=0 ; i<n ; ++i ) { dpdt[i] = 0.0; for( size_t j=0 ; j<i ; ++j ) { point_type diff = q[j] - q[i]; double d = abs( diff ); diff *= ( gravitational_constant * m_masses[i] * m_masses[j] / d / d / d ); dpdt[i] += diff; dpdt[j] -= diff; } } }
pair< double , double > calc_mean_field( const container_type &x ) { size_t n = x.size(); double cos_sum = 0.0 , sin_sum = 0.0; for( size_t i=0 ; i<n ; ++i ) { cos_sum += cos( x[i] ); sin_sum += sin( x[i] ); } cos_sum /= double( n ); sin_sum /= double( n ); double K = sqrt( cos_sum * cos_sum + sin_sum * sin_sum ); double Theta = atan2( sin_sum , cos_sum ); return make_pair( K , Theta ); }
// // Capacity // size_t size() const { return list.size(); }
static std::size_t size(const container_type& p) { return p.size(); }
typename container_type::size_type size() { return m_queue.size(); }
void operator()( const container_type &x , container_type &dxdt , double /* t */ ) const { pair< double , double > mean = calc_mean_field( x ); for( size_t i=0 ; i<x.size() ; ++i ) dxdt[i] = m_omega[i] + m_epsilon * mean.first * sin( mean.second - x[i] ); }
size_type size() const { return cont_.size(); }
void label_interior_position(double *x, double *y) const { // start with the default label position label_position(x,y); unsigned size = cont_.size(); // if we are not a polygon, or the default is within the polygon we are done if (size < 3 || hit_test(*x,*y,0)) return; // otherwise we find a horizontal line across the polygon and then return the // center of the widest intersection between the polygon and the line. std::vector<double> intersections; // only need to store the X as we know the y double x0=0; double y0=0; rewind(0); unsigned command = vertex(&x0, &y0); double x1,y1; while (SEG_END != (command=vertex(&x1, &y1))) { if (command != SEG_MOVETO) { // if the segments overlap if (y0==y1) { if (y0==*y) { double xi = (x0+x1)/2.0; intersections.push_back(xi); } } // if the path segment crosses the bisector else if ((y0 <= *y && y1 >= *y) || (y0 >= *y && y1 <= *y)) { // then calculate the intersection double xi = x0; if (x0 != x1) { double m = (y1-y0)/(x1-x0); double c = y0 - m*x0; xi = (*y-c)/m; } intersections.push_back(xi); } } x0 = x1; y0 = y1; } // no intersections we just return the default if (intersections.empty()) return; x0=intersections[0]; double max_width = 0; for (unsigned ii = 1; ii < intersections.size(); ++ii) { double x1=intersections[ii]; double xc=(x0+x1)/2.0; double width = fabs(x1-x0); if (width > max_width && hit_test(xc,*y,0)) { *x=xc; max_width = width; } } }
/*! * Initializes a new instance by using a copy of the * container object specified by \p src */ explicit concurrent_queue(const container_type& src) : _size(src.size()) , _container(src) , _have_elements(_container) { }
unsigned num_points() const { return cont_.size(); }
size_type size() const { return values.size(); }
size_type size() const { return _data.size(); }