Example #1
0
QRegion QMatrix::mapToRegion(const QRect &rect) const
{
    QRegion result;
    if (isIdentity()) {
        result = rect;
    } else if (m12() == 0.0F && m21() == 0.0F) {
        int x = qRound(m11()*rect.x() + dx());
        int y = qRound(m22()*rect.y() + dy());
        int w = qRound(m11()*rect.width());
        int h = qRound(m22()*rect.height());
        if (w < 0) {
            w = -w;
            x -= w - 1;
        }
        if (h < 0) {
            h = -h;
            y -= h - 1;
        }
        result = QRect(x, y, w, h);
    } else {
        result = QRegion(mapToPolygon(rect));
    }
    return result;

}
Example #2
0
WTransform WTransform::adjoint() const
{
  return WTransform(m33() * m22() - m32() * m23(),
		    - (m33() * m12() - m32() * m13()),
		    - (m33() * m21() - m31() * m23()),
		    m33() * m11() - m31() * m13(),
		    m32() * m21() - m31() * m22(),
		    - (m32() * m11() - m31() * m12()));
}
Example #3
0
Matrix2D Matrix2D::inverse() const
{
	Matrix2D T(1, 0, 0, 1, -tx(), -ty());

    float invdet = 1 / (m11() * m22() - m21() * m12());
    Matrix2D L(m22() * invdet, -m12() * invdet, -m21() * invdet, m11() * invdet);

	return L * T;
}
Example #4
0
matrix_3x3 m33_inverse(matrix_3x3 m) {

  float det = m33_det(m);
  if (det == 0) {
    error("Cannot Invert non-singular 3x3 matrix.");
  }
  
  float fac = 1.0 / det;
  
  matrix_3x3 ret;
  ret.xx = fac * m22_det(m22(m.yy, m.yz, m.zy, m.zz));
  ret.xy = fac * m22_det(m22(m.xz, m.xy, m.zz, m.zy));
  ret.xz = fac * m22_det(m22(m.xy, m.xz, m.yy, m.yz));
  
  ret.yx = fac * m22_det(m22(m.yz, m.yx, m.zz, m.zx));
  ret.yy = fac * m22_det(m22(m.xx, m.xz, m.zx, m.zz));
  ret.yz = fac * m22_det(m22(m.xz, m.xx, m.yz, m.yx));
  
  ret.zx = fac * m22_det(m22(m.yx, m.yy, m.zx, m.zy));
  ret.zy = fac * m22_det(m22(m.xy, m.xx, m.zy, m.zx));
  ret.zz = fac * m22_det(m22(m.xx, m.xy, m.yx, m.yy));
  
  return ret;
  
}
Example #5
0
void Matrix2D::inverseTransformPoint(float x, float y, float* newx, float* newy) const
{
    float invdet = 1 / (m11() * m22() - m21() * m12());

    float nx = invdet * m22() * (x - tx()) + invdet * -m12() * (y - ty());
    float ny = invdet * -m21() * (x - tx()) + invdet * m11() * (y - ty());

	if (newx)
		*newx = nx;

	if (newy)
		*newy = ny;
}
FloatPoint TransformationMatrix::projectPoint(const FloatPoint& p) const
{
    // This is basically raytracing. We have a point in the destination
    // plane with z=0, and we cast a ray parallel to the z-axis from that
    // point to find the z-position at which it intersects the z=0 plane
    // with the transform applied. Once we have that point we apply the
    // inverse transform to find the corresponding point in the source
    // space.
    // 
    // Given a plane with normal Pn, and a ray starting at point R0 and
    // with direction defined by the vector Rd, we can find the
    // intersection point as a distance d from R0 in units of Rd by:
    // 
    // d = -dot (Pn', R0) / dot (Pn', Rd)
    
    double x = p.x();
    double y = p.y();
    double z = -(m13() * x + m23() * y + m43()) / m33();

    double outX = x * m11() + y * m21() + z * m31() + m41();
    double outY = x * m12() + y * m22() + z * m32() + m42();

    double w = x * m14() + y * m24() + z * m34() + m44();
    if (w != 1 && w != 0) {
        outX /= w;
        outY /= w;
    }

    return FloatPoint(static_cast<float>(outX), static_cast<float>(outY));
}
Example #7
0
WTransform WTransform::adjoint() const
{
  WTransform res = WTransform(m33() * m22() - m32() * m23(),
		    - (m33() * m12() - m32() * m13()),
		    - (m33() * m21() - m31() * m23()),
		    m33() * m11() - m31() * m13(),
		    m32() * m21() - m31() * m22(),
		    - (m32() * m11() - m31() * m12()));

  if (isJavaScriptBound()) {
    res.assignBinding(*this,
	WT_CLASS ".gfxUtils.transform_adjoint(" + jsRef() + ")");
  }

  return res;
}
Example #8
0
void Matrix2D::transformPoint(float x, float y, float* newx, float* newy) const
{
    float nx = m11() * x + m12() * y + tx();
    float ny = m21() * x + m22() * y + ty();

	if (newx)
		*newx = nx;

	if (newy)
		*newy = ny;
}
Example #9
0
const String DOMMatrixReadOnly::toString() const {
  std::stringstream stream;
  if (is2D()) {
    stream << "matrix(" << a() << ", " << b() << ", " << c() << ", " << d()
           << ", " << e() << ", " << f();
  } else {
    stream << "matrix3d(" << m11() << ", " << m12() << ", " << m13() << ", "
           << m14() << ", " << m21() << ", " << m22() << ", " << m23() << ", "
           << m24() << ", " << m31() << ", " << m32() << ", " << m33() << ", "
           << m34() << ", " << m41() << ", " << m42() << ", " << m43() << ", "
           << m44();
  }
  stream << ")";

  return String(stream.str().c_str());
}
    // ONLY USE WHEN MASS MATRIX CONTAINS FREE BASE TRANSLATION AND ROTATION
    //      Since the translation and rotation are switched
    //      WBI order [T R Q]
    //      ocra order [R T Q]
