Exemple #1
0
std::vector<std::vector<size_t>> where_diff(const vec2d& data, const T& func) {
  std::vector<std::vector<size_t>> res(data.size());
  for (size_t j = 0; j < data.size(); ++j) {
    for (size_t i = 0; i < data[j].size() - 1; ++i) {
      if (func(data[j][i], data[j][i + 1])) {
        res[j].push_back(i);
      }
    }
  }
  return res;
}
Exemple #2
0
//******* Cosine of Angle Between Vectors ******//
double cos_angle( const vec2d& a, const vec2d& b )
{
    double angle = dot( a, b ) / ( a.mag() * b.mag() );

    if ( angle >= -1.0 && angle <= 1.0 )
    {
        return( angle );
    }
    else
    {
        return( 0.0 );
    }
}
Exemple #3
0
bool PointInPolygon( const vec2d & R, const std::vector< vec2d > & pnts )
{
    // Implementation of Algorithm 6 from "The Point in Polygon Problem
    // for Arbitrary Polygons" by Hormann and Agathos.
    //
    // R: the point in question
    // pnts: vector of points defining polygon, first and last point should be the same
    //
    // Note: This algorithm does not test to see if the test point lies on the
    //       an edge of the polygon

    int w = 0; // winding number
    bool modify_w = false;

    for ( int i = 0; i < ( int )pnts.size() - 1; i++ )
    {
        if ( ( pnts[i].y() < R.y() ) != ( pnts[i + 1].y() < R.y() ) ) // if crossing
        {
            if ( pnts[i].x() >= R.x() )
            {
                if ( pnts[i + 1].x() > R.x() )
                {
                    modify_w = true;
                }
                else if ( ( det( pnts[i], pnts[i + 1], R ) > 0 ) == ( pnts[i + 1].y() > pnts[i].y() ) ) // right crossing
                {
                    modify_w = true;
                }
            }
            else if ( pnts[i + 1].x() > R.x() )
            {
                if ( ( det( pnts[i], pnts[i + 1], R ) > 0 ) == ( pnts[i + 1].y() > pnts[i].y() ) ) // right crossing
                {
                    modify_w = true;
                }
            }
        }

        if ( modify_w )
        {
            w = w + 2 * ( pnts[i + 1].y() > pnts[i].y() ) - 1;    // modify w
        }

        modify_w = false;
    }

    return !!(abs( w % 2 ));

}
OneD matrixExtract(vec2d &bigMatrix, int index)
{
  int size = bigMatrix.size();
  
  OneD result(size,0);

  for (int x=0; x<size; x++)
    {
      result[x] = bigMatrix[x][index];
    }

  return result;
}
Exemple #5
0
 const std::string serialize() const
 {
     std::ostringstream ret_stream;
     std::cout << "Pussy" << std::endl;
     ret_stream << _id << ' ' << _hp << ' ' << _mana << ' '
                << _position.get_x() << ' ' << _position.get_y()
                << _target_position.get_x() << ' ' << _target_position.get_y() << ' '
                << _velocity.get_x() << ' ' << _velocity.get_y() << ' '
                << _facing << ' ';
     std::cout << "Bitch." << std::endl;
     return ret_stream.str();
 }
Exemple #6
0
 void deserialize(const std::string & serialized)
 {
     std::istringstream in_stream(serialized);
     int facing;
     double px, py, tx, ty, vx, vy;
     in_stream >> _id >> _hp >> _mana >> px >> py >> tx >> ty >> vx >> vy >> facing;
     _position.set_x(px);
     _position.set_y(py);
     _target_position.set_x(tx);
     _target_position.set_y(ty);
     _velocity.set_x(vx);
     _velocity.set_y(vy);
     _facing = static_cast< Direction >(facing);
 }
std::string python_code_caller(const std::string& script_name, const vec2d& levels, const int& dim)
{
    int levels_no = 0;
    int level_size = 0;
    int one_level = 0;
    std::stringstream caller;

    levels_no = levels.size();
    level_size = levels[0].size();

    caller << "python " << script_name << " " << dim << " ";

    for(int i = 0 ; i < levels_no ; ++i)
    {
        for(int j = 0 ; j < level_size ; ++j)
        {
            one_level = levels[i][j];
            caller << one_level << " ";
        }
    }

    return caller.str();
}
Exemple #8
0
vec3d MapFromPlane( vec2d & uw, vec3d & B, vec3d & e0, vec3d & e1 )
{
    vec3d result = B + e0 * uw.x() + e1 * uw.y();
    return result;
}
Exemple #9
0
inline size_t inner_p1_size(const vec2d& data){
  return data.size();
}
Exemple #10
0
template <> inline vec2d normalize (vec2d value, FLOAT64 len) {
	return value.normal() * len;
}
Exemple #11
0
template <> inline FLOAT64 length (vec2d value) {
	return value.len();
}
Exemple #12
0
// normalize
vec2d operator~(vec2d vec)
{
   return vec.normalized();
}