Exemplo n.º 1
0
PassOwnPtr<CCAnimationCurve> CCKeyframedTransformAnimationCurve::clone() const
{
    OwnPtr<CCKeyframedTransformAnimationCurve> toReturn(CCKeyframedTransformAnimationCurve::create());
    for (size_t i = 0; i < m_keyframes.size(); ++i)
        toReturn->addKeyframe(m_keyframes[i]->clone());
    return toReturn.release();
}
Exemplo n.º 2
0
bool Ray::GetRefracted( Ray& outRay, const glm::vec3& normal, 
	const glm::vec3& hitPt, float matRefrIndex) const{
	
	glm::vec3 incident = hitPt - this->m_start;
	glm::vec3 normalNormal = glm::normalize( normal ); //normalized normal
	incident = glm::normalize( incident );

	if( isInside ){
		matRefrIndex = 1.0f; //air
	}

	float nRatio = this->m_start_refr_ind / matRefrIndex;	

	float critDisc = 1 - nRatio*nRatio*( 1 - 
		(float)pow(glm::dot(normal, incident), 2) );

	
	//NOTE: we are omitting the case where critical angle == incident angle.
	//In practice, it probably won't happen due to floating point. 
	if( critDisc < 0 ) { //critical angle, ray gets reflected	
		return false;
	} else {
		float nScale = -1 * nRatio * glm::dot(normalNormal, incident) - 
			(float)sqrt(critDisc);
		glm::vec3 transmitDir = nScale * normalNormal + nRatio * incident;
		transmitDir = glm::normalize( transmitDir );
		Ray toReturn( hitPt + 0.001f * transmitDir, transmitDir );
		toReturn.m_start_refr_ind = matRefrIndex;
		toReturn.isInside = !this->isInside;
		outRay = toReturn; 
		return true;
	}
}
CoefficientSpectrum operator*( float c, const CoefficientSpectrum& s ){
	CoefficientSpectrum toReturn( s.getDim() );
	for( int i = 0; i < s.getDim(); i++ ){
		toReturn.m_v[i] = s.m_v[i] * c;
	}
	return toReturn;
}
Exemplo n.º 4
0
std::string Client::moveString(const Move &move, Piece promotionChoice) const
{
    std::string toReturn(colToString(move.square_1.col) + std::to_string(move.square_1.row+1)
                         + colToString(move.square_2.col) + std::to_string(move.square_2.row+1));
    if (promotionChoice != Piece::None) toReturn += "=" + pieceToSymbol(promotionChoice);
    return toReturn;
}
Exemplo n.º 5
0
Pattern ParallelInfo::rcvZi()
{
   int  P_Tag = 0;
   MPI_Status P_Status;
#if defined(TIMING_MODE)
   start = rdtsc();
#endif

#if defined(RNG_BUCKET)
   P_RandComm->Recv(&(P_Nodes[0].P_zi[0]), totalNumNrns, MPI_INT,
                    P_ROOT_NODE_NUM, P_Tag, MPI_COMM_WORLD, &P_Status);
#else
   MPI_Recv(&(P_Nodes[0].P_zi[0]), totalNumNrns, MPI_INT, P_ROOT_NODE_NUM,
            P_Tag, MPI_COMM_WORLD, &P_Status);
#endif

#if defined(TIMING_MODE)
   elapsed = rdtsc() - start;
   Output::Out() << MSG << "Elapsed nonroot_rcv time = " 
                 << elapsed * 1.0 / TICKS_PER_SEC << " seconds" << endl;
#endif

   Pattern toReturn(totalNumNrns);
   for (unsigned int i = 0; i < totalNumNrns; i++)
      toReturn.at(i) = P_Nodes[0].P_zi[i];
   return toReturn;
}
Exemplo n.º 6
0
std::string uParserBed::_getNextEntry(char* line)
{
    char toReturnChar[4096];
    int i = 0;

    /**< Fetch the next entry */
    do
    {
        toReturnChar[i] = line[i];
        i++;
    } while (line[i] != m_delimiter && line[i] != '\0');
    toReturnChar[i] = '\0';

    /**< Remove fetched entry from line */
    int j = 0;
    if (line[i] != '\0')
    {
        i++;
        do
        {
            line[j] = line[i];
            i++;
            j++;
        } while (line[i] != '\n' && line[i] != '\0');
    }
    line[j] = '\0';

    std::string toReturn(toReturnChar);
    return toReturn;
}
Exemplo n.º 7
0
/// gets a user-inputted string until return is entered
/// will use getChar to process characters one by one so that individual
/// key handlers can be created
std::string getInputString(teasafe::TeaSafe &theBfs, std::string const &workingPath)
{
    std::string toReturn("");

    // disable echo and prevent need to press enter for getchar flush
    setupTerminal();

    int cursorPos(0);
    while(1) {
        char c = getchar();
        if((int)c == 10) { // enter
            std::cout<<std::endl;
            break;
        }
        if((int)c == 127 || (int)c == 8) { // delete / backspace

            handleBackspace(cursorPos, toReturn);

        } else if((int)c == 9) { // tab

            handleTabKey(theBfs, workingPath, cursorPos, toReturn);

        } else { // print out char to screen and push into string vector
            std::cout<<c;
            ++cursorPos;
            toReturn.push_back(c);
        }
    }
    return toReturn;
}
//----------------------------------------------------------------------------------------
// ConvertPageItemInnerToSpread
//----------------------------------------------------------------------------------------
PMRect
CZExpPageItemUtils::ConvertPageItemInnerToSpread(
	const ISpread *				inSpread,
	const IGeometry *			inPageItemGeometry,
	const PMRect &				inPageItemRect) const
{
	PMRect toReturn(inPageItemRect);

#if 1
	InterfacePtr<const ITransform> spreadTransform( inSpread, UseDefaultIID() );
	ASSERT( inSpread );

	InterfacePtr<const ITransform> pageItemTransform( inPageItemGeometry, UseDefaultIID() );
	ASSERT( pageItemTransform );

	PMMatrix pageItemToSpreadMatrix;
	
	pageItemTransform->GetInnerToRootMatrix( &pageItemToSpreadMatrix, spreadTransform );

	pageItemToSpreadMatrix.Transform( &toReturn );
#else
	TransformInnerRectToParent( inPageItemGeometry, &toReturn );	//Page item parent is spread.
#endif

	return toReturn;
}
Exemplo n.º 9
0
elliptic_point elliptic_point::operator+(const elliptic_point &P) const{
  int lambda = 0;
  elliptic_point toReturn(0,0);
  
  if(this->isPOI)
    return P;
  else if(P.isPOI)
    return (*this);
  
  if((*this) == P){
    if(P.y == 0){
      toReturn.isPOI = true;
      return toReturn;
    }
    int twoypinv = modular_inverse(modular_positive(2 * P.y, mod), mod);
    lambda = modular_positive((3 * P.x * P.x + a) * twoypinv, mod);
  }else{
    if(this->x == P.x){
      toReturn.isPOI = true;
      return toReturn;
    }
    int xsinv = modular_inverse(modular_positive(this->x - P.x, mod), mod);
    lambda = modular_positive((this->y - P.y) * xsinv, mod);
  }

  toReturn.x = modular_positive(((lambda * lambda) - (P.x) - (this->x)), mod);
  toReturn.y = modular_positive(((lambda * (P.x - toReturn.x)) - P.y), mod);
  
  return toReturn;
}
CoefficientSpectrum CoefficientSpectrum::operator*( float c ) const{
	CoefficientSpectrum toReturn( m_dim );
	for( int i = 0; i < m_dim; i++ ){
		toReturn.m_v[i] = this->m_v[i] * c;
	}
	return toReturn;
}
Exemplo n.º 11
0
Point3D Shot::getWallIntersectionPoint(BoundingWall* wall) {
    if (!isBeam) {
        return Object3D::getWallIntersectionPoint(wall);
    }

    Point3D toReturn(*position);
    Point3D pointOnPlane = wall->normal.scalarMultiply(-wall->wallSize);

    // Calculate intersection between beam and wall.
    Vector3D normalizedDirection = velocity->getNormalized();
    Vector3D wallNormal = wall->normal.scalarMultiply(-1); // To make it face away from the center.
    double rayDotNormal = normalizedDirection.dot(wallNormal);
    if (rayDotNormal <= 0) {
        wall->actuallyHit = false;
        return toReturn;
    }

    Vector3D rayOriginToPointOnPlane(*position, pointOnPlane);

    double distance = rayOriginToPointOnPlane.dot(wallNormal) / rayDotNormal;
    if (distance < 0) {
        wall->actuallyHit = false;
        return toReturn;
    }

    toReturn.addUpdate(normalizedDirection.scalarMultiply(distance));
    return toReturn;
}
Exemplo n.º 12
0
    // Prints out short options with a leading '-' and long ones with '--'.
    // Puts a ',' between them if it has both.
 string CommandOption::getFullOptionString() const
 {
    string toReturn("  ");
    if (shortOpt != 0)
    {
       toReturn += string("-") + string(1, shortOpt);
       if (!longOpt.empty())
       {
          toReturn += string(", --") + longOpt;
          if (optFlag == hasArgument)
             toReturn += "=" + getArgString();
       }
       else
       {
          if (optFlag == hasArgument)
             toReturn += "  " + getArgString();
       }
    }
    else
    {
       toReturn += string("    --") + longOpt;
       if (optFlag == hasArgument)
          toReturn += "=" + getArgString();
    }
    return toReturn;
 }
