CubitStatus OCCSurface::principal_curvatures( CubitVector const& location, double& curvature_1, double& curvature_2, CubitVector* closest_location ) { BRepAdaptor_Surface asurface(*myTopoDSFace); gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0); double minDist=0.0, u, v; int i; BRepLProp_SLProps SLP(asurface, 2, Precision::PConfusion()); Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation()); if (ext.IsDone() && (ext.NbExt() > 0)) { for ( i = 1 ; i <= ext.NbExt() ; i++ ) { if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) { minDist = p.Distance(ext.Point(i).Value()); newP = ext.Point(i).Value(); ext.Point(i).Parameter(u, v); SLP.SetParameters(u, v); } } } if (closest_location != NULL) *closest_location = CubitVector(newP.X(), newP.Y(), newP.Z()); if (SLP.IsCurvatureDefined()) { curvature_1 = SLP.MinCurvature(); curvature_2 = SLP.MaxCurvature(); } return CUBIT_SUCCESS; }
const Position Game::move(const Position & pos, const ActionType & ac) const { if (isLegal(ac, pos)) { int x, y; x = pos.x; y = pos.y; switch (ac) { case N: x--; break; case NE: y++; x--; break; case E: y++; break; case SE: x++; y++; break; case S: x++; break; case SW: y--; x++; break; case W: y--; break; case NW: y--; x--; break; default: break; } Position newP((unsigned)x, (unsigned)y); return newP; } return pos; }
Litteral& Computer::pop() { pushHistorique(*pileActuelle, true); Pile newP(*pileActuelle); Litteral &res = newP.pop(); pileActuelle = &newP; return res; }
OneD<_T> OneD<_T>::truncateTo(size_t order) const { order = std::min(this->order(), order); OneD<_T> newP(order); for (size_t ii = 0; ii <= order; ++ii) { newP[ii] = (*this)[ii]; } return newP; }
OneD<_T> OneD<_T>::transformInput(const OneD<_T>& gx, double zeroEpsilon) const { OneD<_T> newP(order()); for (size_t ii = 0; ii <= order(); ++ii) { newP += gx.power(ii) * (*this)[ii]; } return newP.truncateToNonZeros(zeroEpsilon); }
//------------------------------------------------------------------------- // Purpose : Computes the closest_point on the surface to the input // location. Optionally, it also computes and returns // the normal to the surface at closest_location and the // principal curvatures(1-min, 2-max) // //------------------------------------------------------------------------- CubitStatus OCCSurface::closest_point( CubitVector const& location, CubitVector* closest_location, CubitVector* unit_normal_ptr, CubitVector* curvature_1, CubitVector* curvature_2) { BRepAdaptor_Surface asurface(*myTopoDSFace); gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0); double minDist=0.0, u, v; int i; BRepLProp_SLProps SLP(asurface, 2, Precision::PConfusion()); Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation()); if (ext.IsDone() && (ext.NbExt() > 0)) { for ( i = 1 ; i <= ext.NbExt() ; i++ ) { if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) { minDist = p.Distance(ext.Point(i).Value()); newP = ext.Point(i).Value(); ext.Point(i).Parameter(u, v); SLP.SetParameters(u, v); } } if (closest_location != NULL) *closest_location = CubitVector(newP.X(), newP.Y(), newP.Z()); if (unit_normal_ptr != NULL) { gp_Dir normal; //normal of a RefFace point to outside of the material if (SLP.IsNormalDefined()) { normal = SLP.Normal(); CubitSense sense = get_geometry_sense(); if(sense == CUBIT_REVERSED) normal.Reverse() ; *unit_normal_ptr = CubitVector(normal.X(), normal.Y(), normal.Z()); } } gp_Dir MaxD, MinD; if (SLP.IsCurvatureDefined()) { SLP.CurvatureDirections(MaxD, MinD); if (curvature_1 != NULL) *curvature_1 = CubitVector(MinD.X(), MinD.Y(), MinD.Z()); if (curvature_2 != NULL) *curvature_2 = CubitVector(MaxD.X(), MaxD.Y(), MaxD.Z()); } } return CUBIT_SUCCESS; }
std::vector<gmtl::Point3f> rPoints(std::vector<gmtl::Point3f> start, int nm, int np, char rot) { std::vector<gmtl::Point3f> verts; for (int i = 0; i <= nm; i++) //nm must be at least 3 to get 4 rotations { GLfloat phi = 2 * pi * GLfloat(i) / GLfloat(nm); for (int j = 0; j < np; j++) //np times { gmtl::Point3f oldP = start.at(j); GLfloat x = oldP[0]; GLfloat y = oldP[1]; GLfloat z = oldP[2]; GLfloat newX; GLfloat newY; GLfloat newZ; GLfloat c = cos(phi); GLfloat s = sin(phi); switch (rot) { case 'y': newX = x * c + z * s; newY = y; newZ = z * c - x * s; break; case 'x': newX = x * c - y * s; newY = x * s + y * c; newZ = z; break; case 'z': newX = x; newY = y * c + z * s; newZ = -y * s + z * c; break; } gmtl::Point3f newP(newX, newY, newZ); verts.push_back(newP); } } return verts; }
//------------------------------------------------------------------------- // Purpose : Computes the closest_point on the trimmed surface to the // input location. // // Special Notes : //------------------------------------------------------------------------- void OCCSurface::closest_point_trimmed( CubitVector from_point, CubitVector& point_on_surface) { BRepAdaptor_Surface asurface(*myTopoDSFace); gp_Pnt p(from_point.x(), from_point.y(), from_point.z()), newP(0.0, 0.0, 0.0); double minDist=0.0; int i; Extrema_ExtPS ext(p, asurface, Precision::Approximation(), Precision::Approximation()); if (ext.IsDone() && (ext.NbExt() > 0)) { for ( i = 1 ; i <= ext.NbExt() ; i++ ) { if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) { minDist = p.Distance(ext.Point(i).Value()); newP = ext.Point(i).Value(); } } } point_on_surface = CubitVector(newP.X(), newP.Y(), newP.Z()); }
//------------------------------------------------------------------------- // Purpose : This function returns the {u, v} coordinates of the point // on the Surface closest to the input point (specified in // global space). The closest_location is also returned. // // Special Notes : // //------------------------------------------------------------------------- CubitStatus OCCSurface::u_v_from_position( CubitVector const& location, double& u, double& v, CubitVector* closest_location ) { BRepAdaptor_Surface asurface(*myTopoDSFace); Handle(Geom_Surface) surface = BRep_Tool::Surface(*myTopoDSFace); gp_Pnt p(location.x(), location.y(), location.z()), newP(0.0, 0.0, 0.0); GeomAPI_ProjectPointOnSurf projection( p, surface); if(projection.NbPoints() > 0) { if(projection.LowerDistance() < Precision::Confusion() ) { projection.LowerDistanceParameters(u, v); return CUBIT_SUCCESS; } } double minDist=0.0; int i; Extrema_ExtPS ext(p, asurface, Precision::Confusion(), Precision::Confusion()); if (ext.IsDone() && (ext.NbExt() > 0)) { for ( i = 1 ; i <= ext.NbExt() ; i++ ) { if ( (i==1) || (p.Distance(ext.Point(i).Value()) < minDist) ) { minDist = p.Distance(ext.Point(i).Value()); newP = ext.Point(i).Value(); ext.Point(i).Parameter(u, v); } } } if (closest_location != NULL) *closest_location = CubitVector(newP.X(), newP.Y(), newP.Z()); if (ext.IsDone() && (ext.NbExt() > 0)) return CUBIT_SUCCESS; Handle(ShapeAnalysis_Surface) su = new ShapeAnalysis_Surface(surface); gp_Pnt2d suval = su->ValueOfUV(p, BRep_Tool::Tolerance(*myTopoDSFace)); suval.Coord(u, v); return CUBIT_SUCCESS; }
bool Game::isLegal(const ActionType & ac, const Position & pos) const { int x, y; x = pos.x; y = pos.y; switch (ac) { case N: x--; break; case NE: y++; x--; break; case E: y++; break; case SE: x++; y++; break; case S: x++; break; case SW: y--; x++; break; case W: y--; break; case NW: y--; x--; break; default: break; } Position newP((unsigned)x, (unsigned)y); if (newP.x < __height &&newP.y < __width) { return true; } else { return false; } }
/** Separate local from non-local potentials * @param angList angular momentum list * @param vnn semilocal tables of size (angList.size(),global_grid->size()) * @param rmax cutoff radius * @param Vprefactor conversion factor to Hartree */ void ECPComponentBuilder::doBreakUp(const vector<int>& angList, const Matrix<RealType>& vnn, RealType rmax, RealType Vprefactor) { app_log() << " Creating a Linear Grid Rmax=" << rmax << endl; //this is a new grid RealType d=1e-4; LinearGrid<RealType>* agrid = new LinearGrid<RealType>; // If the global grid is already linear, do not interpolate the data int ng; if (grid_global->getGridTag() == LINEAR_1DGRID) { ng = (int)std::ceil(rmax/grid_global->Delta) + 1; app_log() << " Using global grid with delta = " << grid_global->Delta << endl; rmax = grid_global->Delta * (ng-1); agrid->set(0.0,rmax,ng); // fprintf (stderr, " grid_global delta = %1.10e agrid delta = %1.12e\n", // grid_global->Delta, agrid->Delta); } else { ng=static_cast<int>(rmax/d)+1; agrid->set(0,rmax,ng); } // This is critical!!! // If d is not reset, we generate an error in the interpolated PP! d = agrid->Delta; int ngIn=vnn.cols()-2; if (Llocal == -1 && Lmax > 0) { app_error() << "The local channel is not specified in the pseudopotential file.\n" << "Please add \'l-local=\"n\"\' attribute the semilocal section of the fsatom XML file.\n"; APP_ABORT("ECPComponentBuilder::doBreakUp"); // Llocal = Lmax; } //find the index of local int iLlocal=-1; for(int l=0; l<angList.size(); l++) if(angList[l] == Llocal) iLlocal=l; vector<RealType> newP(ng),newPin(ngIn); for(int l=0; l<angList.size(); l++) { if(angList[l] == Llocal) continue; const RealType* restrict vp=vnn[angList[l]]; const RealType* restrict vpLoc=vnn[iLlocal]; int ll=angList[l]; for(int i=0; i<ngIn; i++) newPin[i]=Vprefactor*(vp[i]-vpLoc[i]); OneDimCubicSpline<RealType> infunc(grid_global,newPin); infunc.spline(0,0.0,ngIn-1,0.0); RealType r=d; for(int i=1; i<ng-1; i++) { newP[i]=infunc.splint(r)/r; r+=d; } newP[0]=newP[1]; newP[ng-1]=0.0; RadialPotentialType *app = new RadialPotentialType(agrid,newP); app->spline(); pp_nonloc->add(angList[l],app); } NumNonLocal=Lmax; if (Llocal == Lmax) Lmax--; if(NumNonLocal) { pp_nonloc->lmax=Lmax; pp_nonloc->Rmax=rmax; } else { //only one component, remove non-local potentials delete pp_nonloc; pp_nonloc=0; } { app_log() << " Making L=" << Llocal << " a local potential." << endl; newPin[0]=0.0; RealType vfac=-Vprefactor/Zeff; const RealType* restrict vpLoc=vnn[iLlocal]; for(int i=0; i<ngIn; i++) newPin[i]=vfac*vpLoc[i]; OneDimCubicSpline<RealType> infunc(grid_global,newPin); infunc.spline(0,0.0,ngIn-1,0.0); RealType r=d; for(int i=1; i<ng-1; i++) { newP[i]=infunc.splint(r); r+=d; } // FIX! //newP[0]=newP[1]; newP[0]=0.0; newP[ng-1]=1.0; pp_loc = new RadialPotentialType(agrid,newP); pp_loc->spline(); // for (double r=0.0; r<3.50001; r+=0.001) // fprintf (stderr, "%10.5f %10.5f\n", r, pp_loc->splint(r)); } }
void LocalizationManager::InitParticles(double x, double y, Map* map) { for (int p = 0; p < PARTICLES_QTY; p++) { Particle newP(x, y, map); _particleVector.push_back(newP); } }
bool PNS_DIFF_PAIR_PLACER::FixRoute( const VECTOR2I& aP, PNS_ITEM* aEndItem ) { if( !m_fitOk ) return false; if( m_currentTrace.CP().SegmentCount() < 1 || m_currentTrace.CN().SegmentCount() < 1 ) return false; if( m_currentTrace.CP().SegmentCount() > 1 ) m_initialDiagonal = !DIRECTION_45( m_currentTrace.CP().CSegment( -2 ) ).IsDiagonal(); PNS_TOPOLOGY topo( m_lastNode ); if( !m_snapOnTarget && !m_currentTrace.EndsWithVias() ) { SHAPE_LINE_CHAIN newP( m_currentTrace.CP() ); SHAPE_LINE_CHAIN newN( m_currentTrace.CN() ); if( newP.SegmentCount() > 1 && newN.SegmentCount() > 1 ) { newP.Remove( -1, -1 ); newN.Remove( -1, -1 ); } m_currentTrace.SetShape( newP, newN ); } if( m_currentTrace.EndsWithVias() ) { m_lastNode->Add( m_currentTrace.PLine().Via().Clone() ); m_lastNode->Add( m_currentTrace.NLine().Via().Clone() ); m_chainedPlacement = false; } else { m_chainedPlacement = !m_snapOnTarget; } PNS_LINE lineP( m_currentTrace.PLine() ); PNS_LINE lineN( m_currentTrace.NLine() ); m_lastNode->Add( &lineP ); m_lastNode->Add( &lineN ); topo.SimplifyLine( &lineP ); topo.SimplifyLine( &lineN ); m_prevPair = m_currentTrace.EndingPrimitives(); Router()->CommitRouting( m_lastNode ); m_lastNode = NULL; m_placingVia = false; if( m_snapOnTarget ) { m_idle = true; return true; } else { initPlacement(); return false; } }
std::vector<gmtl::Point3f> nPoints(std::vector<gmtl::Point3f> verts, char shape) { std::vector<gmtl::Point3f> _normals; switch (shape) { case 's': for (GLuint i = 0; i < verts.size();) { gmtl::Point3f oldP = verts.at(i); //magnitude given by a^2 + b^2 + c^2 GLfloat oldX = oldP[0]; GLfloat oldY = oldP[1]; GLfloat oldZ = oldP[2]; GLfloat magnitude = sqrt(oldX * oldX + oldY * oldY + oldZ * oldZ); //normalized value given by vert/magnitude GLfloat newX = oldX / magnitude; GLfloat newY = oldY / magnitude; GLfloat newZ = oldZ / magnitude; gmtl::Point3f newP(newX, newY, newZ); _normals.push_back(newP); i++; } break; case 'c': for (GLuint i = 0; i < verts.size();) { gmtl::Point3f oldP = verts.at(i); //magnitude given by a^2 + b^2 + c^2 GLfloat oldX = oldP[0]; GLfloat oldY = oldP[1]; GLfloat oldZ = oldP[2]; GLfloat magnitude = sqrt(oldX * oldX + oldY * oldY + oldZ * oldZ); //normalized value given by vert/magnitude GLfloat newX = oldX / magnitude; GLfloat newY = oldY / magnitude; GLfloat newZ = oldZ / magnitude; gmtl::Point3f newP(newX, newY, newZ); _normals.push_back(newP); i++; } break; case 'a': for (GLuint i = 0; i < verts.size();) { gmtl::Point3f oldP = verts.at(i); //magnitude given by a^2 + b^2 + c^2 GLfloat oldX = oldP[0]; GLfloat oldY = oldP[1]; GLfloat oldZ = oldP[2]; GLfloat magnitude = sqrt(oldX * oldX + oldY * oldY + oldZ * oldZ); //normalized value given by vert/magnitude GLfloat newX = oldX / magnitude; GLfloat newY = oldY / magnitude; GLfloat newZ = oldZ / magnitude; gmtl::Point3f newP(newX, newY, newZ); _normals.push_back(newP); i++; } break; case 'b': for (GLuint i = 0; i < verts.size();) { gmtl::Point3f oldP = verts.at(i); //magnitude given by a^2 + b^2 + c^2 GLfloat oldX = oldP[0]; GLfloat oldY = oldP[1]; GLfloat oldZ = oldP[2]; GLfloat magnitude = sqrt(oldX * oldX + oldY * oldY + oldZ * oldZ); //normalized value given by vert/magnitude GLfloat newX = oldX / magnitude; GLfloat newY = oldY / magnitude; GLfloat newZ = oldZ / magnitude; gmtl::Point3f newP(newX, newY, newZ); _normals.push_back(newP); i++; } break; } return _normals; }