Exemplo n.º 1
0
node* insert(node* start,int n)
{
	if(start==NULL)
	{
		start=(node*)malloc(sizeof(node));
		start->left=NULL;
		start->right=NULL;
		start->num=n;
	}
	else if(start->num > n)
	{
		start->left=insert(start->left,n);
		if((he(start->left)) - (he(start->right))==2)
		{
			if(start->left->num>n)
				start=single_left(start);
			else
				start=double_left(start);
		}
	}
	else if(start->num < n)
	{
		start->right=insert(start->right,n);
		if((he(start->right)) - (he(start->left))==2)
		{
			if(start->right->num < n)
				start=single_right(start);
			else
				start=double_right(start);
		}
	
	}
	start->height=he(start);
	return start;
}
Exemplo n.º 2
0
int he(node* start)
{
	if(start==NULL){
		return -1;
	}
	return (max(he(start->left),he(start->right))+1);
}
Exemplo n.º 3
0
node* single_right(node* start)
{
	node* k;
	k=start->right;
	start->right=k->left;
	k->left=start;
	k->height=he(k);
	start->height=he(start);
	return k;
}
Exemplo n.º 4
0
sample hydrator::
process_sample(const std::string& line, const unsigned int line_number) const {
    std::vector<std::string> tokens;
    boost::split(tokens, line, boost::is_space(), boost::token_compress_on);
    BOOST_LOG_SEV(lg, trace) << "Parsing line with tokens: " << tokens;

    if (tokens.size() < minimum_number_of_fields) {
        BOOST_LOG_SEV(lg, error) << missing_fields << ". Expected: "
                                 << minimum_number_of_fields
                                 << " Actual: " << tokens.size();
        BOOST_THROW_EXCEPTION(hydration_error(missing_fields));
    }

    unsigned int field_number(0);
    try {
        sample r;
        r.number(stoui(tokens[field_number]));

        const auto usi(stoi(tokens[++field_number]));
        r.unparsed_structure_identifier(usi);
        r.structure_identifier(to_structure_identifier_type(usi));

        point p;
        p.x(stod(tokens[++field_number]));
        p.y(stod(tokens[++field_number]));
        p.z(stod(tokens[++field_number]));
        r.position(p);
        r.radius(stod(tokens[++field_number]));

        r.parent(stoi(tokens[++field_number]));
        r.line_number(line_number);
        return r;
    } catch (const std::invalid_argument& e) {
        BOOST_LOG_SEV(lg, error) << "Conversion error. Field " << field_number
                                 << ". Value: '" << tokens[field_number] << "'";

        hydration_error he(invalid_field_value);
        he << error_in_field(field_number);
        throw he;
    } catch (const std::out_of_range& e) {
        BOOST_LOG_SEV(lg, error) << "Conversion error. Field " << field_number
                                 << ". Value: '" << tokens[field_number] << "'";

        hydration_error he(invalid_field_value);
        he << error_in_field(field_number);
        throw he;
    }
}
Exemplo n.º 5
0
void Scene::hidden(Event *ev)
{
	//hidden called by Tween
	//notify HiddenEvent listeners

	HiddenEvent he(this);
	dispatchEvent(&he);
}
Exemplo n.º 6
0
 forAll(heBf, patchi)
 {
     heBf[patchi] == he
     (
         this->p_.boundaryField()[patchi],
         this->T_.boundaryField()[patchi],
         patchi
     );
 }