Exemplo n.º 13
0
// turns a string into its lowercase...
inline std::string tolcstr(const std::string& s)
{
   std::string::size_type i;
   std::string toReturn(s);
   for (i = 0; i < s.size(); i++)
      toReturn[i] = tolower(s[i]);
   return toReturn;
}
CoefficientSpectrum CoefficientSpectrum::operator*( 
	const CoefficientSpectrum &s2 ) const{

	CoefficientSpectrum toReturn( m_dim );
	for( int i = 0; i < m_dim; i++ ){
		toReturn.m_v[i] = this->m_v[i] * s2.m_v[i];
	}
	return toReturn;
}
Exemplo n.º 15
0
 /**
  * \brief Retrieves all the data currently entered in each of the
  * individual widgets and compiles it into a TwoDArray.
  *
  * @return A TwoDArray representing the current values in the
  * idividual widgets.
  */
 TwoDArray<S> getArrayFromWidgets() {
     Teuchos::TwoDArray<QWidget*>::size_type numRows =
         widgetArray.getNumRows()-1;
     Teuchos::TwoDArray<QWidget*>::size_type numCols =
         widgetArray.getNumCols()-1;
     TwoDArray<S> toReturn(
         numRows, numCols);
     int numColsToIterate =0;
     for(int i=0; i<numRows; ++i) {
         numColsToIterate = baseArray.isSymmetrical() ?
                            numCols-numRows+i : numCols;
         for(int j=0; j<numColsToIterate; ++j) {
             toReturn(i,j) = getWidgetValue(i+1,j+1);
         }
     }
     toReturn.setSymmetrical(baseArray.isSymmetrical());
     return toReturn;
 }