/* static */ bool ocraWbiConversions::wbiToOcraMassMatrix(int qdof, const Eigen::MatrixXd &M_wbi, Eigen::MatrixXd &M_ocra)
    {
        int dof = qdof + DIM_T + DIM_R;
        if(dof != M_wbi.cols() || dof != M_wbi.rows() || dof != M_ocra.rows() || dof != M_ocra.cols())
        {
            std::cout<<"ERROR: Input and output matrices - Is the model free root?" <<std::endl;
            return false;
        }

        // ORIGINAL MATRIX BLOCKS
        Eigen::MatrixXd m11(DIM_T, DIM_T);
        m11 = M_wbi.block(0, 0, DIM_T, DIM_T);

        Eigen::MatrixXd m12(DIM_T, DIM_R);
        m12 = M_wbi.block(0, DIM_T, DIM_T, DIM_R);

        Eigen::MatrixXd m13(DIM_T, qdof);
        m13 = M_wbi.block(0, DIM_T+DIM_R, DIM_T, qdof);

        Eigen::MatrixXd m21(DIM_R, DIM_T);
        m21 = M_wbi.block(DIM_T, 0, DIM_R, DIM_T);

        Eigen::MatrixXd m22(DIM_R, DIM_R);
        m22 = M_wbi.block(DIM_T, DIM_T, DIM_R, DIM_R);

        Eigen::MatrixXd m23(DIM_R, qdof);
        m23 = M_wbi.block(DIM_T, DIM_T+DIM_R, DIM_R, qdof);

        Eigen::MatrixXd m31(qdof, DIM_T);
        m31 = M_wbi.block(DIM_T+DIM_R, 0, qdof, DIM_T);

        Eigen::MatrixXd m32(qdof, DIM_R);
        m32 = M_wbi.block(DIM_T+DIM_R, DIM_T, qdof, DIM_R);

        Eigen::MatrixXd m33(qdof, qdof);
        m33 = M_wbi.block(DIM_T+DIM_R, DIM_T+DIM_R, qdof, qdof);

        M_ocra << m22, m21, m23,
                m12, m11, m13,
                m32, m31, m33;

        return true;
    }
