Example #1
0
io_return_t
sceopen(
       dev_t			dev,
       dev_mode_t		flag,
       io_req_t			ior)
{
	struct	ifnet	*ifp;
	int i, unit;
	sce_softc_t ssc;
	scsit_return_t sr;
	TR_DECL("sceopen");

	tr4("enter: dev = 0x%x flag = 0x%x ior = 0x%x", dev, flag, ior);
	unit = minor(dev);

	if (scegetssc(unit) != NULL_SSC) {
		tr1("exit: D_ALREADY_OPEN");
		return (D_ALREADY_OPEN);
	}

	for(i=0;i<NSCE;i++) {
		ssc = &sce_softc[i];
		if (!ssc->inuse)
		    break;
	}
	if (ssc->inuse) {
		tr1("exit: D_WOULD_BLOCK");
		return (D_WOULD_BLOCK);
	}

	ssc->inuse = TRUE;
	ssc->node = unit;
	sr = scsit_handle_alloc(&ssc->recv_handle);
	assert(sr == SCSIT_SUCCESS);
	sr = scsit_handle_mismatch(ssc->recv_handle);
	assert(sr == SCSIT_SUCCESS);

	ifp = &(ssc->sce_if);
	ifp->if_unit = unit;
	ifp->if_mtu = SCE_MTU;
	ifp->if_flags = IFF_UP | IFF_RUNNING | IFF_BROADCAST;
	ifp->if_header_size = sizeof(struct ether_header);
	ifp->if_header_format = HDR_ETHERNET;
	ifp->if_address_size = 6;
	ifp->if_address = sce_fake_addr;
	if_init_queues(ifp);

	(void)sce_prime(ssc, IKM_NULL);
	tr1("exit: D_SUCCESS");
	return (D_SUCCESS);
}
Example #2
0
template<class Tret,class TcreateFunc1,class TcreateFunc2> Tret Twindow::createDlg_Box(int dlgId,HWND hWndParent,LPARAM lparam,TcreateFunc1 createFunc1,TcreateFunc2 createFunc2)
{
    resized=false;

    if (bindsHtrack)
        for (int i=0; i<bindsHtrack[i].idc; i++) {
            bindTrackbarsMap.insert(std::make_pair(bindsHtrack[i].idc,bindsHtrack+i));
        }
    if (bindsVtrack)
        for (int i=0; i<bindsVtrack[i].idc; i++) {
            bindTrackbarsMap.insert(std::make_pair(bindsVtrack[i].idc,bindsVtrack+i));
        }
    if (bindsCheckbox)
        for (int i=0; i<bindsCheckbox[i].idc; i++) {
            bindCheckboxesMap.insert(std::make_pair(bindsCheckbox[i].idc,bindsCheckbox+i));
        }
    HINSTANCE hi=this->hi?this->hi:g_hInst;//HACK!!
    if (!tr) {
        char_t lang[MAX_PATH],pth[MAX_PATH];
        getpth(pth);
        getUILanguage(pth,lang);
        Ttranslate tr1(g_hInst,pth); // Create temporary translator to calculate window size.
        tr1.init(lang,0);            // don't care translatorMode, because we just want size.
        DLGTEMPLATE *dlg=tr1.translateDialogTemplate(dlgId);
        Tret ret=createFunc2(hi,dlg,hWndParent,msgProc0,lparam);
        LocalFree(dlg);
        return ret;
    } else {
        DLGTEMPLATE *dlg=tr->translateDialogTemplate(dlgId);
        Tret ret=createFunc2(hi,dlg,hWndParent,msgProc0,lparam);
        LocalFree(dlg);
        return ret;
    }
}
Example #3
0
 bool egcd(const bigint &b1, const bigint &b2, bigint &dr, bigint &r1, bigint &r2) const {
     bool scs;
     bigint dd(0), ppr1(0), ppr2(0), pr1(0), pr2(0), q, r(0), tr1(0), tr2(0);
     if(compare(b1, b2) > 0) {
         dd = b1;
         dr = b2;
         pr1 = one;
         pr2.init();
     } else {
         dd = b2;
         dr = b1;
         pr1.init();
         pr2 = one;
     }
     r1 = pr2;
     r2 = pr1;
     while((scs = divide(dd, dr, q, r)) && r.capacity() > 0) {
         ppr1 = pr1;
         ppr2 = pr2;
         pr1 = r1;
         pr2 = r2;
         tr1.init();
         tr2.init();
         if(!(scs = (signedmultiply(q, pr1, tr1) && signedsubtract(ppr1, tr1, r1) &&
                     signedmultiply(q, pr2, tr2) && signedsubtract(ppr2, tr2, r2)))) {
             break;
         }
         dd = dr;
         dr = r;
         q.init();
         r.init();
     }
     return scs;
 }
Example #4
0
int main() {
	std::thread tr1(stepLeft);
	std::thread tr2(stepRight);
	
	tr1.join();
	tr2.join();


}
Example #5
0
void test_SHARC2() {
	SumOfSines vox1(196), vox2(196), vox3(196), vox4(196), vox5(196);
	SHARC_Library * lib;
	SHARC_Spectrum * sp1, * sp2, * sp3, * sp4, * sp5;
	lib = new SHARC_Library("../../../Code/sharc");
							// access a spectrum, load it into a SumOfSines, and scale it by a triangle envelope
	sp1 = lib->spectrum_named("altoflute_vibrato", "g3");	
	vox1.add_partials(csl_min(sp1->_num_partials, 20), sp1->_partials);
	vox1.create_cache();			// cache the waveform (since it's a harmonic overtone spectrum)
	Triangle tr1(3, 0.75); 			
	vox1.set_scale(tr1);
							// repeat for 3 other delayed examples
	sp2 = lib->spectrum_named("bass_clarinet", "g3");	
	vox2.add_partials(csl_min(sp2->_num_partials, 20), sp2->_partials);
	vox2.create_cache();			// cache the waveform
	Triangle tr2(3, 0.75); 		
	vox2.set_scale(tr2);
	sp3 = lib->spectrum_named("cello_vibrato", "g3");	
	vox3.add_partials(csl_min(sp3->_num_partials, 20), sp3->_partials);
	vox3.create_cache();			// cache the waveform
	Triangle tr3(3, 0.75); 		
	vox3.set_scale(tr3);
	sp4 = lib->spectrum_named("trombone", "g3");	
	vox4.add_partials(csl_min(sp4->_num_partials, 20), sp4->_partials);
	vox4.create_cache();			// cache the waveform
	Triangle tr4(3, 0.75); 		
	vox4.set_scale(tr4);
	sp5 = lib->spectrum_named("violin_martele", "g3");	
	vox5.add_partials(csl_min(sp4->_num_partials, 20), sp4->_partials);
	vox5.create_cache();			// cache the waveform
	Triangle tr5(3, 0.75); 		
	vox5.set_scale(tr5);

	Mixer mix(2);		// create a stereo mixer
	mix.add_input(vox1);	mix.add_input(vox2); 	
	mix.add_input(vox3); 	mix.add_input(vox4); 	mix.add_input(vox5);
	
	logMsg("playing SumOfSines mix...");	// I don't use run_test() here because I need to trigger the envelopes while it's playing	
	gIO->set_root(mix);			// turn it on
	tr1.trigger();				// trigger the 1st envelope
	usleep(1500000);			// wait 1.5 sec
	tr2.trigger();				// trigger the 2nd envelope
	usleep(1500000);			// wait 1.5 sec
	tr3.trigger();				// trigger the 3rd envelope
	usleep(1500000);			// wait 1.5 sec
	tr4.trigger();				// trigger the 4th envelope
	usleep(1500000);			// wait 1.5 sec
	tr5.trigger();				// trigger the 5th envelope
	usleep(3000000);			// wait 3 seconds
	gIO->clear_root();			// turn it off
	logMsg("SumOfSines done.");
}
Example #6
0
void ObjectTransactiontestUnit::test_nested_rollback()
{
  matador::object_store store;
  store.attach<person>("person");

  matador::transaction tr1(store);

  try {
    tr1.begin();

    auto hans = store.insert(new person("Hans", matador::date(12, 3, 1980), 180));

    UNIT_ASSERT_GREATER(hans->id(), 0UL, "id must be valid");

    tr1.commit();

    tr1.begin();

    UNIT_ASSERT_EQUAL(hans->height(), 180U, "height must be valid");
    hans->height(183);
    UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid");

    matador::transaction tr2(store);

    try {
      tr2.begin();

      UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid");
      hans->height(159);
      UNIT_ASSERT_EQUAL(hans->height(), 159U, "height must be valid");

      tr2.rollback();

      UNIT_ASSERT_EQUAL(hans->height(), 183U, "height must be valid");

    } catch (std::exception &) {
      tr2.rollback();
    }

    tr1.commit();
  } catch (std::exception &) {
    tr1.rollback();
  }

  matador::object_view<person> pview(store);

  auto p = pview.front();

  UNIT_ASSERT_GREATER(p->id(), 0UL, "id must be valid");
  UNIT_ASSERT_EQUAL(p->name(), "Hans", "name must be 'Hans'");
}
Example #7
0
void
scestart(int unit)
{
	sce_softc_t ssc = scegetssc(unit);
	scsit_return_t sr;
	struct ifnet *ifp;
	io_req_t ior;
	TR_DECL("scestart");

	tr2("enter: unit = 0x%x", unit);

	assert(ssc != NULL_SSC);

	ifp = &ssc->sce_if;
	IF_DEQUEUE(&ifp->if_snd, ior);
      dequeued:
	while(ior) {
		struct ether_header *ehp = (struct ether_header *)ior->io_data;
		scsit_handle_t handle;

		bcopy((const char *)sce_fake_addr,(char *)&ehp->ether_shost,6);

		sr = scsit_handle_alloc(&handle);
		assert(sr == SCSIT_SUCCESS);

		tr1("sending");
		sr = scsit_send(handle,
				ssc->node,
				sce_lun,
				(void *)ior,
				(char *)ehp,
				ior->io_count,
				FALSE);
		assert(sr == SCSIT_SUCCESS);
		IF_DEQUEUE(&ifp->if_snd, ior);
	}
	tr1("exit");
}
Example #8
0
void
sce_send_complete(
		  scsit_handle_t	handle,
		  void *		opaque,
		  char *		buffer,
		  unsigned int		count,
		  scsit_return_t	sr)
{
	io_req_t ior = (io_req_t)opaque;
	TR_DECL("sce_send_complete");

	tr1("enter");
	sr = scsit_handle_free(handle);
	assert(sr == SCSIT_SUCCESS);
	iodone(ior);
}
Example #9
0
void
transaction_per_period (int nPeriodSeconds, void (*tr1) ())
{


  int start = get_msec_count (), duration, wait_secs;

  tr1 ();
  duration = (get_msec_count () - start) / 1000;
  wait_secs = nPeriodSeconds - duration;
  if (wait_secs > 0)
#ifdef WIN32
    Sleep (RandomNumber (1, wait_secs) * 1000);
#else
    sleep (RandomNumber (1, wait_secs));
#endif
}
Example #10
0
TEST_F(PhyloTreeTest, PulleyPrinciple) {
    double t1 = rand()/(double)RAND_MAX;
    double t2 = rand()/(double)RAND_MAX;
    PhyloTreeNode* r1 = new PhyloTreeNode();
    PhyloTreeNode* h1 = new PhyloTreeNode();

    h1->addChild(new PhyloTreeNode("s1", "ACGT"), rand()/(double)RAND_MAX);
    h1->addChild(new PhyloTreeNode("s2", "GCCA"), rand()/(double)RAND_MAX);

    r1->addChild(new PhyloTreeNode("s3", "GGGA"), t1);
    r1->addChild(h1, t2);

    PhyloTree tr1(r1, new Kimura(10.0));

    double lh1 = tr1.logLikelihood();
    ASSERT_LT(tr1.logLikelihood(), 0.0);

    for (unsigned int i = 0; i < 1000; i++) {
        double t_rand = rand()/(double)RAND_MAX;
        r1->setLeftDist(t_rand);
        r1->setLeftDist((t1+t2)-t_rand);
        ASSERT_FLOAT_EQ(tr1.logLikelihood(), lh1);
    }
}
Example #11
0
File: f.c Project: PlanetAPL/a-plus
Z H2(rho){A z;ND2 I1{I wt=w->t,wn=w->n;I *d=a->p,r=a->n,n=tr1(r,d);Q(n<0,9)
 Q(r>MAXR,13)if(n==wn)R rsh(w,r,d);W(ga(t=wt,r,n,d))u=wn;C2(m0)}}