Exemplo n.º 16
0
Graph< typename F::node_type, typename F::edge_type > *copy_topology( const Graph<N,E>& originalGraph, F& creator )
{
  // We need to go through all the nodes and edges, using the function to copy them.
  std::auto_ptr< Graph< typename F::node_type, typename F::edge_type > > toReturn( new Graph< typename F::node_type, typename F::edge_type >() );

  hidden_copy_topology( *toReturn, originalGraph, creator );

  return toReturn.release();
}
Exemplo n.º 17
0
CadenaDeBits Tabla::agregarString(string cadena){
	CadenaDeBits toReturn(this->cantidadBitsTabla, this->tabla->size());
	(*this->mapa)[cadena] = (int)this->tabla->size();
	this->tabla->push_back(cadena);
	this->lastCode++;
	int maxValor = (pow(2.0,(int)(this->cantidadBitsTabla)));
	if(this->lastCode >= maxValor){
		this->cantidadBitsTabla++;
	}
	return toReturn;
}
Exemplo n.º 18
0
    // post decrement
    delay_t operator--( int ) {
        delay_t toReturn( *this );

        if ( counter > 1 ) {
            counter -= 1;
        } else {
            counter = 0;
        }

        return toReturn;
    }
Exemplo n.º 19
0
PassOwnPtr<CCActiveAnimation> CCActiveAnimation::cloneForImplThread() const
{
    OwnPtr<CCActiveAnimation> toReturn(adoptPtr(new CCActiveAnimation(m_curve->clone(), m_id, m_group, m_targetProperty)));
    toReturn->m_runState = m_runState;
    toReturn->m_iterations = m_iterations;
    toReturn->m_startTime = m_startTime;
    toReturn->m_pauseTime = m_pauseTime;
    toReturn->m_totalPausedTime = m_totalPausedTime;
    toReturn->m_timeOffset = m_timeOffset;
    return toReturn.release();
}
//----------------------------------------------------------------------------------------
// ConvertSpreadInnerToPageInner
//----------------------------------------------------------------------------------------
PMRect
CZExpPageItemUtils::ConvertSpreadInnerToPageInner(
	const IGeometry *			inPageGeometry,
	const PMRect &				inRectOnSpread) const
{
	PMRect toReturn(inRectOnSpread);

	TransformParentRectToInner( inPageGeometry, &toReturn );

	return toReturn;
}
Exemplo n.º 21
0
Matrix<int> zeroCrossing(Matrix<double> M){
    Matrix<int> toReturn(M.getXdim(), M.getYdim());
    for(unsigned int i=0; i<M.getXdim()-1;++i)
        for(unsigned int j=0; j<M.getYdim()-1;++j){
            double nx = M(i+1, j);//this->p[i+1][j];
            double ny = M(i, j+1);//this->p[i][j+1];
            double current = M(i,j);//this->p[i][j];
            if((nx>0 && current<0) || (nx<0 && current>0) || (nx==0 && current>0) || (nx>0 && current==0)){
                if(fabs(nx)<fabs(current))
                    toReturn(i+1,j) = 1;//m.p[i+1][j] = 1;
                else
                    toReturn(i,j) = 1;//m.p[i][j] = 1;
            }
            if((ny>0 && current<0) || (ny<0 && current>0) || (ny==0 && current>0) || (ny>0 && current ==0)){
                if(fabs(ny)<fabs(current))
                    toReturn(i, j+1) = 1;//m.p[i][j+1] = 1;
                else
                    toReturn(i, j) = 1;//m.p[i][j] = 1;
            }
        }
    return toReturn;
}
Exemplo n.º 22
0
inline std::string ReadStringFromBuffer(const IReadBuffer &buf)
{
  NTA_Byte *value = 0;
  NTA_UInt32 size = 0;
  NTA_Int32 result = buf.readString(value, size, 
      _ReadString_alloc, _ReadString_dealloc); 
  if(result != 0)
    throw std::runtime_error("Failed to read string from stream.");
  std::string toReturn(value, size);
  // Real fps must be provided to use delete here.
  delete[] value;
  return toReturn;
}
Exemplo n.º 23
0
PassOwnPtr<CCActiveAnimation> CCActiveAnimation::cloneAndInitialize(InstanceType instanceType, RunState initialRunState, double startTime) const
{
    OwnPtr<CCActiveAnimation> toReturn(adoptPtr(new CCActiveAnimation(m_curve->clone(), m_id, m_group, m_targetProperty)));
    toReturn->m_runState = initialRunState;
    toReturn->m_iterations = m_iterations;
    toReturn->m_startTime = startTime;
    toReturn->m_pauseTime = m_pauseTime;
    toReturn->m_totalPausedTime = m_totalPausedTime;
    toReturn->m_timeOffset = m_timeOffset;
    toReturn->m_alternatesDirection = m_alternatesDirection;
    toReturn->m_isControllingInstance = instanceType == ControllingInstance;
    return toReturn.release();
}
Exemplo n.º 24
0
string getEnvDirPath(cchar *envVarName)
{
    cchar* dir = std::getenv(envVarName);
    if (dir == NULL || dir[0] == 0) {
        CORE_ASSERT_FAIL_P(("Missed environment variable %s", envVarName));
        return "";
    }

    string toReturn(dir);
    if (!STR_HAS_SLASH_AT_END(toReturn)) {
        toReturn += PATH_SEPARATOR;
    }
    return toReturn;
}
std::string lggHunSpell_Wrapper::VEC2CSV(std::vector<std::string> vec)
{
	std::string toReturn("");
	if (vec.size() < 1)
	{
		return toReturn;
	}

	for (int i = 0;i < (int)vec.size() ;i++)
	{
		toReturn += vec[i] + ",";
	}
	return toReturn.erase(toReturn.length()-1);
}
Exemplo n.º 26
0
/*!	\brief		Verify command line parameters.
 *		\details		Trim the parameters' line; remove everything after && or ; to prevent maluse.
 *		\param[in]	in		Original parameters as string
 *		\returns		Modified parameters.
 */