Exemplo n.º 7
0
void CapsuleShape2DSW::set_data(const Variant& p_data) {

	ERR_FAIL_COND(p_data.get_type()!=Variant::ARRAY && p_data.get_type()!=Variant::VECTOR2);

	if (p_data.get_type()==Variant::ARRAY) {
		Array arr=p_data;
		ERR_FAIL_COND(arr.size()!=2);
		height=arr[0];
		radius=arr[1];
	} else {

		Point2 p = p_data;
		radius=p.x;
		height=p.y;
	}

	Point2 he(radius,height*0.5+radius);
	configure(Rect2(-he,he*2));

}
void Scene_nef_polyhedron_item::compute_normals_and_vertices(void)
{
     int count = 0;
    positions_facets.resize(0);
    positions_points.resize(0);
    color_lines.resize(0);
    color_facets.resize(0);
    color_points.resize(0);
    normals.resize(0);
    positions_lines.resize(0);
    //The Facets
    {
        for(Nef_polyhedron::Halffacet_const_iterator
            f = nef_poly->halffacets_begin (),
            end = nef_poly->halffacets_end();
            f != end; ++f)
        {
            if(f->is_twin()) continue;
            count++;
            Nef_polyhedron::Vector_3 v = f->plane().orthogonal_vector();
            P_traits cdt_traits(v);
            CDT cdt(cdt_traits);

            for(Nef_polyhedron::Halffacet_cycle_const_iterator
                fc = f->facet_cycles_begin(),
                end = f->facet_cycles_end();
                fc != end; ++fc)
            {
                if ( fc.is_shalfedge() )
                {

                    Nef_polyhedron::SHalfedge_const_handle h = fc;
                    Nef_polyhedron::SHalfedge_around_facet_const_circulator hc(h), he(hc);

                    CDT::Vertex_handle previous, first;

                    do {
                        Nef_polyhedron::SVertex_const_handle v = hc->source();
                        const Nef_polyhedron::Point_3& point = v->source()->point();
                        CDT::Vertex_handle vh = cdt.insert(point);
                        if(first == 0) {
                            first = vh;
                        }
                        vh->info() = hc->source();
                        if(previous != 0 && previous != vh) {
                            cdt.insert_constraint(previous, vh);
                        }
                        previous = vh;
                    } while( ++hc != he );

                    cdt.insert_constraint(previous, first);

                    // sets mark is_external
                    for(CDT::All_faces_iterator
                        fit = cdt.all_faces_begin(),
                        end = cdt.all_faces_end();
                        fit != end; ++fit)
                    {
                        fit->info().is_external = false;

                    }
                    //check if the facet is external or internal
                    std::queue<CDT::Face_handle> face_queue;
                    face_queue.push(cdt.infinite_vertex()->face());

                    while(! face_queue.empty() ) {
                        CDT::Face_handle fh = face_queue.front();
                        face_queue.pop();
                        if(fh->info().is_external) continue;
                        fh->info().is_external = true;
                        for(int i = 0; i <3; ++i) {
                            if(!cdt.is_constrained(std::make_pair(fh, i)))
                            {
                                face_queue.push(fh->neighbor(i));
                            }
                        }

                    }
                    //iterates on the internal faces to add the vertices to the positions
                    //and the normals to the appropriate vectors

                    for(CDT::Finite_faces_iterator
                        ffit = cdt.finite_faces_begin(),
                        end = cdt.finite_faces_end();
                        ffit != end; ++ffit)
                    {


                        if(ffit->info().is_external){ continue;}
                        for(int i = 0; i<3; i++)
                        {
                            positions_facets.push_back(CGAL::to_double(ffit->vertex(i)->point().x()));
                            positions_facets.push_back(CGAL::to_double(ffit->vertex(i)->point().y()));
                            positions_facets.push_back(CGAL::to_double(ffit->vertex(i)->point().z()));

                        }



                        Nef_polyhedron::Vector_3 v = f->plane().orthogonal_vector();
                        GLdouble normal[3];
                        normal[0] = CGAL::to_double(v.x());
                        normal[1] = CGAL::to_double(v.y());
                        normal[2] = CGAL::to_double(v.z());
                        GLdouble norm = normal[0]*normal[0]
                                + normal[1]*normal[1]
                                + normal[2]*normal[2];
                        norm = CGAL::sqrt(norm);
                        normal[0] /= norm;
                        normal[1] /= norm;
                        normal[2] /= norm;

                        normals.push_back(normal[0]);
                        normals.push_back(normal[1]);
                        normals.push_back(normal[2]);

                        normals.push_back(normal[0]);
                        normals.push_back(normal[1]);
                        normals.push_back(normal[2]);

                        normals.push_back(normal[0]);
                        normals.push_back(normal[1]);
                        normals.push_back(normal[2]);

                        if(is_selected)
                        {
                            color_facets.push_back(this->color().lighter(120).redF());
                            color_facets.push_back(this->color().lighter(120).greenF());
                            color_facets.push_back(this->color().lighter(120).blueF());

                            color_facets.push_back(this->color().lighter(120).redF());
                            color_facets.push_back(this->color().lighter(120).greenF());
                            color_facets.push_back(this->color().lighter(120).blueF());

                            color_facets.push_back(this->color().lighter(120).redF());
                            color_facets.push_back(this->color().lighter(120).greenF());
                            color_facets.push_back(this->color().lighter(120).blueF());
                        }
                        else
                        {
                            color_facets.push_back(this->color().redF());
                            color_facets.push_back(this->color().greenF());
                            color_facets.push_back(this->color().blueF());

                            color_facets.push_back(this->color().redF());
                            color_facets.push_back(this->color().greenF());
                            color_facets.push_back(this->color().blueF());

                            color_facets.push_back(this->color().redF());
                            color_facets.push_back(this->color().greenF());
                            color_facets.push_back(this->color().blueF());

                        }

                    }
                }
            }
        }

    } // end facets

    //The Lines
    {
       for(Nef_polyhedron::Halfedge_const_iterator
            e = nef_poly->halfedges_begin(),
            end = nef_poly->halfedges_end();
            e != end; ++e)
        {
            if (e->is_twin()) continue;
            const Nef_polyhedron::Vertex_const_handle& s = e->source();
            const Nef_polyhedron::Vertex_const_handle& t = e->twin()->source();
            const Nef_polyhedron::Point_3& a = s->point();
            const Nef_polyhedron::Point_3& b = t->point();

            positions_lines.push_back(CGAL::to_double(a.x()));
            positions_lines.push_back(CGAL::to_double(a.y()));
            positions_lines.push_back(CGAL::to_double(a.z()));

            positions_lines.push_back(CGAL::to_double(b.x()));
            positions_lines.push_back(CGAL::to_double(b.y()));
            positions_lines.push_back(CGAL::to_double(b.z()));

            if(is_selected)
            {
                color_lines.push_back(this->color().lighter(50).redF());
                color_lines.push_back(this->color().lighter(50).greenF());
                color_lines.push_back(this->color().lighter(50).blueF());

                color_lines.push_back(this->color().lighter(50).redF());
                color_lines.push_back(this->color().lighter(50).greenF());
                color_lines.push_back(this->color().lighter(50).blueF());
            }
            else
            {
                color_lines.push_back(0.0);
                color_lines.push_back(0.0);
                color_lines.push_back(0.0);

                color_lines.push_back(0.0);
                color_lines.push_back(0.0);
                color_lines.push_back(0.0);
            }
        }
    }
    //The points
    {
        for(Nef_polyhedron::Vertex_const_iterator
            v = nef_poly->vertices_begin(),
            end = nef_poly->vertices_end();
            v != end; ++v)
        {
            const Nef_polyhedron::Point_3& p = v->point();
            positions_points.push_back(CGAL::to_double(p.x()));
            positions_points.push_back(CGAL::to_double(p.y()));
            positions_points.push_back(CGAL::to_double(p.z()));

                color_points.push_back(this->color().lighter(50).redF());
                color_points.push_back(this->color().lighter(50).greenF());
                color_points.push_back(this->color().lighter(50).blueF());

                color_points.push_back(this->color().lighter(50).redF());
                color_points.push_back(this->color().lighter(50).greenF());
                color_points.push_back(this->color().lighter(50).blueF());

        }

    } //end points
}
Exemplo n.º 9
0
MStatus updateTCCDataFty::remapMeshData(MFnMesh &meshFn)
{
    MIntArray o_nFV, o_F;
    meshFn.getVertices(o_nFV, o_F);
    size_t o_nF  = o_nFV.length();
    size_t o_nHE = o_F.length();
    size_t o_nV  = meshFn.numVertices();

    MIntArray o_F2H(o_nF); // maps face index to halfedge index
    {
        size_t kS=0;
        for (size_t k=0; k<o_nF; k++)
        {
            o_F2H[k] = kS;
            kS+=o_nFV[k];
        }
    }

    size_t nF  = fPolyOrder.length();
    size_t nHE = compute_nHE(fPolyOrder, o_nFV, fDelta_nFV);
    size_t nV  = fnV;

    HalfedgeData he(o_nHE, nHE);
    VertexData   v(o_nV, nV);

    MFloatPointArray V(nV);
    MIntArray nFV(nF);
    MIntArray F(nHE);

    get_vertex_blindData(meshFn, v);
    get_halfedge_blindData(meshFn, he);

    // add old/new faces in the order given by fPolyOrder and remap their halfedge data (if exists)

    size_t delta_kF = 0, delta_kHE=0;
    size_t kF = 0, kHE = 0;
    for (size_t k=0; k<fPolyOrder.length(); k++)
    {
        if (fPolyOrder[k]>=0)
        {
            size_t cF = fPolyOrder[k], cnFV = o_nFV[cF];

            size_t o_cF2H = o_F2H[cF];
            size_t cShift = fCShift[cF];
            for (size_t kFV=0; kFV<cnFV; kFV++)
            {
                size_t o_kHE = o_cF2H + ((kFV + cShift) % cnFV);

                F[kHE] = fVtxRemap[o_F[o_kHE]];

                remap_HalfedgeData(he, o_kHE, kHE);

                kHE++;
            }

            nFV[kF] = cnFV;
            kF++;
        }
        else // this is a new face
        {
            size_t cnFV = fDelta_nFV[delta_kF];
            delta_kF++;
            for (size_t kFV=0; kFV<cnFV; kFV++)
            {
                F[kHE] = fDelta_F[delta_kHE];

                kHE++;
                delta_kHE++;
            }
            nFV[kF] = cnFV;
            kF++;
        }
    }

    // remap vertex data
    for (size_t k=0; k<o_nV; k++)
    {
        if (fVtxRemap[k]>=0)
        {
            remap_VertexData(v, k, fVtxRemap[k]);
        }
    }

    MStatus stat = meshFn.createInPlace(nV, nF, V, nFV, F);
    if (stat != MS::kSuccess)
    {
        std::cerr<<"createInPlace failed"<<endl;
        std::cerr<<stat.errorString()<<endl;
    }


    update_tags(nFV, F, v, he);

    set_vertex_blindData(meshFn, v);
    set_halfedge_blindData(meshFn, he);

    return stat;
}
Exemplo n.º 10
0
static PyObject *
SigningKey__dump(SigningKey *self, PyObject *dummy) {
    const DL_GroupParameters_EC<ECP>& gp = self->k->GetKey().GetGroupParameters();
    std::cout << "whee " << gp.GetEncodedElementSize(true) << "\a";
    std::cout << "booo " << gp.GetEncodedElementSize(false) << "\n";

    ECPPoint p = gp.GetSubgroupGenerator();
    std::cout << "generator " << p.x << ", " << p.y << "\n";

    std::cout << "GroupOrder: ";
    std::cout << gp.GetGroupOrder();
    std::cout << "\n";

    std::string s;
    StringSink* ss = new StringSink(s);
    HexEncoder he(ss);
    std::cout << "AlgorithmID: ";
    gp.GetAlgorithmID().DEREncode(he);
    std::cout << s << "\n";

    const ECP& ec = gp.GetCurve();
    Integer fieldsize = ec.FieldSize();
    std::cout << "field size " << fieldsize.BitCount() << " " << fieldsize.ByteCount() << " " << ec.FieldSize() << "\n";
    std::cout << "Curve: ";
    std::cout << "curve field max element bit length: " << ec.GetField().MaxElementBitLength() << "\n";
    std::cout << "curve field modulus: " << ec.GetField().GetModulus() << "\n";
    std::cout << "curve A: " << ec.GetA() << ", curve B: " << ec.GetB();

    const ECP::Field& f = ec.GetField();
    std::cout << "curve field modulus: " << f.GetModulus() << "\n";
    std::cout << "curve field identity: " << f.Identity() << "\n";

    std::string cfs;
    StringSink* cfss = new StringSink(cfs);
    HexEncoder cfhe(cfss);
    f.DEREncode(cfhe);
    std::cout << "curve field derencoding: " << cfs << "\n";

    const CryptoMaterial& cm = self->k->GetMaterial();
    Integer i;
    cm.GetValue("SubgroupOrder", i);
    std::cout << "\n";
    std::cout << "SubgroupOrder: ";
    std::cout << i;
    std::cout << "\n";
    ECP::Element e;
    cm.GetValue("SubgroupGenerator", e);
    std::cout << "SubgroupGenerator: ";
    std::cout << e.x << ", " << e.y;
    std::cout << "\n";

    std::cout << "private key: ";

    const PrivateKey& privkey = self->k->GetPrivateKey();

    std::cout << privkey.GetValueNames() << "\n";

    Integer privi;
    privkey.GetValue("PrivateExponent", privi);
    std::cout << privi << "\n";
    std::cout << "numbits: " << privi.BitCount() << "\n";
    std::cout << "numbytes: " << privi.ByteCount() << "\n";

    Py_RETURN_NONE;
}
Exemplo n.º 11
0
int main()
{
	printf("the answer is : %lld\n",he(1777,1855));
	return 0;
}
Exemplo n.º 12
0
ll he(ll a,ll b)
{
	if(b==1)
		return a%MOD;
	return power(a,he(a,b-1));
}
Exemplo n.º 13
0
static void _collision_rectangle_capsule(const Shape2DSW* p_a,const Matrix32& p_transform_a,const Shape2DSW* p_b,const Matrix32& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b) {

	const RectangleShape2DSW *rectangle_A = static_cast<const RectangleShape2DSW*>(p_a);
	const CapsuleShape2DSW *capsule_B = static_cast<const CapsuleShape2DSW*>(p_b);


	SeparatorAxisTest2D<RectangleShape2DSW,CapsuleShape2DSW,castA,castB> separator(rectangle_A,p_transform_a,capsule_B,p_transform_b,p_collector,p_motion_a,p_motion_b);

	if (!separator.test_previous_axis())
		return;

	if (!separator.test_cast())
		return;

	//box faces
	if (!separator.test_axis(p_transform_a.elements[0].normalized()))
		return;

	if (!separator.test_axis(p_transform_a.elements[1].normalized()))
		return;

	//capsule axis
	if (!separator.test_axis(p_transform_b.elements[0].normalized()))
		return;


	//box endpoints to capsule circles

	Matrix32 boxinv = p_transform_a.affine_inverse();

	for(int i=0;i<2;i++) {

		{
			Vector2 capsule_endpoint = p_transform_b.get_origin()+p_transform_b.elements[1]*capsule_B->get_height()*(i==0?0.5:-0.5);

			const Vector2& half_extents = rectangle_A->get_half_extents();
			Vector2 local_v = boxinv.xform(capsule_endpoint);

			Vector2 he(
				(local_v.x<0) ? -half_extents.x : half_extents.x,
				(local_v.y<0) ? -half_extents.y : half_extents.y
			);

			if (!separator.test_axis(p_transform_a.xform(he-capsule_endpoint).normalized()))
				return;
		}


		if (castA) {
			Vector2 capsule_endpoint = p_transform_b.get_origin()+p_transform_b.elements[1]*capsule_B->get_height()*(i==0?0.5:-0.5);
			capsule_endpoint-=p_motion_a;


			const Vector2& half_extents = rectangle_A->get_half_extents();
			Vector2 local_v = boxinv.xform(capsule_endpoint);

			Vector2 he(
				(local_v.x<0) ? -half_extents.x : half_extents.x,
				(local_v.y<0) ? -half_extents.y : half_extents.y
			);

			if (!separator.test_axis(p_transform_a.xform(he-capsule_endpoint).normalized()))
				return;
		}

		if (castB) {
			Vector2 capsule_endpoint = p_transform_b.get_origin()+p_transform_b.elements[1]*capsule_B->get_height()*(i==0?0.5:-0.5);
			capsule_endpoint+=p_motion_b;


			const Vector2& half_extents = rectangle_A->get_half_extents();
			Vector2 local_v = boxinv.xform(capsule_endpoint);

			Vector2 he(
				(local_v.x<0) ? -half_extents.x : half_extents.x,
				(local_v.y<0) ? -half_extents.y : half_extents.y
			);

			if (!separator.test_axis(p_transform_a.xform(he-capsule_endpoint).normalized()))
				return;
		}

		if (castA && castB) {
			Vector2 capsule_endpoint = p_transform_b.get_origin()+p_transform_b.elements[1]*capsule_B->get_height()*(i==0?0.5:-0.5);
			capsule_endpoint-=p_motion_a;
			capsule_endpoint+=p_motion_b;


			const Vector2& half_extents = rectangle_A->get_half_extents();
			Vector2 local_v = boxinv.xform(capsule_endpoint);

			Vector2 he(
				(local_v.x<0) ? -half_extents.x : half_extents.x,
				(local_v.y<0) ? -half_extents.y : half_extents.y
			);

			if (!separator.test_axis(p_transform_a.xform(he-capsule_endpoint).normalized()))
				return;
		}

	}


	separator.generate_contacts();
}
Exemplo n.º 14
0
static void _collision_circle_rectangle(const Shape2DSW* p_a,const Matrix32& p_transform_a,const Shape2DSW* p_b,const Matrix32& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b) {

	const CircleShape2DSW *circle_A = static_cast<const CircleShape2DSW*>(p_a);
	const RectangleShape2DSW *rectangle_B = static_cast<const RectangleShape2DSW*>(p_b);


	SeparatorAxisTest2D<CircleShape2DSW,RectangleShape2DSW,castA,castB> separator(circle_A,p_transform_a,rectangle_B,p_transform_b,p_collector,p_motion_a,p_motion_b);

	if (!separator.test_previous_axis())
		return;

	if (!separator.test_cast())
		return;

	const Vector2 &sphere=p_transform_a.elements[2];
	const Vector2 *axis=&p_transform_b.elements[0];
	const Vector2& half_extents = rectangle_B->get_half_extents();

	if (!separator.test_axis(axis[0].normalized()))
		return;

	if (!separator.test_axis(axis[1].normalized()))
		return;

	{
		Vector2 local_v = p_transform_b.affine_inverse().xform(p_transform_a.get_origin());

		Vector2 he(
			(local_v.x<0) ? -half_extents.x : half_extents.x,
			(local_v.y<0) ? -half_extents.y : half_extents.y
		);


		if (!separator.test_axis((p_transform_b.xform(he)-sphere).normalized()))
			return;
	}

	if (castA) {

		Vector2 sphereofs = sphere + p_motion_a;
		Vector2 local_v = p_transform_b.affine_inverse().xform(sphereofs);

		Vector2 he(
			(local_v.x<0) ? -half_extents.x : half_extents.x,
			(local_v.y<0) ? -half_extents.y : half_extents.y
		);


		if (!separator.test_axis((p_transform_b.xform(he)-sphereofs).normalized()))
			return;
	}

	if (castB) {

		Vector2 sphereofs = sphere - p_motion_b;
		Vector2 local_v = p_transform_b.affine_inverse().xform(sphereofs);

		Vector2 he(
			(local_v.x<0) ? -half_extents.x : half_extents.x,
			(local_v.y<0) ? -half_extents.y : half_extents.y
		);


		if (!separator.test_axis((p_transform_b.xform(he)-sphereofs).normalized()))
			return;
	}

	if (castA && castB) {

		Vector2 sphereofs = sphere - p_motion_b + p_motion_a;
		Vector2 local_v = p_transform_b.affine_inverse().xform(sphereofs);

		Vector2 he(
			(local_v.x<0) ? -half_extents.x : half_extents.x,
			(local_v.y<0) ? -half_extents.y : half_extents.y
		);


		if (!separator.test_axis((p_transform_b.xform(he)-sphereofs).normalized()))
			return;
	}

	separator.generate_contacts();
}