Example #12
0
File: f.c Project: PlanetAPL/a-plus
Z H1(monadicIota){A z;I1;{I r=a->n,*d=a->p,n=tr1(r,d);Q(n<0,9) Q(a->r>1,7)Q(r>MAXR,13)W(ga(It,r,n,d))d=z->p;DO(n,d[i]=i)R(I)z;}}
template<typename Scalar, int Mode, int Options> void transformations()
{
  /* this test covers the following files:
     Cross.h Quaternion.h, Transform.cpp
  */
  typedef Matrix<Scalar,2,2> Matrix2;
  typedef Matrix<Scalar,3,3> Matrix3;
  typedef Matrix<Scalar,4,4> Matrix4;
  typedef Matrix<Scalar,2,1> Vector2;
  typedef Matrix<Scalar,3,1> Vector3;
  typedef Matrix<Scalar,4,1> Vector4;
  typedef Quaternion<Scalar> Quaternionx;
  typedef AngleAxis<Scalar> AngleAxisx;
  typedef Transform<Scalar,2,Mode,Options> Transform2;
  typedef Transform<Scalar,3,Mode,Options> Transform3;
  typedef Transform<Scalar,2,Isometry,Options> Isometry2;
  typedef Transform<Scalar,3,Isometry,Options> Isometry3;
  typedef typename Transform3::MatrixType MatrixType;
  typedef DiagonalMatrix<Scalar,2> AlignedScaling2;
  typedef DiagonalMatrix<Scalar,3> AlignedScaling3;
  typedef Translation<Scalar,2> Translation2;
  typedef Translation<Scalar,3> Translation3;

  Vector3 v0 = Vector3::Random(),
          v1 = Vector3::Random();
  Matrix3 matrot1, m;

  Scalar a = internal::random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
  Scalar s0 = internal::random<Scalar>();

  VERIFY_IS_APPROX(v0, AngleAxisx(a, v0.normalized()) * v0);
  VERIFY_IS_APPROX(-v0, AngleAxisx(Scalar(M_PI), v0.unitOrthogonal()) * v0);
  VERIFY_IS_APPROX(internal::cos(a)*v0.squaredNorm(), v0.dot(AngleAxisx(a, v0.unitOrthogonal()) * v0));
  m = AngleAxisx(a, v0.normalized()).toRotationMatrix().adjoint();
  VERIFY_IS_APPROX(Matrix3::Identity(), m * AngleAxisx(a, v0.normalized()));
  VERIFY_IS_APPROX(Matrix3::Identity(), AngleAxisx(a, v0.normalized()) * m);

  Quaternionx q1, q2;
  q1 = AngleAxisx(a, v0.normalized());
  q2 = AngleAxisx(a, v1.normalized());

  // rotation matrix conversion
  matrot1 = AngleAxisx(Scalar(0.1), Vector3::UnitX())
          * AngleAxisx(Scalar(0.2), Vector3::UnitY())
          * AngleAxisx(Scalar(0.3), Vector3::UnitZ());
  VERIFY_IS_APPROX(matrot1 * v1,
       AngleAxisx(Scalar(0.1), Vector3(1,0,0)).toRotationMatrix()
    * (AngleAxisx(Scalar(0.2), Vector3(0,1,0)).toRotationMatrix()
    * (AngleAxisx(Scalar(0.3), Vector3(0,0,1)).toRotationMatrix() * v1)));

  // angle-axis conversion
  AngleAxisx aa = AngleAxisx(q1);
  VERIFY_IS_APPROX(q1 * v1, Quaternionx(aa) * v1);
  VERIFY_IS_NOT_APPROX(q1 * v1, Quaternionx(AngleAxisx(aa.angle()*2,aa.axis())) * v1);

  aa.fromRotationMatrix(aa.toRotationMatrix());
  VERIFY_IS_APPROX(q1 * v1, Quaternionx(aa) * v1);
  VERIFY_IS_NOT_APPROX(q1 * v1, Quaternionx(AngleAxisx(aa.angle()*2,aa.axis())) * v1);

  // AngleAxis
  VERIFY_IS_APPROX(AngleAxisx(a,v1.normalized()).toRotationMatrix(),
    Quaternionx(AngleAxisx(a,v1.normalized())).toRotationMatrix());

  AngleAxisx aa1;
  m = q1.toRotationMatrix();
  aa1 = m;
  VERIFY_IS_APPROX(AngleAxisx(m).toRotationMatrix(),
    Quaternionx(m).toRotationMatrix());

  // Transform
  // TODO complete the tests !
  a = 0;
  while (internal::abs(a)<Scalar(0.1))
    a = internal::random<Scalar>(-Scalar(0.4)*Scalar(M_PI), Scalar(0.4)*Scalar(M_PI));
  q1 = AngleAxisx(a, v0.normalized());
  Transform3 t0, t1, t2;

  // first test setIdentity() and Identity()
  t0.setIdentity();
  VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
  t0.matrix().setZero();
  t0 = Transform3::Identity();
  VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());

  t0.setIdentity();
  t1.setIdentity();
  v1 << 1, 2, 3;
  t0.linear() = q1.toRotationMatrix();
  t0.pretranslate(v0);
  t0.scale(v1);
  t1.linear() = q1.conjugate().toRotationMatrix();
  t1.prescale(v1.cwiseInverse());
  t1.translate(-v0);

  VERIFY((t0 * t1).matrix().isIdentity(test_precision<Scalar>()));

  t1.fromPositionOrientationScale(v0, q1, v1);
  VERIFY_IS_APPROX(t1.matrix(), t0.matrix());

  t0.setIdentity(); t0.scale(v0).rotate(q1.toRotationMatrix());
  t1.setIdentity(); t1.scale(v0).rotate(q1);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  t0.setIdentity(); t0.scale(v0).rotate(AngleAxisx(q1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  VERIFY_IS_APPROX(t0.scale(a).matrix(), t1.scale(Vector3::Constant(a)).matrix());
  VERIFY_IS_APPROX(t0.prescale(a).matrix(), t1.prescale(Vector3::Constant(a)).matrix());

  // More transform constructors, operator=, operator*=

  Matrix3 mat3 = Matrix3::Random();
  Matrix4 mat4;
  mat4 << mat3 , Vector3::Zero() , Vector4::Zero().transpose();
  Transform3 tmat3(mat3), tmat4(mat4);
  if(Mode!=int(AffineCompact))
    tmat4.matrix()(3,3) = Scalar(1);
  VERIFY_IS_APPROX(tmat3.matrix(), tmat4.matrix());

  Scalar a3 = internal::random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
  Vector3 v3 = Vector3::Random().normalized();
  AngleAxisx aa3(a3, v3);
  Transform3 t3(aa3);
  Transform3 t4;
  t4 = aa3;
  VERIFY_IS_APPROX(t3.matrix(), t4.matrix());
  t4.rotate(AngleAxisx(-a3,v3));
  VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
  t4 *= aa3;
  VERIFY_IS_APPROX(t3.matrix(), t4.matrix());

  v3 = Vector3::Random();
  Translation3 tv3(v3);
  Transform3 t5(tv3);
  t4 = tv3;
  VERIFY_IS_APPROX(t5.matrix(), t4.matrix());
  t4.translate(-v3);
  VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
  t4 *= tv3;
  VERIFY_IS_APPROX(t5.matrix(), t4.matrix());

  AlignedScaling3 sv3(v3);
  Transform3 t6(sv3);
  t4 = sv3;
  VERIFY_IS_APPROX(t6.matrix(), t4.matrix());
  t4.scale(v3.cwiseInverse());
  VERIFY_IS_APPROX(t4.matrix(), MatrixType::Identity());
  t4 *= sv3;
  VERIFY_IS_APPROX(t6.matrix(), t4.matrix());

  // matrix * transform
  VERIFY_IS_APPROX((t3.matrix()*t4).matrix(), (t3*t4).matrix());

  // chained Transform product
  VERIFY_IS_APPROX(((t3*t4)*t5).matrix(), (t3*(t4*t5)).matrix());

  // check that Transform product doesn't have aliasing problems
  t5 = t4;
  t5 = t5*t5;
  VERIFY_IS_APPROX(t5, t4*t4);

  // 2D transformation
  Transform2 t20, t21;
  Vector2 v20 = Vector2::Random();
  Vector2 v21 = Vector2::Random();
  for (int k=0; k<2; ++k)
    if (internal::abs(v21[k])<Scalar(1e-3)) v21[k] = Scalar(1e-3);
  t21.setIdentity();
  t21.linear() = Rotation2D<Scalar>(a).toRotationMatrix();
  VERIFY_IS_APPROX(t20.fromPositionOrientationScale(v20,a,v21).matrix(),
    t21.pretranslate(v20).scale(v21).matrix());

  t21.setIdentity();
  t21.linear() = Rotation2D<Scalar>(-a).toRotationMatrix();
  VERIFY( (t20.fromPositionOrientationScale(v20,a,v21)
        * (t21.prescale(v21.cwiseInverse()).translate(-v20))).matrix().isIdentity(test_precision<Scalar>()) );

  // Transform - new API
  // 3D
  t0.setIdentity();
  t0.rotate(q1).scale(v0).translate(v0);
  // mat * aligned scaling and mat * translation
  t1 = (Matrix3(q1) * AlignedScaling3(v0)) * Translation3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  t1 = (Matrix3(q1) * Eigen::Scaling(v0)) * Translation3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  t1 = (q1 * Eigen::Scaling(v0)) * Translation3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // mat * transformation and aligned scaling * translation
  t1 = Matrix3(q1) * (AlignedScaling3(v0) * Translation3(v0));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());


  t0.setIdentity();
  t0.scale(s0).translate(v0);
  t1 = Eigen::Scaling(s0) * Translation3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  t0.prescale(s0);
  t1 = Eigen::Scaling(s0) * t1;
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  
  t0 = t3;
  t0.scale(s0);
  t1 = t3 * Eigen::Scaling(s0,s0,s0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  t0.prescale(s0);
  t1 = Eigen::Scaling(s0,s0,s0) * t1;
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());


  t0.setIdentity();
  t0.prerotate(q1).prescale(v0).pretranslate(v0);
  // translation * aligned scaling and transformation * mat
  t1 = (Translation3(v0) * AlignedScaling3(v0)) * Transform3(q1);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // scaling * mat and translation * mat
  t1 = Translation3(v0) * (AlignedScaling3(v0) * Transform3(q1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  t0.setIdentity();
  t0.scale(v0).translate(v0).rotate(q1);
  // translation * mat and aligned scaling * transformation
  t1 = AlignedScaling3(v0) * (Translation3(v0) * Transform3(q1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // transformation * aligned scaling
  t0.scale(v0);
  t1 *= AlignedScaling3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // transformation * translation
  t0.translate(v0);
  t1 = t1 * Translation3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // translation * transformation
  t0.pretranslate(v0);
  t1 = Translation3(v0) * t1;
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // transform * quaternion
  t0.rotate(q1);
  t1 = t1 * q1;
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // translation * quaternion
  t0.translate(v1).rotate(q1);
  t1 = t1 * (Translation3(v1) * q1);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // aligned scaling * quaternion
  t0.scale(v1).rotate(q1);
  t1 = t1 * (AlignedScaling3(v1) * q1);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // quaternion * transform
  t0.prerotate(q1);
  t1 = q1 * t1;
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // quaternion * translation
  t0.rotate(q1).translate(v1);
  t1 = t1 * (q1 * Translation3(v1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // quaternion * aligned scaling
  t0.rotate(q1).scale(v1);
  t1 = t1 * (q1 * AlignedScaling3(v1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // test transform inversion
  t0.setIdentity();
  t0.translate(v0);
  t0.linear().setRandom();
  Matrix4 t044 = Matrix4::Zero();
  t044(3,3) = 1;
  t044.block(0,0,t0.matrix().rows(),4) = t0.matrix();
  VERIFY_IS_APPROX(t0.inverse(Affine).matrix(), t044.inverse().block(0,0,t0.matrix().rows(),4));
  t0.setIdentity();
  t0.translate(v0).rotate(q1);
  t044 = Matrix4::Zero();
  t044(3,3) = 1;
  t044.block(0,0,t0.matrix().rows(),4) = t0.matrix();
  VERIFY_IS_APPROX(t0.inverse(Isometry).matrix(), t044.inverse().block(0,0,t0.matrix().rows(),4));

  Matrix3 mat_rotation, mat_scaling;
  t0.setIdentity();
  t0.translate(v0).rotate(q1).scale(v1);
  t0.computeRotationScaling(&mat_rotation, &mat_scaling);
  VERIFY_IS_APPROX(t0.linear(), mat_rotation * mat_scaling);
  VERIFY_IS_APPROX(mat_rotation*mat_rotation.adjoint(), Matrix3::Identity());
  VERIFY_IS_APPROX(mat_rotation.determinant(), Scalar(1));
  t0.computeScalingRotation(&mat_scaling, &mat_rotation);
  VERIFY_IS_APPROX(t0.linear(), mat_scaling * mat_rotation);
  VERIFY_IS_APPROX(mat_rotation*mat_rotation.adjoint(), Matrix3::Identity());
  VERIFY_IS_APPROX(mat_rotation.determinant(), Scalar(1));

  // test casting
  Transform<float,3,Mode> t1f = t1.template cast<float>();
  VERIFY_IS_APPROX(t1f.template cast<Scalar>(),t1);
  Transform<double,3,Mode> t1d = t1.template cast<double>();
  VERIFY_IS_APPROX(t1d.template cast<Scalar>(),t1);

  Translation3 tr1(v0);
  Translation<float,3> tr1f = tr1.template cast<float>();
  VERIFY_IS_APPROX(tr1f.template cast<Scalar>(),tr1);
  Translation<double,3> tr1d = tr1.template cast<double>();
  VERIFY_IS_APPROX(tr1d.template cast<Scalar>(),tr1);

  AngleAxis<float> aa1f = aa1.template cast<float>();
  VERIFY_IS_APPROX(aa1f.template cast<Scalar>(),aa1);
  AngleAxis<double> aa1d = aa1.template cast<double>();
  VERIFY_IS_APPROX(aa1d.template cast<Scalar>(),aa1);

  Rotation2D<Scalar> r2d1(internal::random<Scalar>());
  Rotation2D<float> r2d1f = r2d1.template cast<float>();
  VERIFY_IS_APPROX(r2d1f.template cast<Scalar>(),r2d1);
  Rotation2D<double> r2d1d = r2d1.template cast<double>();
  VERIFY_IS_APPROX(r2d1d.template cast<Scalar>(),r2d1);

  t20 = Translation2(v20) * (Rotation2D<Scalar>(s0) * Scaling(s0));
  t21 = Translation2(v20) * Rotation2D<Scalar>(s0) * Scaling(s0);
  VERIFY_IS_APPROX(t20,t21);
}
Example #14
0
void CTTypes::RunTestCaseL(TInt aCurTestCase)
	{
	switch(aCurTestCase)
		{
	case 1:
		{
		__UHEAP_MARK;
		TestRgb tr1(0,0,0, this);
		TestRgb tr2(100,100,100, this);
		TestRgb tr3(10,20,30, this);
		TestRgb tr4(110,160,210, this);
		TestRgb tr5(255,255,255, this);
		INFO_PRINTF1(_L("TRgb"));
		tr1.Test();
		tr2.Test();
		tr3.Test();
		tr4.Test();
		tr5.Test();
		((CTTypesStep*)iStep)->CloseTMSGraphicsStep();
		__UHEAP_MARKEND;
		}
		break;
	case 2:
		{
		INFO_PRINTF1(_L("TTypeface"));
		TestTypeface ttf1(_L(""), 0, this);
		TestTypeface ttf2(_L("Font name"), 1, this);
		TestTypeface ttf3(_L("Font name"), 2, this);
		TestTypeface ttf4(_L("Font name"), 3, this);
		TestTypeface ttf5(_L("Font name"), 4, this);
		TestTypeface ttf6(_L("Font name"), 5, this);
		TestTypeface ttf7(_L("Font name"), 6, this);
		TestTypeface ttf8(_L("Another font name"), 7, this);
		ttf1.Test();
		ttf2.Test();
		ttf3.Test();
		ttf4.Test();
		ttf5.Test();
		ttf6.Test();
		ttf7.Test();
		ttf8.Test();
		}
		break;
	case 3:
		{
		TestMargins tm1(0,0,0,0, this);
		TestMargins tm2(10,20,30,40, this);
		TestMargins tm3(-10,-20,-30,-40, this);
		INFO_PRINTF1(_L("TMargins"));
		tm1.Test();
		tm2.Test();
		tm3.Test();
		}
		break;
	case 4:
		{
		TestPageSpec tps1(TPageSpec::EPortrait,TSize(0,0), this);
		TestPageSpec tps2(TPageSpec::ELandscape,TSize(0,0), this);
		TestPageSpec tps3(TPageSpec::EPortrait,TSize(10,-5), this);
		TestPageSpec tps4(TPageSpec::ELandscape,TSize(15,-20), this);
		TestPageSpec tps5(TPageSpec::EPortrait,TSize(1000,1500), this);
		TestPageSpec tps6(TPageSpec::ELandscape,TSize(2000,500), this);
		INFO_PRINTF1(_L("TPageSpec"));
		tps1.Test();
		tps2.Test();
		tps3.Test();
		tps4.Test();
		tps5.Test();
		tps6.Test();
		}
		break;
	case 5:
		{
		INFO_PRINTF1(_L("FontEffect"));
        	((CTTypesStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-0002"));
		TestFontEffect te(this); 
		((CTTypesStep*)iStep)->RecordTestResultL();
		te.Test();
		}
		break;
	case 6:
		{
		INFO_PRINTF1(_L("TFontSyle"));
		TestTFontStyle ts(this);
		ts.Test();
		}
		break;
	case 7:
		{
		TTypeface typeface;
		typeface.iName=_L("Font name");
		TFontStyle fontstyle;
		TestFontSpec tfspec(typeface,200,fontstyle, this);
		INFO_PRINTF1(_L("TFontSpec"));
		tfspec.Test();
		}
		break;
	case 8:
		{
/*
		TestLine tl1(TPoint(10,10),TPoint(90,90), this);
		TestLine tl2(TPoint(100,150),TPoint(50,-50), this);
		TestLine tl3(TPoint(-50,50),TPoint(60,-40), this);
		TestLine tl4(TPoint(-100,0),TPoint(0,200), this);
		TestLine tl5(TPoint(150,-50),TPoint(50,75), this);
		TestLine tl6(TPoint(0,-100),TPoint(-50,-150), this);
		TestLine tl7(TPoint(-1000,-1000),TPoint(1000,1000), this);
		TestLine tl8(TPoint(1000,-1000),TPoint(-1000,1000), this);
		TestLine tl9(TPoint(500,-1000),TPoint(-500,1000), this);
		TestLine tl10(TPoint(-500,-1000),TPoint(500,1000), this);
		TestLine tl11(TPoint(1000,-500),TPoint(-1000,500), this);
		TestLine tl12(TPoint(1000,500),TPoint(-1000,-500), this);
		INFO_PRINTF1(_L("TLinearDDA"));
		tl1.Test();
		tl2.Test();
		tl3.Test();
		tl4.Test();
		tl5.Test();
		tl6.Test();
		tl7.Test();
		tl8.Test();
		tl9.Test();
		tl10.Test();
		tl11.Test();
		tl12.Test();
*/
		INFO_PRINTF1(_L("TLinearDDA is only for Graphics team. Removed."));
		}
		break;
	case 9:
		{
		INFO_PRINTF1(_L("CTypefaceStore"));
		TestTFStore ttfs(this);
		ttfs.Test();
		}
		break;
	case 10:
		{
		INFO_PRINTF1(_L("CFontCache"));
		TestFontCache tfc(this);
		tfc.Test();
		}
		break;
	case 11:
		{
/*
		INFO_PRINTF1(_L("CScaleCropPicture"));
		TestPicture tp(this);
		tp.Test();
*/
		INFO_PRINTF1(_L("CScaleCropPicture is only for Graphics team. Removed."));
		}
		break;
	case 12:
		{
/*
		INFO_PRINTF1(_L("CPalette"));
		TestPalette tpal(this);
		tpal.Test();
*/
		INFO_PRINTF1(_L("CPalette is only for Graphics team. Removed."));
		}
		break;
	case 13:
		{
		INFO_PRINTF1(_L("TDisplayModeUtils"));
		TestDisplayModeUtils tdmu(this);
		tdmu.Test();
		}
		break;
	case 14:
        	((CTTypesStep*)iStep)->SetOverallTestStepID(_L("GRAPHICS-GDI-0001"));
		((CTTypesStep*)iStep)->RecordTestResultL();
		((CTTypesStep*)iStep)->CloseTMSGraphicsStep();
		TestComplete();		
		break;
		}
	}
int
main(int argc, char **argv) {
  uint64  genomeSize         = 0;
  char   *atacFileName       = 0L;
  char   *prefix             = 0L;
  char   *trFile1  = 0L;
  char   *trFile2  = 0L;
  char    prefixFull[1024];
  bool    error              = false;

  int arg=1;
  while (arg < argc) {
    if (strcmp(argv[arg], "-g") == 0) {
      ++arg;
      if        (argv[arg][0] == 'A') {
        genomeSize = 0;
      } else if (argv[arg][0] == 'B') {
        genomeSize = 1;
      } else {
        genomeSize = strtouint64(argv[arg], 0L);
      }
    } else if (strcmp(argv[arg], "-a") == 0) {
      atacFileName = argv[++arg];
    } else if (strcmp(argv[arg], "-p") == 0) {
      prefix = argv[++arg];
    } else if (strcmp(argv[arg], "-ta") == 0) {
      trFile1 = argv[++arg];
    } else if (strcmp(argv[arg], "-tb") == 0) {
      trFile2 = argv[++arg];
    } else {
      error = true;
    }
    arg++;
  }

  if (!atacFileName || !prefix || error) {
    fprintf(stderr, "usage: %s -a <file.atac> -p <outprefix> [-ta trfile] [-tb trfile] [-g {A | B | g}]\n", argv[0]);
    fprintf(stderr, "  -a          read input from 'file.atac'\n");
    fprintf(stderr, "  -p          write stats to files prefixed with 'outprefix'\n");
    fprintf(stderr, "  -g          use a genome size of g for the Nx computation, defaults to\n");
    fprintf(stderr, "              the length of the A sequence.  Or use the actual length\n");
    fprintf(stderr, "              of sequence A or B.\n");
    fprintf(stderr, "  -ta         read tandem repeats for A from trfile\n");
    fprintf(stderr, "  -tb         read tandem repeats for B from trfile\n");
    exit(1);
  }
  
  atacFile           AF(atacFileName);
  atacMatchList     &matches = *AF.matches();
  atacMatchList     &runs    = *AF.runs();
  atacMatchList     &clumps  = *AF.clumps();

  //  We end up using sequences a lot here, so just bite it and load them in a cache.
  //
  seqCache  *A = new seqCache(AF.assemblyFileA(), 0, true);
  seqCache  *B = new seqCache(AF.assemblyFileB(), 0, true);

  A->loadAllSequences();
  B->loadAllSequences();

  fprintf(stdout, "\nSEQUENCE\n");
  totalLength(AF, A, B);

  if (trFile1 && trFile2) {
    atacFileStream     tr1(trFile1);
    atacFileStream     tr2(trFile2);
    tandemRepeatStats(tr1, tr2, AF, A, B);
  }

  //  XXX unmappedInRuns only works on runs, and if we have clumps in
  //  the input it fails.
  //
  if ((runs.numberOfMatches() > 0) && (clumps.numberOfMatches() == 0)) {
    fprintf(stdout, "\nMATCHES IN RUNS\n");
    unmappedInRuns(AF, A, B, prefix);
  }

  if (matches.numberOfMatches() > 0) {
    fprintf(stdout, "\nMATCHES\n");
    sprintf(prefixFull, "%s-matches", prefix);
    mappedLengths(AF, matches, A, B, prefixFull);
    NxOfMapped(AF, matches, genomeSize, prefixFull);
    MappedByChromosome(AF, matches, A, B, prefixFull);
  }

  if (runs.numberOfMatches() > 0) {
    fprintf(stdout, "\nRUNS\n");
    sprintf(prefixFull, "%s-runs", prefix);
    mappedLengths(AF, runs, A, B, prefixFull);
    NxOfMapped(AF, runs, genomeSize, prefixFull);
    MappedByChromosome(AF, runs, A, B, prefixFull);
  }

  if (clumps.numberOfMatches() > 0) {
    fprintf(stdout, "\nCLUMPS\n");
    sprintf(prefixFull, "%s-clumps", prefix);
    mappedLengths(AF, clumps, A, B, prefixFull);
    NxOfMapped(AF, clumps, genomeSize, prefixFull);
    MappedByChromosome(AF, clumps, A, B, prefixFull);
  }

  delete A;
  delete B;

  return(0);
}
Example #16
0
void TestMatrix()
{
  TGeoHMatrix identity;
  /** translations **/
  TGeoTranslation tr1(1., 2., 3.);
  // Copy ctor
  TGeoTranslation tr2(tr1);
  myassert(tr2 == tr1, "translation copy ctor wrong");
  // Assignment
  tr2 = tr1;
  myassert(tr2 == tr1, "translation assignment wrong");
  myassert(tr2.IsTranslation(), "translation flag not set");
  // Composition
  TGeoTranslation trref1(2., 4., 6.);
  TGeoTranslation tr3 = tr1 * tr2;
  myassert(tr3 == trref1, "translation multiplication wrong");
  tr2 *= tr1;
  myassert(tr2 == trref1, "translation inplace multiplication wrong");
  tr2 *= tr2.Inverse();
  myassert(tr2 == identity, "translation inverse wrong");

  /** rotations **/
  TGeoRotation r1;
  r1.RotateZ(90.);
  // Copy ctor
  TGeoRotation r2(r1);
  myassert(r2 == r1, "rotation copy ctor wrong");
  // Assignment
  r2 = r1;
  myassert(r2 == r1, "rotation assignment wrong");
  myassert(r2.IsRotation(), "rotation flag not set");
  // Composition
  TGeoRotation r3  = r1 * r1 * r1 * r1;
  myassert(r3 == identity, "rotation multiplication wrong");
  r2 *= r2.Inverse();
  myassert(r2 == identity, "rotation inplace multiplication wrong");

   /** scale **/
  TGeoScale scl1(1., 2., 3.);
  // Copy ctor
  TGeoScale scl2(scl1);
  myassert(scl2 == scl1, "scale copy ctor wrong");
  // Assignment
  scl2 = scl1;
  myassert(scl2 == scl1, "scale assignment wrong");
  myassert(scl2.IsScale(), "scale flag not set");
  // Composition
  TGeoScale sclref1(1., 4., 9.);
  TGeoScale scl3 = scl1 * scl2;
  myassert(scl3 == sclref1, "scale multiplication wrong");
  scl2 *= scl1;
  myassert(scl2 == sclref1, "scale inplace multiplication wrong");
  scl2 *= scl2.Inverse();
  myassert(scl2 == identity, "scale inverse wrong");

  /** HMatrix **/
  // Copy constructor
  TGeoHMatrix h1(tr1);
  myassert(h1 == tr1 && h1.IsTranslation(), "hmatrix constructor from translation wrong");

  // Assignment
  TGeoHMatrix h2 = r1;
  TGeoHMatrix h3 = scl1;
  myassert(h2 == r1 && h3 == scl1 && h2.IsRotation() && h3.IsScale(), "hmatrix assignment wrong");

  TGeoHMatrix h4 = h1 * h2;
  myassert(tr1 == h4 && r1 == h4 && h4.IsTranslation() && h4.IsRotation(), "hmatrix multiplication wrong");

  h4 *= h4.Inverse();
  myassert(h4 == identity, "hmatrix inverse wrong");

  /** Combi trans **/
  // Copy constructor
  TGeoCombiTrans c1(tr1);
  myassert(c1 == tr1 && c1.IsTranslation(), "combi trans constructor from translation wrong");

  // Assignment
  TGeoCombiTrans c2 = r1;
  myassert(c2 == r1 && c2.IsRotation(), "combi trans assignment wrong");

  TGeoCombiTrans c3 = c1 * c2;
  myassert(tr1 == c3 && r1 == c3 && c3.IsTranslation() && c3.IsRotation(), "combi trans multiplication wrong");

  c3 *= c3.Inverse();
  myassert(c3 == identity, "combi trans inverse wrong");

  TGeoCombiTrans c4(1., 2., 3., &r1);
  c4.Print();
  TGeoCombiTrans c5(c4);
  c5.Print();
  myassert(c4.GetRotation() == &r1 && c5.GetRotation() != &r1, "combi trans copy constructor wrong");

  // Test for Wolfgang Korsch's case
  TGeoHMatrix href = tr1;
  href *= TGeoRotation("", 0, 120, 0);
  TGeoRotation r4;
  r4.SetAngles(0, 90, 0);
  TGeoRotation r5 = r4;
  r4.SetAngles(0, 30, 0);
  r5 = r5 * r4;
  TGeoHMatrix combiH1TB = tr1 * r5;
  myassert(combiH1TB == href, "translation multiplication demoted");

  // Test for David Rohr's case
  TGeoHMatrix h5 = href, h6 = href;
  h5 *= h6.Inverse();
  h6.Multiply(h6.Inverse());
  myassert(h5 == h6 && h5 == identity, "inverse not matching");
}
Example #17
0
//Bullet, a btVector can be used for both points and vectors. 
//it is up to the user/developer to use the right multiplication: btTransform for points, and btQuaternion or btMatrix3x3 for vectors.
void	BulletTest()
{

	printf("Bullet Linearmath\n");

	btTransform	tr;
	tr.setIdentity();

	tr.setOrigin(btVector3(10,0,0));
	//initialization
	btVector3	pointA(0,0,0);
	btVector3	pointB,pointC,pointD,pointE;
	//assignment
	pointB = pointA;
	//in-place initialization
	pointB.setValue(1,2,3);
	//transform over tr	
	pointB = tr * pointA;
	printf("pointB = tr * pointA = (%f,%f,%f)\n",pointB.getX(),pointB.getY(),pointB.getZ());
	//transform over tr	
	pointE = tr(pointA);
	//inverse transform
	pointC = tr.inverse() * pointA;
	printf("pointC = tr.inverse() * pointA = (%f,%f,%f)\n",pointC.getX(),pointC.getY(),pointC.getZ());
	//inverse transform
	pointD = tr.invXform( pointA );
	btScalar	x;
	//dot product
	x = pointD.dot(pointE);
	//square length
	x = pointD.length2();
	//length
	x = pointD.length();

	const btVector3& constPointD = pointD;

	//get a normalized vector from constPointD, without changing constPointD
	btVector3 norm = constPointD.normalized();

	//in-place normalize pointD
	pointD.normalize();

	//quaternions & matrices
	btQuaternion	quat(0,0,0,1);
	btQuaternion	quat1(btVector3(0,1,0),90.f * SIMD_RADS_PER_DEG);
	btMatrix3x3		mat0(quat1);
	btMatrix3x3		mat1 = mat0.inverse();
	btMatrix3x3		mat2  = mat0.transpose();
	btTransform tr1(mat2,btVector3(0,10,0));
	btTransform tr2 =tr1.inverse();
	btVector3	pt0(1,1,1);
	btVector3	pt1 = tr2 * pt0;

	printf("btVector3	pt1 = tr2 * pt0 =  (%f,%f,%f)\n",pt1.getX(),pt1.getY(),pt1.getZ());

	
	btVector3	pt2 = tr2.getBasis() * pt0;
	btVector3	pt3 = pt0 * tr2.getBasis();
	btVector3	pt4 =  tr2.getBasis().inverse() * pt0;
	btTransform tr3 =  tr2.inverseTimes(tr2);



}
Example #18
0
//vectormath makes a difference between point and vector.
void	VectormathTest()
{

	printf("Vectormath\n");

	Vectormath::Aos::Transform3 tr;
	tr = Vectormath::Aos::Transform3::identity();

	tr.setTranslation(Vectormath::Aos::Vector3(10,0,0));
	//initialization
	Vectormath::Aos::Point3	pointA(0,0,0);
	Vectormath::Aos::Point3	pointB,pointC,pointE;
	Vectormath::Aos::Vector3 pointD;
	//assignment
	pointB = pointA;
	//in-place initialization
	pointB = Vectormath::Aos::Point3(1,2,3); //or
	pointB.setElem(0,1); //or
	pointB.setX(1);

	//transform over tr	
	pointB = tr * pointA;

	printf("pointB = tr * pointA = (%f,%f,%f)\n",(float)pointB.getX(),(float)pointB.getY(),(float)pointB.getZ());
	//transform over tr	
	//pointE = tr(pointA);
	//inverse transform
	pointC = Vectormath::Aos::inverse(tr) * pointA;
	printf("Vectormath::Aos::inverse(tr) * pointA = (%f,%f,%f)\n",(float)pointC.getX(),(float)pointC.getY(),(float)pointC.getZ());
	
	
	
	btScalar	x;
	//dot product
	x = Vectormath::Aos::dot(Vectormath::Aos::Vector3(pointD),Vectormath::Aos::Vector3(pointE));
	//square length
	x = Vectormath::Aos::lengthSqr(Vectormath::Aos::Vector3(pointD));
	//length
	x = Vectormath::Aos::length(Vectormath::Aos::Vector3(pointD));

	const Vectormath::Aos::Vector3& constPointD = (Vectormath::Aos::Vector3&)pointD;

	//get a normalized vector from constPointD, without changing constPointD
	Vectormath::Aos::Vector3 norm = Vectormath::Aos::normalize(constPointD);

	//in-place normalize pointD
	pointD = Vectormath::Aos::normalize(Vectormath::Aos::Vector3(pointD));

	//quaternions & matrices
	Vectormath::Aos::Quat quat(0,0,0,1);
	Vectormath::Aos::Quat quat1;
	quat1 = Vectormath::Aos::Quat::rotationY(90.f * SIMD_RADS_PER_DEG);
	
	Vectormath::Aos::Matrix3	mat0(quat1);
	
	Vectormath::Aos::Matrix3	mat1 = Vectormath::Aos::inverse(mat0);
	Vectormath::Aos::Matrix3	mat2  = Vectormath::Aos::transpose(mat0);
	Vectormath::Aos::Transform3 tr1(mat2,Vectormath::Aos::Vector3(0,10,0));
	Vectormath::Aos::Transform3	tr2 = Vectormath::Aos::inverse(tr1);
	Vectormath::Aos::Point3	pt0(1,1,1);
	Vectormath::Aos::Point3	pt1 = tr2 * pt0;
	printf("Vectormath::Aos::Vector3	pt1 = tr2 * pt0; =  (%f,%f,%f)\n",(float)pt1.getX(),(float)pt1.getY(),(float)pt1.getZ());

	Vectormath::Aos::Vector3	pt2 = tr2.getUpper3x3() * Vectormath::Aos::Vector3(pt0);
	//Vectormath::Aos::Vector3	pt3 = pt0 * tr2.getUpper3x3();
	Vectormath::Aos::Vector3	pt3 = Vectormath::Aos::inverse(tr2.getUpper3x3()) * Vectormath::Aos::Vector3(pt0);
	Vectormath::Aos::Vector3	pt4 =  Vectormath::Aos::inverse(tr2.getUpper3x3()) * Vectormath::Aos::Vector3(pt0);
	Vectormath::Aos::Transform3		tr3 =  Vectormath::Aos::inverse(tr2) * tr2;

}
Example #19
0
template<typename Scalar> void geometry(void)
{
  /* this test covers the following files:
     Cross.h Quaternion.h, Transform.cpp
  */

  typedef Matrix<Scalar,2,2> Matrix2;
  typedef Matrix<Scalar,3,3> Matrix3;
  typedef Matrix<Scalar,4,4> Matrix4;
  typedef Matrix<Scalar,2,1> Vector2;
  typedef Matrix<Scalar,3,1> Vector3;
  typedef Matrix<Scalar,4,1> Vector4;
  typedef Quaternion<Scalar> Quaternionx;
  typedef AngleAxis<Scalar> AngleAxisx;
  typedef Transform<Scalar,2> Transform2;
  typedef Transform<Scalar,3> Transform3;
  typedef Scaling<Scalar,2> Scaling2;
  typedef Scaling<Scalar,3> Scaling3;
  typedef Translation<Scalar,2> Translation2;
  typedef Translation<Scalar,3> Translation3;

  Scalar largeEps = test_precision<Scalar>();
  if (ei_is_same_type<Scalar,float>::ret)
    largeEps = 1e-2f;

  Vector3 v0 = Vector3::Random(),
    v1 = Vector3::Random(),
    v2 = Vector3::Random();
  Vector2 u0 = Vector2::Random();
  Matrix3 matrot1;

  Scalar a = ei_random<Scalar>(-Scalar(M_PI), Scalar(M_PI));

  // cross product
  VERIFY_IS_MUCH_SMALLER_THAN(v1.cross(v2).eigen2_dot(v1), Scalar(1));
  Matrix3 m;
  m << v0.normalized(),
      (v0.cross(v1)).normalized(),
      (v0.cross(v1).cross(v0)).normalized();
  VERIFY(m.isUnitary());

  // Quaternion: Identity(), setIdentity();
  Quaternionx q1, q2;
  q2.setIdentity();
  VERIFY_IS_APPROX(Quaternionx(Quaternionx::Identity()).coeffs(), q2.coeffs());
  q1.coeffs().setRandom();
  VERIFY_IS_APPROX(q1.coeffs(), (q1*q2).coeffs());

  // unitOrthogonal
  VERIFY_IS_MUCH_SMALLER_THAN(u0.unitOrthogonal().eigen2_dot(u0), Scalar(1));
  VERIFY_IS_MUCH_SMALLER_THAN(v0.unitOrthogonal().eigen2_dot(v0), Scalar(1));
  VERIFY_IS_APPROX(u0.unitOrthogonal().norm(), Scalar(1));
  VERIFY_IS_APPROX(v0.unitOrthogonal().norm(), Scalar(1));


  VERIFY_IS_APPROX(v0, AngleAxisx(a, v0.normalized()) * v0);
  VERIFY_IS_APPROX(-v0, AngleAxisx(Scalar(M_PI), v0.unitOrthogonal()) * v0);
  VERIFY_IS_APPROX(ei_cos(a)*v0.squaredNorm(), v0.eigen2_dot(AngleAxisx(a, v0.unitOrthogonal()) * v0));
  m = AngleAxisx(a, v0.normalized()).toRotationMatrix().adjoint();
  VERIFY_IS_APPROX(Matrix3::Identity(), m * AngleAxisx(a, v0.normalized()));
  VERIFY_IS_APPROX(Matrix3::Identity(), AngleAxisx(a, v0.normalized()) * m);

  q1 = AngleAxisx(a, v0.normalized());
  q2 = AngleAxisx(a, v1.normalized());

  // angular distance
  Scalar refangle = ei_abs(AngleAxisx(q1.inverse()*q2).angle());
  if (refangle>Scalar(M_PI))
    refangle = Scalar(2)*Scalar(M_PI) - refangle;

  if((q1.coeffs()-q2.coeffs()).norm() > 10*largeEps)
  {
    VERIFY(ei_isApprox(q1.angularDistance(q2), refangle, largeEps));
  }

  // rotation matrix conversion
  VERIFY_IS_APPROX(q1 * v2, q1.toRotationMatrix() * v2);
  VERIFY_IS_APPROX(q1 * q2 * v2,
    q1.toRotationMatrix() * q2.toRotationMatrix() * v2);

  VERIFY( (q2*q1).isApprox(q1*q2, largeEps) || !(q2 * q1 * v2).isApprox(
    q1.toRotationMatrix() * q2.toRotationMatrix() * v2));

  q2 = q1.toRotationMatrix();
  VERIFY_IS_APPROX(q1*v1,q2*v1);

  matrot1 = AngleAxisx(Scalar(0.1), Vector3::UnitX())
          * AngleAxisx(Scalar(0.2), Vector3::UnitY())
          * AngleAxisx(Scalar(0.3), Vector3::UnitZ());
  VERIFY_IS_APPROX(matrot1 * v1,
       AngleAxisx(Scalar(0.1), Vector3(1,0,0)).toRotationMatrix()
    * (AngleAxisx(Scalar(0.2), Vector3(0,1,0)).toRotationMatrix()
    * (AngleAxisx(Scalar(0.3), Vector3(0,0,1)).toRotationMatrix() * v1)));

  // angle-axis conversion
  AngleAxisx aa = q1;
  VERIFY_IS_APPROX(q1 * v1, Quaternionx(aa) * v1);
  VERIFY_IS_NOT_APPROX(q1 * v1, Quaternionx(AngleAxisx(aa.angle()*2,aa.axis())) * v1);

  // from two vector creation
  VERIFY_IS_APPROX(v2.normalized(),(q2.setFromTwoVectors(v1,v2)*v1).normalized());
  VERIFY_IS_APPROX(v2.normalized(),(q2.setFromTwoVectors(v1,v2)*v1).normalized());

  // inverse and conjugate
  VERIFY_IS_APPROX(q1 * (q1.inverse() * v1), v1);
  VERIFY_IS_APPROX(q1 * (q1.conjugate() * v1), v1);

  // AngleAxis
  VERIFY_IS_APPROX(AngleAxisx(a,v1.normalized()).toRotationMatrix(),
    Quaternionx(AngleAxisx(a,v1.normalized())).toRotationMatrix());

  AngleAxisx aa1;
  m = q1.toRotationMatrix();
  aa1 = m;
  VERIFY_IS_APPROX(AngleAxisx(m).toRotationMatrix(),
    Quaternionx(m).toRotationMatrix());

  // Transform
  // TODO complete the tests !
  a = 0;
  while (ei_abs(a)<Scalar(0.1))
    a = ei_random<Scalar>(-Scalar(0.4)*Scalar(M_PI), Scalar(0.4)*Scalar(M_PI));
  q1 = AngleAxisx(a, v0.normalized());
  Transform3 t0, t1, t2;
  // first test setIdentity() and Identity()
  t0.setIdentity();
  VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());
  t0.matrix().setZero();
  t0 = Transform3::Identity();
  VERIFY_IS_APPROX(t0.matrix(), Transform3::MatrixType::Identity());

  t0.linear() = q1.toRotationMatrix();
  t1.setIdentity();
  t1.linear() = q1.toRotationMatrix();

  v0 << 50, 2, 1;//= ei_random_matrix<Vector3>().cwiseProduct(Vector3(10,2,0.5));
  t0.scale(v0);
  t1.prescale(v0);

  VERIFY_IS_APPROX( (t0 * Vector3(1,0,0)).norm(), v0.x());
  //VERIFY(!ei_isApprox((t1 * Vector3(1,0,0)).norm(), v0.x()));

  t0.setIdentity();
  t1.setIdentity();
  v1 << 1, 2, 3;
  t0.linear() = q1.toRotationMatrix();
  t0.pretranslate(v0);
  t0.scale(v1);
  t1.linear() = q1.conjugate().toRotationMatrix();
  t1.prescale(v1.cwise().inverse());
  t1.translate(-v0);

  VERIFY((t0.matrix() * t1.matrix()).isIdentity(test_precision<Scalar>()));

  t1.fromPositionOrientationScale(v0, q1, v1);
  VERIFY_IS_APPROX(t1.matrix(), t0.matrix());
  VERIFY_IS_APPROX(t1*v1, t0*v1);

  t0.setIdentity(); t0.scale(v0).rotate(q1.toRotationMatrix());
  t1.setIdentity(); t1.scale(v0).rotate(q1);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  t0.setIdentity(); t0.scale(v0).rotate(AngleAxisx(q1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  VERIFY_IS_APPROX(t0.scale(a).matrix(), t1.scale(Vector3::Constant(a)).matrix());
  VERIFY_IS_APPROX(t0.prescale(a).matrix(), t1.prescale(Vector3::Constant(a)).matrix());

  // More transform constructors, operator=, operator*=

  Matrix3 mat3 = Matrix3::Random();
  Matrix4 mat4;
  mat4 << mat3 , Vector3::Zero() , Vector4::Zero().transpose();
  Transform3 tmat3(mat3), tmat4(mat4);
  tmat4.matrix()(3,3) = Scalar(1);
  VERIFY_IS_APPROX(tmat3.matrix(), tmat4.matrix());

  Scalar a3 = ei_random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
  Vector3 v3 = Vector3::Random().normalized();
  AngleAxisx aa3(a3, v3);
  Transform3 t3(aa3);
  Transform3 t4;
  t4 = aa3;
  VERIFY_IS_APPROX(t3.matrix(), t4.matrix());
  t4.rotate(AngleAxisx(-a3,v3));
  VERIFY_IS_APPROX(t4.matrix(), Matrix4::Identity());
  t4 *= aa3;
  VERIFY_IS_APPROX(t3.matrix(), t4.matrix());

  v3 = Vector3::Random();
  Translation3 tv3(v3);
  Transform3 t5(tv3);
  t4 = tv3;
  VERIFY_IS_APPROX(t5.matrix(), t4.matrix());
  t4.translate(-v3);
  VERIFY_IS_APPROX(t4.matrix(), Matrix4::Identity());
  t4 *= tv3;
  VERIFY_IS_APPROX(t5.matrix(), t4.matrix());

  Scaling3 sv3(v3);
  Transform3 t6(sv3);
  t4 = sv3;
  VERIFY_IS_APPROX(t6.matrix(), t4.matrix());
  t4.scale(v3.cwise().inverse());
  VERIFY_IS_APPROX(t4.matrix(), Matrix4::Identity());
  t4 *= sv3;
  VERIFY_IS_APPROX(t6.matrix(), t4.matrix());

  // matrix * transform
  VERIFY_IS_APPROX(Transform3(t3.matrix()*t4).matrix(), Transform3(t3*t4).matrix());

  // chained Transform product
  VERIFY_IS_APPROX(((t3*t4)*t5).matrix(), (t3*(t4*t5)).matrix());

  // check that Transform product doesn't have aliasing problems
  t5 = t4;
  t5 = t5*t5;
  VERIFY_IS_APPROX(t5, t4*t4);

  // 2D transformation
  Transform2 t20, t21;
  Vector2 v20 = Vector2::Random();
  Vector2 v21 = Vector2::Random();
  for (int k=0; k<2; ++k)
    if (ei_abs(v21[k])<Scalar(1e-3)) v21[k] = Scalar(1e-3);
  t21.setIdentity();
  t21.linear() = Rotation2D<Scalar>(a).toRotationMatrix();
  VERIFY_IS_APPROX(t20.fromPositionOrientationScale(v20,a,v21).matrix(),
    t21.pretranslate(v20).scale(v21).matrix());

  t21.setIdentity();
  t21.linear() = Rotation2D<Scalar>(-a).toRotationMatrix();
  VERIFY( (t20.fromPositionOrientationScale(v20,a,v21)
        * (t21.prescale(v21.cwise().inverse()).translate(-v20))).matrix().isIdentity(test_precision<Scalar>()) );

  // Transform - new API
  // 3D
  t0.setIdentity();
  t0.rotate(q1).scale(v0).translate(v0);
  // mat * scaling and mat * translation
  t1 = (Matrix3(q1) * Scaling3(v0)) * Translation3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // mat * transformation and scaling * translation
  t1 = Matrix3(q1) * (Scaling3(v0) * Translation3(v0));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  t0.setIdentity();
  t0.prerotate(q1).prescale(v0).pretranslate(v0);
  // translation * scaling and transformation * mat
  t1 = (Translation3(v0) * Scaling3(v0)) * Matrix3(q1);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // scaling * mat and translation * mat
  t1 = Translation3(v0) * (Scaling3(v0) * Matrix3(q1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  t0.setIdentity();
  t0.scale(v0).translate(v0).rotate(q1);
  // translation * mat and scaling * transformation
  t1 = Scaling3(v0) * (Translation3(v0) * Matrix3(q1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // transformation * scaling
  t0.scale(v0);
  t1 = t1 * Scaling3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // transformation * translation
  t0.translate(v0);
  t1 = t1 * Translation3(v0);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());
  // translation * transformation
  t0.pretranslate(v0);
  t1 = Translation3(v0) * t1;
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // transform * quaternion
  t0.rotate(q1);
  t1 = t1 * q1;
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // translation * quaternion
  t0.translate(v1).rotate(q1);
  t1 = t1 * (Translation3(v1) * q1);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // scaling * quaternion
  t0.scale(v1).rotate(q1);
  t1 = t1 * (Scaling3(v1) * q1);
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // quaternion * transform
  t0.prerotate(q1);
  t1 = q1 * t1;
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // quaternion * translation
  t0.rotate(q1).translate(v1);
  t1 = t1 * (q1 * Translation3(v1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // quaternion * scaling
  t0.rotate(q1).scale(v1);
  t1 = t1 * (q1 * Scaling3(v1));
  VERIFY_IS_APPROX(t0.matrix(), t1.matrix());

  // translation * vector
  t0.setIdentity();
  t0.translate(v0);
  VERIFY_IS_APPROX(t0 * v1, Translation3(v0) * v1);

  // scaling * vector
  t0.setIdentity();
  t0.scale(v0);
  VERIFY_IS_APPROX(t0 * v1, Scaling3(v0) * v1);

  // test transform inversion
  t0.setIdentity();
  t0.translate(v0);
  t0.linear().setRandom();
  VERIFY_IS_APPROX(t0.inverse(Affine), t0.matrix().inverse());
  t0.setIdentity();
  t0.translate(v0).rotate(q1);
  VERIFY_IS_APPROX(t0.inverse(Isometry), t0.matrix().inverse());

  // test extract rotation and scaling
  t0.setIdentity();
  t0.translate(v0).rotate(q1).scale(v1);
  VERIFY_IS_APPROX(t0.rotation() * v1, Matrix3(q1) * v1);

  Matrix3 mat_rotation, mat_scaling;
  t0.setIdentity();
  t0.translate(v0).rotate(q1).scale(v1);
  t0.computeRotationScaling(&mat_rotation, &mat_scaling);
  VERIFY_IS_APPROX(t0.linear(), mat_rotation * mat_scaling);
  VERIFY_IS_APPROX(mat_rotation*mat_rotation.adjoint(), Matrix3::Identity());
  VERIFY_IS_APPROX(mat_rotation.determinant(), Scalar(1));
  t0.computeScalingRotation(&mat_scaling, &mat_rotation);
  VERIFY_IS_APPROX(t0.linear(), mat_scaling * mat_rotation);
  VERIFY_IS_APPROX(mat_rotation*mat_rotation.adjoint(), Matrix3::Identity());
  VERIFY_IS_APPROX(mat_rotation.determinant(), Scalar(1));

  // test casting
  Transform<float,3> t1f = t1.template cast<float>();
  VERIFY_IS_APPROX(t1f.template cast<Scalar>(),t1);
  Transform<double,3> t1d = t1.template cast<double>();
  VERIFY_IS_APPROX(t1d.template cast<Scalar>(),t1);

  Translation3 tr1(v0);
  Translation<float,3> tr1f = tr1.template cast<float>();
  VERIFY_IS_APPROX(tr1f.template cast<Scalar>(),tr1);
  Translation<double,3> tr1d = tr1.template cast<double>();
  VERIFY_IS_APPROX(tr1d.template cast<Scalar>(),tr1);

  Scaling3 sc1(v0);
  Scaling<float,3> sc1f = sc1.template cast<float>();
  VERIFY_IS_APPROX(sc1f.template cast<Scalar>(),sc1);
  Scaling<double,3> sc1d = sc1.template cast<double>();
  VERIFY_IS_APPROX(sc1d.template cast<Scalar>(),sc1);

  Quaternion<float> q1f = q1.template cast<float>();
  VERIFY_IS_APPROX(q1f.template cast<Scalar>(),q1);
  Quaternion<double> q1d = q1.template cast<double>();
  VERIFY_IS_APPROX(q1d.template cast<Scalar>(),q1);

  AngleAxis<float> aa1f = aa1.template cast<float>();
  VERIFY_IS_APPROX(aa1f.template cast<Scalar>(),aa1);
  AngleAxis<double> aa1d = aa1.template cast<double>();
  VERIFY_IS_APPROX(aa1d.template cast<Scalar>(),aa1);

  Rotation2D<Scalar> r2d1(ei_random<Scalar>());
  Rotation2D<float> r2d1f = r2d1.template cast<float>();
  VERIFY_IS_APPROX(r2d1f.template cast<Scalar>(),r2d1);
  Rotation2D<double> r2d1d = r2d1.template cast<double>();
  VERIFY_IS_APPROX(r2d1d.template cast<Scalar>(),r2d1);

  m = q1;
//   m.col(1) = Vector3(0,ei_random<Scalar>(),ei_random<Scalar>()).normalized();
//   m.col(0) = Vector3(-1,0,0).normalized();
//   m.col(2) = m.col(0).cross(m.col(1));
  #define VERIFY_EULER(I,J,K, X,Y,Z) { \
    Vector3 ea = m.eulerAngles(I,J,K); \
    Matrix3 m1 = Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z())); \
    VERIFY_IS_APPROX(m, m1); \
    VERIFY_IS_APPROX(m,  Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z()))); \
  }
  VERIFY_EULER(0,1,2, X,Y,Z);
  VERIFY_EULER(0,1,0, X,Y,X);
  VERIFY_EULER(0,2,1, X,Z,Y);
  VERIFY_EULER(0,2,0, X,Z,X);

  VERIFY_EULER(1,2,0, Y,Z,X);
  VERIFY_EULER(1,2,1, Y,Z,Y);
  VERIFY_EULER(1,0,2, Y,X,Z);
  VERIFY_EULER(1,0,1, Y,X,Y);

  VERIFY_EULER(2,0,1, Z,X,Y);
  VERIFY_EULER(2,0,2, Z,X,Z);
  VERIFY_EULER(2,1,0, Z,Y,X);
  VERIFY_EULER(2,1,2, Z,Y,Z);

  // colwise/rowwise cross product
  mat3.setRandom();
  Vector3 vec3 = Vector3::Random();
  Matrix3 mcross;
  int i = ei_random<int>(0,2);
  mcross = mat3.colwise().cross(vec3);
  VERIFY_IS_APPROX(mcross.col(i), mat3.col(i).cross(vec3));
  mcross = mat3.rowwise().cross(vec3);
  VERIFY_IS_APPROX(mcross.row(i), mat3.row(i).cross(vec3));


}
Example #20
0
int testTriangle() {
	int numErr = 0;

	logMessage(_T("TESTING  -  class GM_3dTriangle ...\n\n"));

	// Default constructor, triangle must be invalid
	GM_3dTriangle tr;
	if (tr.isValid()) {
		logMessage(_T("\tERROR - Default constructor creates valid triangle\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Default constructor creates invalid triangle\n"));
	}

	// Get/Set
	GM_3dPoint v1(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dPoint v2(getRandomDouble(), getRandomDouble(), getRandomDouble());
	GM_3dPoint v3(getRandomDouble(), getRandomDouble(), getRandomDouble());
	tr[0] = GM_3dLine(v1, v2);
	tr[1] = GM_3dLine(v2, v3);
	tr[2] = GM_3dLine(v3, v1);
	if (!tr.isValid() || tr[0].begin() != v1 || tr[0].end() != v2 || tr[1].begin() != v2 || tr[1].end() != v3
				|| tr[2].begin() != v3 || tr[2].end() != v1) {
		logMessage(_T("\tERROR - Get/Set not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Get/Set working\n"));
	}

	// Copy constructor
	GM_3dTriangle tr1(tr);
	if (!tr1.isValid() || tr[0] != tr1[0] || tr[1] != tr1[1] || tr[2] != tr1[2]) {
		logMessage(_T("\tERROR - Copy constructor not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Copy constructor working\n"));
	}

	// Constructor (points)
	GM_3dTriangle tr2(v1, v2, v3);
	if (!tr1.isValid() || tr[0] != tr2[0] || tr[1] != tr2[1] || tr[2] != tr2[2]) {
		logMessage(_T("\tERROR - Constructor (points) not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Constructor (points) working\n"));
	}

	// Constructor (lines)
	GM_3dTriangle tr3(tr[0], tr[1], tr[2]);
	if (!tr1.isValid() || tr[0] != tr3[0] || tr[1] != tr3[1] || tr[2] != tr3[2]) {
		logMessage(_T("\tERROR - Constructor (lines) not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Constructor (lines) working\n"));
	}

	// Inversion
	tr1.invert();
	if (!tr1.isValid() || tr1[0].begin() != tr[0].end() || tr1[0].end() != tr[0].begin() || tr1[1].begin() != tr[1].end() || tr1[1].end() != tr[1].begin() ||
				tr1[2].begin() != tr[2].end() || tr1[2].end() != tr[2].begin()) {
		logMessage(_T("\tERROR - Triangle inversion not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Triangle inversion working\n"));
	}

	// Vertical check
	GM_3dPoint vPoint = GM_3dLine(v1, v2).center();
	vPoint.z(vPoint.z() + getRandomDouble());
	GM_3dTriangle VTr(v1, v2, vPoint);
	if (!VTr.isValid() || !VTr.isVertical()) {
		logMessage(_T("\tERROR - Vertical check not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Vertical check working\n"));
	}

	// Horizontal check
	GM_3dTriangle HTr(tr);
	double z = getRandomDouble();
	for (unsigned int i = 0 ; i < 3 ; i++) {
		HTr[i].begin().z(z);
		HTr[i].end().z(z);
	}
	if (!HTr.isValid() || !HTr.isHorizontal()) {
		logMessage(_T("\tERROR - Horizontal check not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Horizontal check working\n"));
	}

	// Connection check
	GM_3dTriangle discTr(tr);
	discTr[0].begin().x(discTr[0].begin().x() + 2.0 * GM_DIFF_TOLERANCE);
	if (!discTr.isValid() || discTr.isConnected() || !tr.isConnected()) {
		logMessage(_T("\tERROR - Connection check not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Connection check working\n"));
	}

	// Max/Min z
	double maxZ = tr.maxZ();
	double minZ = tr.minZ();
	double checkMaxZ = -DBL_MAX;
	double checkMinZ = DBL_MAX;
	for (unsigned int i = 0 ; i < 3 ; i++) {
		if (tr[i].begin().z() > checkMaxZ) checkMaxZ = tr[i].begin().z();
		if (tr[i].begin().z() < checkMinZ) checkMinZ = tr[i].begin().z();
		if (tr[i].end().z() > checkMaxZ) checkMaxZ = tr[i].end().z();
		if (tr[i].end().z() < checkMinZ) checkMinZ = tr[i].end().z();
	}
	if (checkMinZ != minZ || checkMaxZ != maxZ) {
		logMessage(_T("\tERROR - Min/Max z not working\n"));
		numErr++;
	}
	else {
		logMessage(_T("\tOK - Min/Max z working\n"));
	}

	return numErr;
}