BString		ActivityData::VerifyCommandLineParameters( const BString& in )
{
	BString 	toReturn( in );
	int32		tempInt;
	
	toReturn.Trim();
	
	if ( ( ( tempInt = toReturn.FindFirst( "&&" ) ) != B_ERROR ) ||
		  ( ( tempInt = toReturn.FindFirst( ";" ) ) != B_ERROR ) )
	{
		toReturn.Truncate( tempInt );
	}
	
	return toReturn;
}	// <-- end of function ActivityData::VerifyCommandLineParameters
complex transmissioncom::getFromTransmissionSolver()
{
  	complex toReturn(0,0);
	Message *myMesg=myinterface->getNextInboxMessage();
	const uint8_t* data=myMesg->getData();
	double realPart;
	double imagineryPart;
	memcpy(&realPart,data,sizeof(double));
	memcpy(&imagineryPart,&data[sizeof(double)],sizeof(double));
	toReturn.SetReal(realPart);
	toReturn.SetImag(imagineryPart);
	delete myMesg;

  	return toReturn;
}
Exemplo n.º 28
0
//Refraction formula from Norm's notes...
const Ray Ray::GetRefracted( const glm::vec3& normal, 
	const glm::vec3& hitPt, float matRefrIndex) const{
	
	glm::vec3 incident = hitPt - this->m_start;
	glm::vec3 normalNormal = glm::normalize( normal ); //normalized normal
	incident = glm::normalize( incident );

	//making a BOLD assumption here. If our starting refractive
	//index is the same as the index of the material we hit, then 
	//we started "inside" the material and now we are hitting the other side.
	//ASSUMING no transparent materials inside each other (e.g. a glass of water)
	//then we can set matRefrIndex to 1 (air/vacuum).
	
	//bool isLeavingMat = false;
	//if( m_start_refr_ind < matRefrIndex + RAY_EPSILON && 
		//m_start_refr_ind > matRefrIndex - RAY_EPSILON ){
		//matRefrIndex = 1.0f;
		//isLeavingMat = true;
	//}
	
	if( isInside ){
		matRefrIndex = 1.0f; //air
	}

	float nRatio = this->m_start_refr_ind / matRefrIndex;	

	float critDisc = 1 - nRatio*nRatio*( 1 - 
		(float)pow(glm::dot(normal, incident), 2) );

	
	//NOTE: we are omitting the case where critical angle == incident angle.
	//In practice, it probably won't happen due to floating point. 
	if( critDisc < 0 ) { //critical angle, ray gets reflected	
		//std::cout << "TOTAL INTERNAL REFLECTION" << std::endl;
		Ray toReturn = GetReflected( normal, hitPt ); 
		toReturn.m_start_refr_ind = matRefrIndex;	
		return toReturn;
	} else {
		float nScale = -1 * nRatio * glm::dot(normalNormal, incident) - 
			(float)sqrt(critDisc);
		glm::vec3 transmitDir = nScale * normalNormal + nRatio * incident;
		transmitDir = glm::normalize( transmitDir );
		Ray toReturn( hitPt + 0.001f * transmitDir, transmitDir );
		toReturn.m_start_refr_ind = matRefrIndex;
		toReturn.isInside = !this->isInside;
		return toReturn;
	}
}
Exemplo n.º 29
0
//2D Laplacian 3x3 edge filter (in pixel space, so it's slow)
PGMImage PGMImage::getEdges() {
	PGMImage toReturn(width, height);
	for (int i = 1; i < width - 1; i++) {
		for (int j = 1; j < height - 1; j++) {
			int total = 8 * getPixel(i, j);
			for (int p = -1; p <= 1; p++) {
				for (int q = -1; q <= 1; q++) {
					if (!(p == 0 && q == 0))
						total -= getPixel(i + p, j + q);
				}
			}
			toReturn.setPixel(i, j, (BYTE)total);
		}
	}
	return toReturn;
}
Exemplo n.º 30
0
 User FilesystemData::getUser( string name ) {
     ENTER( "FilesystemData::getUser" );
     
     if( !doesUserExist(name) ) {
         Logger::error() << "No such user";
         throw std::exception();
     }
     
     string serRole;
     Io::initFromFile( getUserPath( name ), serRole );
     
     User toReturn( name, User::roleFromString(serRole) );
     
     EXIT( "FilesystemData::getUser" );
     return toReturn;
 }