Exemple #1
0
void
MeshBase::setVertex(int i, const Math::Vector2 &v)
{
	if (!m_vdata->set(i, v.x(), v.y()))
		MMWARNING("Failed to assign values (%f, %f) to vertex %d",
		    v.x(), v.y(), i);
}
Exemple #2
0
template<UnsignedInt dimensions, class T> typename DimensionTraits<dimensions, T>::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Vector2i& viewport) {
    /* Don't divide by zero / don't preserve anything */
    if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved)
        return {};

    Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale;

    /* Extend on larger side = scale larger side down
       Clip on smaller side = scale smaller side up */
    return Camera<dimensions, T>::aspectRatioScale(
               (relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ?
               Vector2(relativeAspectRatio.y()/relativeAspectRatio.x(), T(1.0)) :
               Vector2(T(1.0), relativeAspectRatio.x()/relativeAspectRatio.y()));
}
    void RendererPlplot::draw_text(const math::Vector2 &c, const math::Vector2 &dir,
                                   const std::string &str, TextAlignMask a, int size, const Rgb &rgb)
    {
      double j = .5;

      if (a & TextAlignLeft)
        j = 0.;
      else if (a & TextAlignRight)
        j = 1.;

      _pls->schr(size/3., 1.);
      _pls->col0(get_color_id(rgb));
      _pls->ptex(c.x(), c.y(), dir.x(), dir.y(), j, str.c_str());
    }
Exemple #4
0
template<UnsignedInt dimensions, class T> MatrixTypeFor<dimensions, T> aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Vector2i& viewport) {
    /* Don't divide by zero / don't preserve anything */
    if(projectionScale.x() == 0 || projectionScale.y() == 0 || viewport.x() == 0 || viewport.y() == 0 || aspectRatioPolicy == AspectRatioPolicy::NotPreserved)
        return {};

    CORRADE_INTERNAL_ASSERT((projectionScale > Math::Vector2<T>(0)).all() && (viewport > Vector2i(0)).all());
    Math::Vector2<T> relativeAspectRatio = Math::Vector2<T>(viewport)*projectionScale;

    /* Extend on larger side = scale larger side down
       Clip on smaller side = scale smaller side up */
    return MatrixTypeFor<dimensions, T>::scaling(Math::Vector<dimensions, T>::pad(
        (relativeAspectRatio.x() > relativeAspectRatio.y()) == (aspectRatioPolicy == AspectRatioPolicy::Extend) ?
        Math::Vector2<T>(relativeAspectRatio.y()/relativeAspectRatio.x(), T(1)) :
        Math::Vector2<T>(T(1), relativeAspectRatio.x()/relativeAspectRatio.y()), T(1)));
}
    void RendererPlplot::draw_point(const math::Vector2 &v, const Rgb &rgb, enum PointStyle s)
    {
      int code;

      _pls->col0(get_color_id(rgb));

      switch (s)
        {
        default:
        case PointStyleDot:
          code = 1;
          break;

        case PointStyleCross:
          code = 2;
          break;

        case PointStyleRound:
          code = 4;
          break;

        case PointStyleSquare:
          code = 6;
          break;

        case PointStyleTriangle:
          code = 11;
          break;
        }

      PLFLT x = v.x(), y = v.y();
      _pls->poin(1, &x, &y, code);
    }
 void RendererPlplot::draw_circle(const math::Vector2 &c, double r,
                                  const Rgb &rgb, bool filled)
 {
   _pls->col0(get_color_id(rgb));
   std::cout << "draw_circle was not tested (added 8th parameter to compile" << std::endl;
   exit(-1);
   _pls->arc(c.x(), c.y(), r, r, 0., 360., 360., filled);
 }
