//funcion que halla el punto3d mas cercano de un segmento3d desde un punto3d 'p' punto3d segmento3d::proyeccion(punto3d p) { //Hay que determinar a cual de las 3 regiones pertenece. Si pertenece a la region del medio, el punto3d //resultante es el obtenido proyectando el punto 'p' a la recta3d que pasa por el segmento3d //Primero hallamos el punto proyeccion del punto3d 'p' sobre la recta3d que pasa por el segmento3d //Construyo una recta a partir de los puntos3d que definen el segmento3d recta3d r(ini,fin); //Proyecto el punto 'p' sobre esa recta 'r' punto3d proy = r.proyeccion(p); //Construyo los dos vectores desde 'p' hasta los extremos vector3d vi(p,ini); vector3d vf(p,fin); //Si 'proy' pertenece a la region del medio, ambos vectores 'vi' y 'vf' deben de apuntar a la misma direccion //Calculo la proyeccion (producto punto) de los dos vectores 'vi' y 'vf' float f =vi*vf; //Si apuntan a direcciones opuestas, es que esta en la region central, y el producto punto deberia dar negativo //En ese caso, el punto 'proy' proyectado si es el mas cercano al segmento de recta if (f<0) return (proy); //Sino, entonces veo cual de los dos extremos esta mas cerca. Para ello comparo la distancia (norma del vector) if (vi.norma() < vf.norma()) return (ini); else return (fin); }
int main() { PJWFront::GPUFrontal<float> vf(3, 1, 3); //vf.set(i, j, i+1); vf.set(0, 0, 1); vf.set(0, 1, 1); vf.set(0, 2, 1); vf.setRHS(0, 0); vf.set(1, 0, 1); vf.set(1, 1, -2); vf.set(1, 2, 2); vf.setRHS(1, 4); vf.set(2, 0, 1); vf.set(2, 1, 2); vf.set(2, 2, -1); vf.setRHS(2, 2); vf.solve(); std::vector<float> solution = vf.solution; for(int i=0; i<3; i++) cout << solution[i] << " "; cout << endl; return 0; }
void graph3d::grid_draw(void) { mesh_material::set_default(); VECT vn(0.0f,0.0f,-1.0f); VECT vf(0.0f,0.0f, 1.0f); GPIPE *p_gpipe = gpipe_get(); p_gpipe->screen_normal_to_world(&vn); p_gpipe->screen_normal_to_world(&vf); // v1->v2 VECT dir; dir = vf-vn; dir *= 0.5f; vn += dir; vn.y = 0.0f; VECT vl(-1.0f,0.0f,1.0f); VECT vr( 1.0f,0.0f,1.0f); p_gpipe->screen_normal_to_world(&vl); p_gpipe->screen_normal_to_world(&vr); VECT width; width = vr-vl; draw_floor_line(&vn,width.size(),2,40); }
int main(int argc, char* argv[]) { try { if (argc != 3) { std::cerr << "Usage: vorbis_file_example (input file) (output file)" << std::endl; return 1; } audio::vorbis_file_source vf(argv[1]); const audio::vorbis_info& info = vf.info(); audio::pcm_format fmt; fmt.type = audio::int_le16; fmt.channels = info.channels; fmt.rate = info.rate; io::copy( vf, audio::widen<float>( audio::wave_file_sink(argv[2], fmt) ) ); return 0; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } return 1; }
void CPointObj::glDrawElementFaceGoround(const int eid, void *pvoid) { ASSERT0(eid>=0 && eid<m_nVertexCount); Vector3d& v = m_pVertex[eid]; bool reverse_normal=false; if (pvoid) reverse_normal=true; if (this->NeedTexture1D() && m_pVertexTexCoor1D){ const float tx = m_pVertexTexCoor1D[eid]; glTexCoord1f(tx); } if (!m_pMatrix){ float r=0; if (m_pRadius) r= m_pRadius[eid]; if (r==0) r = m_fGivenRad; r *= m_pDrawParms->m_fVertexSizeScale; CSphere16::getInstance().glDraw(v, r, reverse_normal); } else{ Vector3f vf(v.x, v.y, v.z); float3x3 mat = m_pMatrix[eid]*m_pDrawParms->m_fVertexSizeScale; mat.Transpose(); CSphere16::getInstance().glDraw(vf, mat, reverse_normal); } }
void Cinema::load(){ ofDirectory dir("cinema/"); dir.listDir(); vector<string> dirs; for(int i=0;i<dir.size();i++){ string d = dir.getPath(i); if(d.find("DB")!=string::npos){ vector<string> vids; vector<ofVideoPlayer*> ps; ofDirectory dir2(d); dir2.listDir(); for(int j=0;j<dir2.size();j++){ vector<double> scene; vector<string> movs; string vidpath = dir2.getPath(j); string origVidPath = vidpath; if(dir2.getName(j)[0] != '.' && (vidpath.find(".mov")!=string::npos || vidpath.find(".mp4")!=string::npos || vidpath.find(".avi")!=string::npos || vidpath.find(".3gp")!=string::npos || vidpath.find(".gif")!=string::npos || vidpath.find(".webm")!=string::npos || vidpath.find(".mkv")!=string::npos)){ vids.push_back(vidpath); playerPaths.push_back(vidpath); ofVideoPlayer* p = new ofVideoPlayer; playerIntensities.push_back(0); ps.push_back(p); string txtPath = vidpath; ofStringReplace(txtPath, ".mov", ".txt"); ofStringReplace(txtPath, ".mp4", ".txt"); ofStringReplace(txtPath, ".mkv", ".txt"); ofStringReplace(txtPath, ".webm", ".txt"); ofStringReplace(txtPath, ".avi", ".txt"); ofStringReplace(txtPath, ".gif", ".txt"); string t = ofBufferFromFile(txtPath).getText(); if(t.compare("")){ vector<string > splitted = ofSplitString(t, "\n"); for(int x=0;x<splitted.size();x++){ vector<string> line = ofSplitString(splitted[x]," "); scene.push_back(ofToDouble(line[0])); if(line.size()>1) movs.push_back((line[1])); else movs.push_back(" "); } ofFile vf(vidpath) ; string absoluteVidPath = vf.getAbsolutePath(); playerScenes[absoluteVidPath] = scene; playerScenesMovements[origVidPath] = movs; } } } strdb.push_back(vids); } } }
void Refraction::backward(Vec3f& altAzPos) const { altAzPos.transfo4d(invertPostTransfoMatf); Vec3d vf(altAzPos[0], altAzPos[1], altAzPos[2]); innerRefractionBackward(vf); altAzPos.set(vf[0], vf[1], vf[2]); altAzPos.transfo4d(invertPreTransfoMatf); }
int main (void) { vf (0, s); if (d != s) abort (); exit (0); }
void Refraction::forward(Vec3f& altAzPos) const { Vec3d vf(altAzPos[0], altAzPos[1], altAzPos[2]); vf.transfo4d(preTransfoMat); innerRefractionForward(vf); vf.transfo4d(postTransfoMat); altAzPos.set(vf[0], vf[1], vf[2]); }
typename C::CellScalar timestep(C c) { typename C::CellScalar a,b; // TODO -- project horizontal and vertical velocities // for curved cells; currently assuming rectangular // elements a = (std::abs(uf(c.value()))+cf(c.value())) * c.dx(); b = (std::abs(vf(c.value()))+cf(c.value())) * c.dy(); return c.dx()*c.dy() / (a+b); }
int main(int argc,char *argv[]) { char fn[100],fn2[100],line[1000],SNPName[100],SNPNames[100],posSpec[100],*ptr; int i,first,cc; FILE *fp,*fg; gvaParams gp; analysisSpecs spec; fp=fopen(argv[1],"r"); gp.input(fp,spec); fclose(fp); masterLocusFile vf(gp.nCc[0]+gp.nCc[1]); strcpy(SNPNames,argv[2]); sprintf(fn,"gva.SNPs.db"); sprintf(fn2,"gva.SNPs.vdx"); unlink(fn); unlink(fn2); vf.openFiles(fn,fn2); first=1; fg=fopen(SNPNames,"r"); while (fgets(line,999,fg) && sscanf(line,"%s",SNPName)==1) { ptr=strchr(SNPName,':'); *ptr='\0'; int ff=0; for (cc=0;cc<2;++cc) for (i=0;i<gp.nCc[cc];++i) { sprintf(posSpec,"%s%s:%s-%s",spec.addChrInVCF[ff++]?"chr":"",SNPName,ptr+1,ptr+1); sprintf(fn,"gva.altSubs.%s.%d.vcf",cc?"case":"cont",i+1); sprintf(line,"tabix %s %s %s %s%s",first==1?"-h ":"",gp.ccFn[cc][i],posSpec,first==1?">":">>",fn); printf("%s\n",line); system(line); } first=0; } fclose(fg); for (cc=0;cc<2;++cc) for (i = 0; i < gp.nCc[cc]; ++i) { sprintf(fn, "gva.altSubs.%s.%d.vcf", cc ? "case" : "cont", i + 1); vf.addLocusFile(fn,VCFFILE); vf.readLocusFileEntries(fn, spec, cc); } sprintf(fn,"gva.%s","SNPs"); vf.writeOldScoreAssocFiles(fn,gp.wf,gp.wFunc,gp.useFreqs,gp.nSubs,1,gp.writeComments,spec); sprintf(line,"scoreassoc gva.SNPs.par gva.SNPs.dat %s",argv[3]); if (gp.writeScoreFile==1) sprintf(strchr(line,'\0')," gva.%s.sco",fn); system(line); return 0; }
void subtract ( const View& lhs, const View& rhs, View& dst ) { dst.altitude=lhs.altitude-rhs.altitude; std::vector<Vfeat>::const_iterator lt=lhs.features.begin(); std::vector<Vfeat>::const_iterator rt=rhs.features.begin(); for( ; lt!=lhs.features.end(); ++lt, ++rt ) { Vfeat vf( lt->current-rt->current, lt->initial-rt->initial, lt->reflection-rt->reflection ); dst.features.push_back(vf); } return ; } /* ----- end of method View::subtract ----- */
int main() { BARK("main()"); X().f(); Y<int,int>().f(); vf(); f(); g(); h(0); boost::implicit_cast<unsigned int>(X()); ::operator new(0, 'x'); bla<&operator<< >(); X()<<X(); std::cout << "-----------------\nNo test failures.\n"; }
bool LibAVFilterPrivate::pull(Frame *f) { AVFrameHolderRef frame_ref(new AVFrameHolder()); int ret = av_buffersink_get_frame(out_filter_ctx, frame_ref->frame()); if (ret < 0) { qWarning("av_buffersink_get_frame error: %s", av_err2str(ret)); return false; } VideoFrame vf(frame_ref->frame()->width, frame_ref->frame()->height, VideoFormat(frame_ref->frame()->format)); vf.setBits(frame_ref->frame()->data); vf.setBytesPerLine(frame_ref->frame()->linesize); vf.setMetaData("avframe_hoder_ref", QVariant::fromValue(frame_ref)); *f = vf; return true; }
/** *@brief 手先速度から関節角速度を取得 * @param v 手先速度 * @return 関節角速度 */ Vector3d RobotArm::calcJointVel(Vector3d v) { Matrix3d J = calcJacobian(theta); Matrix3d Jinv = J.inverse(); Vector3d vf(v(0), v(1), v(2)); Vector3d A = Jinv * vf; //std::cout << Jinv << std::endl << std::endl; return A; }
void Initializer::initialize() { if(is_initialized_) { DEBUG_M("Already initialized this list..."); return; } for(VoidFunction vf : init_list_) { if(vf) { vf(); } else { DEBUG_M("Bad function in initializing list!"); } } is_initialized_ = true; }
template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType) { typedef Matrix<float, SizeAtCompileType, SizeAtCompileType> Mat_f; typedef Matrix<double, SizeAtCompileType, SizeAtCompileType> Mat_d; typedef Matrix<std::complex<float>, SizeAtCompileType, SizeAtCompileType> Mat_cf; typedef Matrix<std::complex<double>, SizeAtCompileType, SizeAtCompileType> Mat_cd; typedef Matrix<float, SizeAtCompileType, 1> Vec_f; typedef Matrix<double, SizeAtCompileType, 1> Vec_d; typedef Matrix<std::complex<float>, SizeAtCompileType, 1> Vec_cf; typedef Matrix<std::complex<double>, SizeAtCompileType, 1> Vec_cd; Mat_f mf(size,size); Mat_d md(size,size); Mat_cf mcf(size,size); Mat_cd mcd(size,size); Vec_f vf(size,1); Vec_d vd(size,1); Vec_cf vcf(size,1); Vec_cd vcd(size,1); mf+mf; VERIFY_RAISES_ASSERT(mf+md); VERIFY_RAISES_ASSERT(mf+mcf); VERIFY_RAISES_ASSERT(vf=vd); VERIFY_RAISES_ASSERT(vf+=vd); VERIFY_RAISES_ASSERT(mcd=md); mf*mf; md*mcd; mcd*md; mf*vcf; mcf*vf; mcf *= mf; vcd = md*vcd; vcf = mcf*vf; #if 0 // these are know generating hard build errors in eigen3 VERIFY_RAISES_ASSERT(mf*md); VERIFY_RAISES_ASSERT(mcf*mcd); VERIFY_RAISES_ASSERT(mcf*vcd); VERIFY_RAISES_ASSERT(vcf = mf*vf); vf.eigen2_dot(vf); VERIFY_RAISES_ASSERT(vd.eigen2_dot(vf)); VERIFY_RAISES_ASSERT(vcf.eigen2_dot(vf)); // yeah eventually we should allow this but i'm too lazy to make that change now in Dot.h // especially as that might be rewritten as cwise product .sum() which would make that automatic. #endif }
int main() { BARK("main()"); X().f(); Y<int,int>().f(); vf(); f(); g(); h(0); boost::implicit_cast<unsigned int>(X()); ::operator new(0, 'x'); [](int){ BARK("main()::<lambda(int)>"); }(3); [](int, auto){ BARK("main()::<lambda(int, auto:1)> [with auto:1 = int]"); }(3, 2); bla<&operator<< >(); X()<<X(); std::cout << "-----------------\nNo test failures.\n"; }
View* View_list::view_at(Point p){ Rect f = frame(); Rect vf(f.p.x+list_width, f.p.y, f.s.w-list_width, f.s.h); if (vf.in_side(p)){ size_t ct = 0; View* v= list_begin; while(v && ct != active_view_count){ if (v->is_visible()){ if (v->frame().in_side(p)) return v; ct ++; } v= v->next_list_element(); } } return NULL; }
void LLTransferSourceAsset::responderCallback(LLVFS *vfs, const LLUUID& uuid, LLAssetType::EType type, void *user_data, S32 result, LLExtStat ext_status ) { LLUUID *tidp = ((LLUUID*) user_data); LLUUID transfer_id = *(tidp); delete tidp; tidp = NULL; LLTransferSourceAsset *tsap = (LLTransferSourceAsset *) gTransferManager.findTransferSource(transfer_id); if (!tsap) { LL_INFOS() << "Aborting transfer " << transfer_id << " callback, transfer source went away" << LL_ENDL; return; } if (result) { LL_INFOS() << "AssetStorage: Error " << gAssetStorage->getErrorString(result) << " downloading uuid " << uuid << LL_ENDL; } LLTSCode status; tsap->mGotResponse = TRUE; if (LL_ERR_NOERR == result) { // Everything's OK. LLVFile vf(gAssetStorage->mVFS, uuid, type, LLVFile::READ); tsap->mSize = vf.getSize(); status = LLTS_OK; } else { // Uh oh, something bad happened when we tried to get this asset! switch (result) { case LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE: status = LLTS_UNKNOWN_SOURCE; break; default: status = LLTS_ERROR; } } tsap->sendTransferStatus(status); }
void CTriangleObj::DrawPickingObject(const int objid) { int i, name = objid; Vector3i* m_pTriangle = (Vector3i*)m_pPolygon; SETUP_PICKING_GLENV(); glPushName(name); glBegin(GL_TRIANGLES); for (i=0; i<m_nPolygonCount; i++, name++){ for (int t=0; t<3; t++){ int p = m_pTriangle[i][t]; const Vector3d& v = m_pVertex[p]; Vector3f vf(v.x, v.y, v.z); glVertex3fv(&vf.x); } } glEnd(); glPopName(); }
Swarm::Swarm(int partAmount, int dimAmount, int maxEpoch, TopologyFactory::TOPOLOGY top, AlgorithmFactory::ALGORITHM alg, VelocityFactory::TYPE velType) { this->particleAmount = partAmount; this->dimensionAmount = dimAmount; this->maxEpoch = maxEpoch; AlgorithmFactory af(alg); this->algorithm = af.get(); TopologyFactory tf(top); this->topology = tf.get(); this->topology->init(partAmount); VelocityFactory vf(velType); this->velocity = vf.get(); this->ran = new IagoRandom(); initClerc(); }
int _sasl_check_db(const sasl_utils_t *utils, sasl_conn_t *conn) { const char *path = SASL_DB_PATH; int ret; void *cntxt; sasl_getopt_t *getopt; sasl_verifyfile_t *vf; if(!utils) return SASL_BADPARAM; if (utils->getcallback(conn, SASL_CB_GETOPT, &getopt, &cntxt) == SASL_OK) { const char *p; if (getopt(cntxt, NULL, "sasldb_path", &p, NULL) == SASL_OK && p != NULL && *p != 0) { path = p; } } ret = utils->getcallback(conn, SASL_CB_VERIFYFILE, &vf, &cntxt); if(ret != SASL_OK) { utils->seterror(conn, 0, "verifyfile failed"); return ret; } ret = vf(cntxt, path, SASL_VRFY_PASSWD); if (ret == SASL_OK) { db_ok = 1; } if (ret == SASL_OK || ret == SASL_CONTINUE) { return SASL_OK; } else { return ret; } }
int main( int argc, char ** argv ) { char * pth; pth = getenv( "VOICERECORDER" ); if( !pth ) { usage( argv[0] ); return -1; } // NOTE: on windows, put in a scan for a drive with label "IC_RECORDER" VoiceFile vf( pth ); if( !vf.Valid() ) { std::cerr << "Directory is invalid: " << pth << std::endl; return -2; } int ret = vf.Dump(); return ret; }
void Controller::jump() { // Change to leaping pose mDesiredDofs = mDefaultPose; mDesiredDofs[6] = 0.2; mDesiredDofs[9] = 0.2; mDesiredDofs[14] = -0.2; mDesiredDofs[15] = -0.2; mDesiredDofs[17] = -0.2; mDesiredDofs[19] = -0.2; mDesiredDofs[27] = 0.3; mDesiredDofs[28] = -1.0; mDesiredDofs[30] = 0.3; mDesiredDofs[31] = 1.0; mDesiredDofs[33] = 0.5; mDesiredDofs[34] = 0.5; stablePD(); // Use Jacobian transpose to compute pushing torques Eigen::Vector3d vf(-800.0, -3500.0, 0.0); if(numBars==1){ vf.x() = 6000 * barPositions[0].x() - 5600; vf.y() = -5000 * barPositions[0].y() + 2000; } else{ vf.x() = 6000 * barPositions[1].x() - 5600; vf.y() = -5000 * barPositions[1].y() + 2000; } Eigen::Vector3d offset(0.05, -0.02, 0.0); virtualForce(vf, mSkel->getBodyNode("h_heel_left"), offset); virtualForce(vf, mSkel->getBodyNode("h_heel_right"), offset); checkContactState(); if (mFootContact == NULL) { mState = "REACH"; std::cout << mCurrentFrame << ": " << "JUMP -> REACH" << std::endl; } }
int main( int argc, char* argv[] ) { // Lecture de la vidéo passée en paramètre // La création du vecteur se fait à la lecture VideoFrames vf(argv[1]); // Affichage de la première trame const cv::Mat& frame = vf.frame(1); if(! frame.data ) { std::cout << "Impossible d'afficher l'image" << std::endl ; return -1; } cv::namedWindow( "Résultat", CV_WINDOW_AUTOSIZE); imshow( "Résultat", frame ); cv::waitKey(0); // Appuyer sur une touche pour pouvoir continuer // Sauvegarde de la séquence des trames vf.saveToPngSequence(argv[2]); return 0; }/*
LLTSCode LLTransferTargetVFile::dataCallback(const S32 packet_id, U8 *in_datap, const S32 in_size) { //llinfos << "LLTransferTargetFile::dataCallback" << llendl; //llinfos << "Packet: " << packet_id << llendl; LLVFile vf(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::APPEND); if (mNeedsCreate) { vf.setMaxSize(mSize); mNeedsCreate = FALSE; } if (!in_size) { return LLTS_OK; } if (!vf.write(in_datap, in_size)) { llwarns << "Failure in LLTransferTargetVFile::dataCallback!" << llendl; return LLTS_ERROR; } return LLTS_OK; }
std::vector<Foo> getFoos(int ct) { std::vector<Foo> vf(ct); return vf; }
void LLTransferTargetVFile::completionCallback(const LLTSCode status) { //llinfos << "LLTransferTargetVFile::completionCallback" << llendl; if (!gAssetStorage) { llwarns << "Aborting vfile transfer after asset storage shut down!" << llendl; return; } // Still need to gracefully handle error conditions. S32 err_code = 0; switch (status) { case LLTS_DONE: if (!mNeedsCreate) { LLVFile file(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::WRITE); if (!file.rename(mParams.getAssetID(), mParams.getAssetType())) { llwarns << "LLTransferTargetVFile: rename failed" << llendl; } } err_code = LL_ERR_NOERR; lldebugs << "LLTransferTargetVFile::completionCallback for " << mParams.getAssetID() << "," << LLAssetType::lookup(mParams.getAssetType()) << " with temp id " << mTempID << llendl; break; case LLTS_ERROR: case LLTS_ABORT: case LLTS_UNKNOWN_SOURCE: default: { // We're aborting this transfer, we don't want to keep this file. llwarns << "Aborting vfile transfer for " << mParams.getAssetID() << llendl; LLVFile vf(gAssetStorage->mVFS, mTempID, mParams.getAssetType(), LLVFile::APPEND); vf.remove(); } break; } switch (status) { case LLTS_DONE: err_code = LL_ERR_NOERR; break; case LLTS_UNKNOWN_SOURCE: err_code = LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE; break; case LLTS_INSUFFICIENT_PERMISSIONS: err_code = LL_ERR_INSUFFICIENT_PERMISSIONS; break; case LLTS_ERROR: case LLTS_ABORT: default: err_code = LL_ERR_ASSET_REQUEST_FAILED; break; } if (mParams.mCompleteCallback) { mParams.mCompleteCallback(err_code, mParams.getAssetID(), mParams.getAssetType(), mParams.mUserDatap, LL_EXSTAT_NONE); } }
bool vector_test::run() { bool ok = true; vector< 4, double > v; double data[] = { 1, 2, 3, 4 }; v.iter_set( data, data+4 ); // tests copyFrom1DimCArray function ok = true; { size_t tmp = 1; for( size_t index = 0; ok && index < 4; ++index, ++tmp ) { ok = v.at( index ) == tmp; } tmp = 4; float dataf[] = { 4, 3, 2, 1 }; v.iter_set( dataf, dataf + 4 ); for( size_t index = 0; ok && index < 4; ++index, --tmp ) { ok = v.at( index ) == tmp; } log( "set( input_iterator begin_, input_iterator end_ )", ok ); if ( ! ok ) { std::stringstream error; error << v << std::endl; log_error( error.str() ); } } // tests operator+ function ok = true; { vector< 4, double > v_other; vector< 4, double > v_result; v = data; double datad[] = { 4, 3, 2, 1 }; v_other = datad; v_result = v + v_other; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == 5; } v_result = v; v_result += v_other; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == 5; } v = data; v_result = v + 2; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == index + 3; } v_result = v; v_result += 2; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == index + 3; } log( "operator+, operator+=", ok ); if ( ! ok ) { std::stringstream error; error << "\n" << "v " << v << "v_other " << v_other << "v_result " << v_result << std::endl; log_error( error.str() ); } } // tests operator- function ok = true; { vector< 4, double > v_other; vector< 4, double > v_result; v = data; double datad[] = { 1, 2, 3, 4 }; v_other = datad; v_result = v - v_other; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == 0; } v_result = v; v_result -= v_other; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == 0; } v_result = v - 1.0; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == index; } v_result = v; v_result -= 1.0; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == index; } log( "operator-, operator-=", ok ); if ( ! ok ) { std::stringstream error; error << "\n" << "v " << v << "v_other " << v_other << "v_result " << v_result << std::endl; log_error( error.str() ); } } // tests operator* function ok = true; { vector< 4, double > v_other; vector< 4, double > v_result; v = data; double datad[] = { 24, 12, 8, 6 }; v_other = datad; v_result = v * v_other; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == 24; } v_result = v; v_result *= v_other; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == 24; } v_result = v * 2.0; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == v.at( index ) * 2.0; } v_result = v; v_result *= 2.0; for( size_t index = 0; ok && index < 4; ++index ) { ok = v_result.at( index ) == v.at( index ) * 2.0; } log( "operator*, operator*=", ok ); if ( ! ok ) { std::stringstream error; error << "\n" << "v " << v << "v_other " << v_other << "v_result " << v_result << std::endl; log_error( error.str() ); } } // tests operator/ function ok = true; { vector< 4, double > v_other; vector< 4, double > v_result; v = data; double datad[] = { 2, 4, 6, 8 }; v_other = datad; v_result = v / v_other; for( size_t index = 0; ok && index < 4; ++index ) { ok = ( v_result.at( index ) - 0.5 ) < 1e-12; } v_result = v; v_result /= v_other; for( size_t index = 0; ok && index < 4; ++index ) { ok = ( v_result.at( index ) - 0.5 ) < 1e-12; } v_result = v / 1.5; for( size_t index = 0; ok && index < 4; ++index ) { ok = ( v_result.at( index ) - ( v.at( index ) / 1.5 ) ) < 1e-12; } v_result = v; v_result /= 1.5; for( size_t index = 0; ok && index < 4; ++index ) { ok = ( v_result.at( index ) - ( v.at( index ) / 1.5 ) ) < 1e-12; } log( "operator/, operator/=", ok ); if ( !ok ) { std::stringstream error; error << "\n" << "v " << v << "v_other " << v_other << "v_result " << v_result << std::endl; log_error( error.str() ); } } // tests norm / normSquared (length/lengthSquared) computation ok = true; { vector< 4, double > vec; vec = data; double normSquared = vec.squared_length(); ok = normSquared == 1 * 1 + 2 * 2 + 3 * 3 + 4 * 4; double norm = vec.length(); if ( ok ) ok = sqrt( normSquared ) == norm; log( "length(), squared_length()", ok ); } // tests normalize ok = true; { vector< 4, double > vec; vec = data; vec.normalize(); ok = vec.length() == 1.0; log( "normalize(), maximum precision", ok, true ); if ( ! ok ) { ok = vec.length() - 1.0 < 1e-15; log( "normalize(), tolerance 1e-15", ok ); } if ( ! ok ) { std::stringstream ss; ss << "length after normalize() " << vec.length() << std::endl; log_error( ss.str() ); } } // constructor tests { bool ok = true; double vData[] = { 1, 2, 3, 4 }; vector< 4, double > v4( 1, 2, 3, 4 ); vector< 2, double > v2C; v2C = vData; vector< 2, double > v2( 1, 2 ); if ( ok && v2 != v2C ) ok = false; vector< 3, double > v3C; v3C = vData; vector< 3, double > v3( 1, 2, 3 ); if ( ok && v3 != v3C ) ok = false; vector< 4, double > v4C; v4C = vData; if ( ok && v4 != v4C ) ok = false; double vData2[] = { 23, 23, 23, 23 }; v4C = vData2; vector< 4, double > v4_( 23 ); if ( ok && v4_ != v4C ) ok = false; v3 = vData; v4C = vData; vector< 4, double > v4from3_1( v3, vData[ 3 ] ); if ( ok && v4from3_1 != v4C ) ok = false; double hvData[] = { 1., 2., 3., 0.25 }; double xvData[] = { 4.0, 8.0, 12.0 }; vector< 4, double > homogenous; homogenous.iter_set( hvData, hvData + 4 ); vector< 3, double > nonh; nonh.iter_set( xvData, xvData + 3 ); vector< 4, double > htest( nonh ); // to-homogenous-coordinates ctor if ( ok && htest != vector< 4, double >( 4, 8., 12., 1. ) ) { ok = false; } vector< 3, double > nhtest( homogenous ); // from homogenous-coordiates ctor if ( ok && nhtest != nonh ) { ok = false; } log( "constructors ", ok ); } // set tests { bool ok = true; vector< 4, double > vec; vec.set( 2, 3, 4, 5 ); vector< 4, double > vecCorrect; double vCData[] = { 2, 3, 4, 5 }; vecCorrect = vCData; if ( vec != vecCorrect ) ok = false; vec.set( 2 ); double vCData2[] = { 2, 2, 2, 2 }; vecCorrect = vCData2; if ( vec != vecCorrect ) ok = false; vector< 3, double > v( 2, 3, 4 ); // uncommenting the following line will throw a compiler error because the number // of arguments to set is != M //v.set( 2, 3, 4, 5 ); vecCorrect = vCData; vec.set( v, 5 ); if ( vec != vecCorrect ) ok = false; log( "set() functions", ok ); } // component accessors { bool ok = true; vector< 4, double > vd( 1, 2, 3, 4 ); if ( vd.x() == 1 && vd.y() == 2 && vd.z() == 3 && vd.w() == 4 ) {} else ok = false; log( "component accessors ( x(), y(), z(), w() )", ok ); } // dot product { bool ok = true; vector< 3, float > v0( 1, 2, 3 ); vector< 3, float > v1( -6, 5, -4 ); if ( v0.dot( v1 ) != -8 ) ok = false; log( "dot product, dot()", ok ); } // cross product { bool ok = true; vector< 3, float > v0( 1, 2, 3 ); vector< 3, float > v1( -6, 5, -4 ); vector< 3, float > vcorrect( -23, -14, 17 ); if ( v0.cross( v1 ) != vcorrect ) ok = false; log( "cross product, cross()", ok ); } { // TODO vector< 3, float > v0( 1, 2, 3 ); vector< 3, float > v1( -6, 5, -4 ); vector< 3, float > v2( -2, 2, -1 ); v0.squared_distance( v1 ); vector< 3, float > n; n.compute_normal( v0, v1, v2 ); vector< 3, double > vd( 3, 2, 1 ); v0 = vd; } { vector< 4, float > vf( -1.0f, 3.0f, -99.0f, -0.9f ); vector< 4, size_t > vui( 0, 5, 2, 4 ); bool ok = true; size_t index = vf.find_min_index(); float f = vf.find_min(); if ( index != 2 || f != -99.0f ) ok = false; if ( ok ) { index = vf.find_max_index(); f = vf.find_max(); if ( index != 1 || f != 3.0f ) ok = false; } size_t ui; if ( ok ) { index = vui.find_min_index(); ui = vui.find_min(); if ( index != 0 || ui != 0 ) { ok = false; } } if ( ok ) { index = vui.find_max_index(); ui = vui.find_max(); if ( index != 1 || ui != 5 ) { ok = false; } } log( "find_min/max(), find_min_index/max_index()", ok ); } { vector< 4, float > v( -1.0f, 3.0f, -99.0f, -0.9f ); float f = 4.0f; vector< 4, float > v_scaled = f * v; ok = true; if ( v_scaled != vector< 4, float >( -4.0f, 12.0f, -396.0f, -3.6f ) ) { ok = false; } log( "operator*( float, vector )", ok ); } { vector< 3, float > vf( 3.0, 2.0, 1.0 ); vector< 3, double > vd( vf ); vector< 3, double >::const_iterator it = vd.begin(), it_end = vd.end(); vector< 3, float >::const_iterator fit = vf.begin(); bool ok = true; for( ; ok && it != it_end; ++it, ++fit ) { if ( *it != *fit ) ok = false; } vd = 0.0; vd = vf; for( ; ok && it != it_end; ++it, ++fit ) { if ( *it != *fit ) ok = false; } // to-homogenous-coords and from-homogenous-coords assignment ops // are already tested in the tests for the respective ctors, // since the ctors call the assignment ops log( "conversion operator=, conversion ctor", ok ); } { vector< 4, float > vf( 3.0, 2.0, 1.0, 1.0 ); vector< 3, float >& v3 = vf.get_sub_vector< 3 >(); bool ok = v3.x() == vf.x() && v3.y() == vf.y(); v3.normalize(); if ( ok ) ok = v3.x() == vf.x() && v3.y() == vf.y(); log( "get_sub_vector< N >()", ok ); } #ifndef VMMLIB_NO_CONVERSION_OPERATORS { vector< 4, double > v; double* array = v; //const double* const_array = v; array[ 1 ] = 2.0; //const_array[ 2 ] = 3.0; } #endif { //elementwise sqrt vector< 4, float > vsq( 9.0, 4.0, 1.0, 2.0 ); vector< 4, float > vsq_check( 3.0, 2.0, 1.0, 1.414213538169861 ); vsq.sqrt_elementwise(); bool ok = vsq == vsq_check; log( "elementwise sqrt ", ok ); } { //elementwise sqrt vector< 4, float > vr( 9.0, 4.0, 1.0, 2.0 ); vector< 4, float > vr_check( 0.1111111119389534, 0.25, 1, 0.5 ); vr.reciprocal(); bool ok = vr == vr_check; log( "reciprocal ", ok ); } { //l2 norm vector< 4, float > vr( 9.0, 4.0, 1.0, 2.0 ); double v_norm_check = 10.09950493836208; double v_norm = vr.norm(); bool ok = ((v_norm - v_norm_check) < 0.0001); log( "l2 norm ", ok ); } return ok; }