Example #11
0
 void
 verifyComparisons()
   {
     function<void(short,int)> u1_fun;             // deliberately unbound
     function<void(short,int)> u2_fun  = undo;
     function< int(short)>     c1_fun;
     function< int(short)>     c2_fun  = capture;
     
     MemHolder m11 (u1_fun, c1_fun);
     MemHolder m12 (u1_fun, c2_fun);
     MemHolder m21 (u2_fun, c1_fun);
     MemHolder m22 (u2_fun, c2_fun);
     
     CHECK (!m11 && !m12 && !m21 && !m22);
     CHECK ( (m11 == m11));
     CHECK (!(m11 != m11));
     
     CHECK (m11 != m12);
     CHECK (m11 != m21);
     CHECK (m11 != m22);
     CHECK (m12 != m11);
     CHECK (m12 != m21);
     CHECK (m12 != m22);
     CHECK (m21 != m11);
     CHECK (m21 != m12);
     CHECK (m21 != m22);
     CHECK (m22 != m11);
     CHECK (m22 != m12);
     CHECK (m22 != m21);
     
     MemHolder m22x (m22); // clone copy
     CHECK (!m22x);
     CHECK (m22 == m22x);  // same functions, no state --> equal
     
     testVal = 0;
     m22x.tieCaptureFunc() (1 + (rand() % 9));   // produce a random memento value != 0
     CHECK (0 < m22x.getState());
     
     CHECK (m22 != m22x);
     m22.tieCaptureFunc() (m22x.getState()); // get the same value into the memento within m22
     CHECK (m22 == m22x);
   }
Example #12
0
CSSFunctionValue* MatrixTransformComponent::toCSSValue() const
{
    CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueMatrix : CSSValueMatrix3d);

    if (m_is2D) {
        double values[6] = {a(), b(), c(), d(), e(), f()};
        for (double value : values) {
            result->append(cssValuePool().createValue(value, CSSPrimitiveValue::UnitType::Number));
        }
    } else {
        double values[16] = {m11(), m12(), m13(), m14(), m21(), m22(), m23(), m24(),
                             m31(), m32(), m33(), m34(), m41(), m42(), m43(), m44()
                            };
        for (double value : values) {
            result->append(cssValuePool().createValue(value, CSSPrimitiveValue::UnitType::Number));
        }
    }

    return result;
}
TransformationMatrix::operator CATransform3D() const
{
    CATransform3D toT3D;
    toT3D.m11 = narrowPrecisionToFloat(m11());
    toT3D.m12 = narrowPrecisionToFloat(m12());
    toT3D.m13 = narrowPrecisionToFloat(m13());
    toT3D.m14 = narrowPrecisionToFloat(m14());
    toT3D.m21 = narrowPrecisionToFloat(m21());
    toT3D.m22 = narrowPrecisionToFloat(m22());
    toT3D.m23 = narrowPrecisionToFloat(m23());
    toT3D.m24 = narrowPrecisionToFloat(m24());
    toT3D.m31 = narrowPrecisionToFloat(m31());
    toT3D.m32 = narrowPrecisionToFloat(m32());
    toT3D.m33 = narrowPrecisionToFloat(m33());
    toT3D.m34 = narrowPrecisionToFloat(m34());
    toT3D.m41 = narrowPrecisionToFloat(m41());
    toT3D.m42 = narrowPrecisionToFloat(m42());
    toT3D.m43 = narrowPrecisionToFloat(m43());
    toT3D.m44 = narrowPrecisionToFloat(m44());
    return toT3D;
}
Example #14
0
double WTransform::determinant() const
{
  return m11() * (m33() * m22() - m32() * m23())
    - m21() * (m33() * m12() - m32() * m13())
    + m31() * (m23() * m12() - m22() * m13());
}