bool TRegularPolygon::inside(const Math::Vector2 &point) const
{
    double d = Math::square(point.x()) + Math::square(point.y());

    // check against circumscribed circle
    if (d > Math::square(_radius))
        return false;

    // check against inscribed circle
    if (d < Math::square(_i_radius))
        return true;

    Math::VectorPair2 e(get_edge(point));

    return ((point.y() - e.y0()) * (e.x1() - e.x0()) -
            (point.x() - e.x0()) * (e.y1() - e.y0()) > 0);
}
Math::VectorPair2 TRegularPolygon::get_edge(const Math::Vector2 &point) const
{
    // find sector start angle
    double a = Math::lp_floor(atan2(point.y(), point.x()) - _angle, (double)_edge_cnt / (2.0 * M_PI));

    // find sector edge coordinates
    return Math::VectorPair2(_radius * cos(_angle + a), _radius * sin(_angle + a),
                             _radius * cos(_angle + a + _a_step), _radius * sin(_angle + a + _a_step));
}
Exemple #9
0
void TCurveBase::normal(Math::Vector3 &normal, const Math::Vector3 &point) const
{
    Math::Vector2 d;

    derivative(point.project_xy(), d);

    normal = Math::Vector3(d.x(), d.y(), -1.0);
    normal.normalize();
}
Exemple #10
0
void TCurveBase::derivative(const Math::Vector2 & xy, Math::Vector2 & dxdy) const
{
    double abserr;
    struct curve_gsl_params_s params;
    gsl_function gsl_func;

    gsl_func.params = &params;

    params.c = this;
    params.x = xy.x();
    params.y = xy.y();

    gsl_func.function = gsl_func_sagitta_x;
    gsl_deriv_central(&gsl_func, xy.x(), 1e-6, &dxdy.x(), &abserr);

    gsl_func.function = gsl_func_sagitta_y;
    gsl_deriv_central(&gsl_func, xy.y(), 1e-6, &dxdy.y(), &abserr);
}
Exemple #11
0
    bool Polygon::inside(const math::Vector2 &p) const
    {
      unsigned int s = _vertices.size();

      if (s < 3)
        return false;

      unsigned int count = 0;
      const math::Vector2 *w = &_vertices[s - 1];

      // FIXME optimize
      for (unsigned int i = 0; i < s; i++)
        {
          const math::Vector2 *v = &_vertices[i];

          // Algorithm from http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
          if ((((v->y() <= p.y()) && (p.y() < w->y())) || ((w->y() <= p.y()) && (p.y() < v->y()))) &&
              (p.x() < (w->x() - v->x()) * (p.y() - v->y()) / (w->y() - v->y()) + v->x()))
            count++;
          w = v;
        }

      return (count & 1) != 0;
    }
Exemple #12
0
void TLens::draw_2d_edge(TRenderer &r, const TSurface &left, double l_y,
                         const TSurface &right, double r_y, LensEdge type,
                         const TElement *ref) const
{
    const Math::Vector3 l3(0., l_y, left.get_curve()->sagitta(Math::Vector2(0., l_y)));
    const Math::Vector2 l2(left.get_transform_to(ref).transform(l3).project_zy());

    const Math::Vector3 r3(0., r_y, right.get_curve()->sagitta(Math::Vector2(0., r_y)));
    const Math::Vector2 r2(right.get_transform_to(ref).transform(r3).project_zy());

    switch (type)
    {
    case StraightEdge: {
        if (fabs(l2.y() - r2.y()) > 1e-6)
        {
            double m;

            if (fabs(l2.y()) > fabs(r2.y()))
            {
                m = l2.y();
                r.draw_segment(Math::VectorPair2(r2.x(), m, r2.x(), r2.y()), left.get_color(r));
            }
            else
            {
                m = r2.y();
                r.draw_segment(Math::VectorPair2(l2.x(), m, l2.x(), l2.y()), left.get_color(r));
            }

            r.draw_segment(Math::VectorPair2(l2.x(), m, r2.x(), m), left.get_color(r));

            break;
        }
    }

    case SlopeEdge:
        r.draw_segment(l2, r2, left.get_color(r));
        break;
    }
}
Exemple #13
0
 constexpr static Math::Matrix4<T> aspectRatioScale(const Math::Vector2<T>& scale) {
     return Math::Matrix4<T>::scaling({scale.x(), scale.y(), 1.0f});
 }
Exemple #14
0
bool TRingBase::inside(const Math::Vector2 &point) const
{
    double d = Math::square(point.x()) + Math::square(point.y());

    return d <= Math::square(_radius) && d >= Math::square(_hole_radius);
}
Exemple #15
0
 double EllipseBase::get_outter_radius(const math::Vector2 &dir) const
 {
   return _xr > _yr
     ? sqrt(math::square(_yr) / (1. - _e2 * math::square(dir.x())))
     : sqrt(math::square(_xr) / (1. - _e2 * math::square(dir.y())));
 }
Exemple #16
0
 bool EllipseBase::inside(const math::Vector2 &point) const
 {
   return (math::square(point.x()) + math::square(point.y() * _xy_ratio) <= math::square(_xr));
 }