本文整理汇总了C++中Roots类的典型用法代码示例。如果您正苦于以下问题:C++ Roots类的具体用法?C++ Roots怎么用?C++ Roots使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Roots类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Root
Root(Roots* roots, Object* obj)
: LinkedList::Node()
, roots_(roots)
, object_(obj)
{
roots_->add(this);
}
示例2: collect
void MarkSweepGC::collect(Roots &roots, CallFrameLocationList& call_frames) {
Object* tmp;
Root* root = static_cast<Root*>(roots.head());
while(root) {
tmp = root->get();
if(tmp->reference_p()) {
saw_object(tmp);
}
root = static_cast<Root*>(root->next());
}
// Walk all the call frames
for(CallFrameLocationList::const_iterator i = call_frames.begin();
i != call_frames.end();
++i) {
CallFrame** loc = *i;
walk_call_frame(*loc);
}
while(!mark_stack_.empty()) {
tmp = mark_stack_.back();
mark_stack_.pop_back();
scan_object(tmp);
}
after_marked();
}
示例3: collect
void MarkSweepGC::collect(Roots &roots) {
Object* tmp;
Root* root = static_cast<Root*>(roots.head());
while(root) {
tmp = root->get();
if(tmp->reference_p()) {
saw_object(tmp);
}
root = static_cast<Root*>(root->next());
}
// Cleanup all weakrefs seen
clean_weakrefs();
// Sweep up the garbage
sweep_objects();
}
示例4: tgtPln
Foam::plane Foam::sweptFaceAreaWeightAMI<SourcePatch, TargetPatch>::getCutPlane
(
const point& p0,
const point& p1,
const vector& n0,
const vector& n1,
const FixedList<point, 3>& tgtTri
) const
{
// The target plane
const plane tgtPln(tgtTri[0], tgtTri[1], tgtTri[2]);
const point& pp = tgtPln.refPoint();
const vector& np = tgtPln.normal();
// Calculate the bounding intersection points. These are the locations at
// which the bounding lines of the projected surface intersect with the
// target plane.
const scalar v0 = ((pp - p0) & np)/(n0 & np);
const scalar v1 = ((pp - p1) & np)/(n1 & np);
Pair<point> cutPnts(p0 + v0*n0, p1 + v1*n1);
Pair<vector> cutNrms((p1 - p0 + n1*v0) ^ n0, (p1 - p0 - n0*v1) ^ n1);
// Calculate edge intersections with the surface
for (label i = 0; i < 3; ++ i)
{
// The current target edge
const point& l0 = tgtTri[i], l1 = tgtTri[(i + 1)%3];
// Form the quadratic in the surface parameter u
const vector k = l0 - p0;
const vector a = l0 - l1, b = p1 - p0, c = n0, d = n1 - n0;
const vector ka = k ^ a, ba = b ^ a, ca = c ^ a, da = d ^ a;
const scalar A = d & ba;
const scalar B = (c & ba) - (d & ka);
const scalar C = - c & ka;
// Solve and extract the other parameters
const Roots<2> us = quadraticEqn(A, B, C).roots();
Pair<scalar> vs, ws;
Pair<vector> ns;
Pair<bool> cuts(false, false);
for (label j = 0; j < 2; ++ j)
{
if (us.type(j) == rootType::real)
{
const vector den = ca + da*us[j];
if (magSqr(den) > vSmall)
{
const vector vNum = ka - ba*us[j];
const vector wNum = (- k + b*us[j]) ^ (c + d*us[j]);
vs[j] = (vNum & den)/magSqr(den);
ws[j] = (wNum & den)/magSqr(den);
ns[j] = (b ^ (c + d*us[j])) + (n1 ^ n0)*vs[j];
const bool cutu = 0 < us[j] && us[j] < 1;
const bool cutw = 0 < ws[j] && ws[j] < 1;
cuts[j] = cutu && cutw;
}
}
}
// If we have just one intersection in bounds then store it in the
// result list based on its direction
if (cuts[0] != cuts[1])
{
const label j = cuts[0] ? 0 : 1;
const scalar na = ns[j] & a;
cutPnts[na < 0] = l0 + (l1 - l0)*ws[j];
cutNrms[na < 0] = ns[j];
}
}
// Generate and return the cut plane. If the cut points are not coincident
// then form a plane normal by crossing the displacement between the points
// by the target plane normal. If the points are coincident then use the
// projected surface normal evaluated at the first cut point.
const vector cutDelta = cutPnts[1] - cutPnts[0];
const bool coincident = mag(cutDelta) < minCutRatio_*mag(p1 - p0);
return plane(cutPnts[0], coincident ? cutNrms[0] : np ^ cutDelta);
};
示例5: computeInstantSpeed
// Function to compute the sustainable speed in KM/H from input params and a
// bunch of real world constants.
// Relies upon cubic root finder.
// The bicycle related equations came from http://kreuzotter.de/english/espeed.htm,
// The pressure and density equations came from wikipedia.
double computeInstantSpeed(double weightKG,
double slope,
double altitude, // altitude in meters
double pw, // watts
double crr, // rolling resistance
double Cm, // powertrain loss
double Cd, // coefficient of drag
double A, // frontal area (m2)
double T) // temp in kelvin
{
double vs = 0; // Return value
double sl = slope / 100; // 10% = 0.1
// Compute velocity using equations from http://kreuzotter.de/english/espeed.htm
const double CrV = 0.1; // Coefficient for velocity - dependent dynamic rolling resistance, here approximated with 0.1
double CrVn = CrV * cos(sl); // Coefficient for the dynamic rolling resistance, normalized to road inclination; CrVn = CrV*cos(slope)
const double W = 0; // Windspeed
double Hnn = altitude; // Altitude above sea level (m).
double m = weightKG;
double Rho = AirDensity(Hnn, T);
double Beta = atan(sl);
double cosBeta = cos(Beta);
double sinBeta = sin(Beta);
double Frg = s_g0 * m * (crr * cosBeta + sinBeta);
// Home Rolled cubic solver:
// v^3 + v^2 * 2 * (W + CrVn/(Cd *A*Rho)) + V*(W^2 + (2*Frg/(Cd*A*Rho))) - (2*P)/(Cm*Cd*A*Rho) = 0;
//
// A = 1 (monic)
// B = 2 * (W + CrVn / (Cd*A*Rho))
// C = (W ^ 2 + (2 * Frg / (Cd*A*Rho)))
// D = -(2 * P) / (Cm*Cd*A*Rho)
double CdARho = Cd * A * Rho;
double a = 1;
double b = 2 * (W + CrVn / (CdARho));
double c = (W * W + (2 * Frg / (CdARho)));
double d = -(2 * pw) / (Cm * CdARho);
vs = 0;
{
Roots r = BlinnCubicSolver(a, b, c, d);
// Iterate across roots for one that provides a positive velocity,
// otherwise try and choose a positive one that is closest to zero,
// finally tolerate a negative one thats closest to zero.
for (unsigned u = 0; u < r.resultcount(); u++) {
double t = r.result(u).x / r.result(u).w;
if (vs == 0) vs = t;
else if (vs > 0) {
if (t > 0 && t < vs) vs = t;
} else {
if (t > vs) vs = t;
}
}
}
#if 0
// Now to test we run the equation the other way and compute power needed to sustain computed speed.
// A properly computed v should very closely predict the power needed to sustain that speed.
double testPw = Cm * vs * (Cd * A * Rho / 2 * (vs + W)*(vs + W) + Frg + vs * CrVn);
double delta = fabs(testPw - pw);
#endif
vs *= 3.6; // m/s to km/h.
return vs;
}
示例6: test_collect_young_through_references
void test_collect_young_through_references() {
ObjectMemory& om = *state->memory();
Tuple *obj, *obj2, *obj3;
obj = (Tuple*)util_new_object(om);
obj2 = (Tuple*)util_new_object(om);
obj->field[0] = obj2;
obj2->field[0] = cTrue;
om.write_barrier(obj, obj2);
Root r(roots, obj);
om.collect_young(state, gc_data);
TS_ASSERT(obj->forwarded_p());
TS_ASSERT(obj2->forwarded_p());
Object* new_obj = roots->front()->get();
TS_ASSERT(obj != new_obj);
obj = (Tuple*)new_obj;
TS_ASSERT(om.young_->in_current_p(obj));
obj3 = (Tuple*)obj->field[0];
TS_ASSERT(obj2 != obj3);
TS_ASSERT_EQUALS(obj2->field[0], cTrue);
}
示例7: test_collect_young_promotes_objects
void test_collect_young_promotes_objects() {
ObjectMemory& om = *state->memory();
Object* young;
young = util_new_object(om);
Root r(roots, young);
om.set_young_lifetime(1);
TS_ASSERT_EQUALS(young->age(), 0U);
om.collect_young(state, gc_data);
TS_ASSERT_EQUALS(roots->front()->get()->age(), 1U);
om.collect_young(state, gc_data);
TS_ASSERT(roots->front()->get()->mature_object_p());
}
示例8: test_collect_young_doesnt_move_mature_objects
void test_collect_young_doesnt_move_mature_objects() {
ObjectMemory& om = *state->memory();
Object* obj;
om.large_object_threshold = 10;
obj = util_new_object(om,20);
Root r(roots, obj);
om.collect_young(state, gc_data);
TS_ASSERT_EQUALS(obj, roots->front()->get());
}
示例9: test_collect_young_copies_byte_bodies
void test_collect_young_copies_byte_bodies() {
ObjectMemory& om = *state->memory();
ByteArray* obj;
obj = ByteArray::create(state, 3);
obj->raw_bytes()[0] = 47;
Root r(roots, obj);
om.collect_young(state, gc_data);
obj = (ByteArray*)roots->front()->get();
TS_ASSERT_EQUALS(obj->raw_bytes()[0], static_cast<char>(47));
}
示例10: test_collect_young_uses_forwarding_pointers
void test_collect_young_uses_forwarding_pointers() {
ObjectMemory& om = *state->memory();
Tuple *obj, *obj2;
obj = (Tuple*)util_new_object(om);
obj2 = (Tuple*)util_new_object(om);
obj->field[0] = obj2;
obj->field[1] = obj2;
obj->field[2] = obj2;
om.write_barrier(obj, obj2);
Root r(roots, obj);
om.collect_young(state, gc_data);
obj = (Tuple*)roots->front()->get();
obj2 = (Tuple*)obj->field[0];
TS_ASSERT_EQUALS(obj2, obj->field[1]);
TS_ASSERT_EQUALS(obj2, obj->field[2]);
}
示例11: test_collect_young_stops_at_already_marked_objects
void test_collect_young_stops_at_already_marked_objects() {
ObjectMemory& om = *state->memory();
Tuple *obj, *obj2;
obj = (Tuple*)util_new_object(om);
obj2 = (Tuple*)util_new_object(om);
obj2->field[1] = cTrue;
obj->field[0] = obj2;
obj2->field[0] = obj;
om.write_barrier(obj, obj2);
om.write_barrier(obj2, obj);
Root r(roots, obj);
om.collect_young(state, gc_data);
obj = (Tuple*)roots->front()->get();
obj2 = (Tuple*)obj->field[0];
TS_ASSERT_EQUALS(obj2->field[0], obj);
TS_ASSERT_EQUALS(obj2->field[1], cTrue);
}
示例12:
~Root() {
if(roots_ && object_) roots_->remove(this);
}
示例13:
~Root() {
if(roots_ && object_ && object_ != cUndef) roots_->remove(this);
}