void demography :: update() { World.Step(1/5.f, 8, 3); // lb2(int(q)); //auto i=0; //for (auto&a:cellbodies) { pos[i]=a->GetPosition(); ++i; } //vbunk.position(pos); //i=0; // if(!cells.empty()) // for (auto&a:pos) // { // //pos_sf[i]=Vec2(SCALE * a.x,SCALE * a.y); //// cells[i].setPosition(Vec2(SCALE * a.x,SCALE * a.y)); // cells[i].setPosition(conv(a)); //// sensors[i].setPosition(cells[i].getPosition()); // //cells[i].setPosition(a*SCALE); // //sensors[i].setPosition(a*SCALE); // i++; // } for(auto&a:cells) { a.second.setPosition(conv(a.first->GetPosition())); } timer+=1/60.0f; auto&e=ek; //if(timer>1) //{ // int deriv=0; // e.res+=e.n*5; // if(cellbodies.size()>e.n)e.n=cellbodies.size(); // while(e.res>50) // { // e.res-=50; // ++e.n; // add(); // ++deriv; // } // timer = 0; // lb2(deriv); //} lb2(e.n); lb2(e.res); }
void propagate::mouseclick(Vec2 pos,sf::Mouse::Button button, bool release){ auto h = hover.getPosition(); last_click = which; lb2(last_click); //sf::Uint8 a[4] = {128,128,0,128}; //if(click.x>-1 // && click.x<p.pixels // && click.y>-1 // && click.y<p.pixels) // tx.update(a,1,1,click.x,click.y); }
void propagate::step() { //++i; //if(i >= p.pixels) { i = 0; ++j; } //if(j >= p.pixels) go=false; //auto a = iter->first; set<Vec2i>changed; //decltype(spread) increments; for(i = 0; i < p.pixels; ++i) for(j = 0; j < p.pixels; ++j) for(auto&s:surnd) { Vec2i select = s+Vec2i(i,j); if(select.x>-1 && select.x<p.pixels && select.y>-1 && select.y<p.pixels) { float f = incr( Vec2i(i,j),select, spread[i][j], p.raw[select.x][select.y]); //spread[i][j]+=f; spread[select.x][select.y]+=spread_coeff*f; changed.insert(select); } } for(auto&a:changed) { float f = spread[a.x][a.y]; if(f<1) img.setPixel(a.x,a.y,Color(f*255,f*255,f*255,64)); else img.setPixel(a.x,a.y,Color(255,255,255,64)); } tx.loadFromImage(img); spr.setTexture(tx); lb2(i); lb2(j); }
gax:: gax(): ispushed(false), bpk(Vec2(50,50),Vec2(200,100)) { cfg->SET(spiral_step); cfg->SET(spiral_start); bpk.add_bar(varname(spiral_step),&spiral_step); bpk.add_bar(varname(spiral_start),&spiral_start); bpk.add_bar(varname(how_many),&how_many); funs["gal"]=([this]() { lines.clear(); float inner, arms, startmult, stepmult, spiral_resolution; cfg->SET(spiral_resolution); cfg->SET(arms); cfg->SET(inner); cfg->SET(startmult); cfg->SET(stepmult); auto & o = circs["o"], & i = circs["i"]; float rado = wcenter.y*.9, radi = wcenter.y*inner; confpoint(o,rado,Color::Transparent,wcenter,1); confpoint(i,radi,Color::Transparent,wcenter,1); int many = how_many*arms; for(int i = 0; i < many; ++i) { float shift_angle = float(i)*PI*2/float(many); // cons_print(shift_angle); lines["arch"+strfy(i)]=VertexArray(LinesStrip); auto & thisline = lines["arch"+strfy(i)]; for (int i=0; i< spiral_resolution; i++) { float angle = 2*PI*i/float(spiral_resolution); thisline.append(Vertex(Vec2( wcenter.x+(spiral_start*startmult+stepmult*spiral_step*angle) *cos(angle+shift_angle), wcenter.y+(spiral_start*startmult+stepmult*spiral_step*angle) *sin(angle+shift_angle) ))); } } lb2(lines.size()); }); funs["gal"](); }
TEST(BoundingBox, CoordinateSize){ Point lb(1,2,0); Point ub(2,4,0); BoundingBox bb1(lb, ub); EXPECT_EQ(2, bb1.sizeCoordX()); EXPECT_EQ(3, bb1.sizeCoordY()); EXPECT_EQ(1, bb1.sizeCoordZ()); Point lb2(1,2,0); Point ub2(2,4,0); BoundingBox bb2(lb, ub); // Intersection should return an bounding box equal to bb2 and bb1, // they are the same bb BoundingBox bbIntersection = bb2.intersection(bb1); EXPECT_TRUE( bbIntersection.getLb().getX() == bb2.getLb().getX() && bbIntersection.getLb().getY() == bb2.getLb().getY() && bbIntersection.getLb().getZ() == bb2.getLb().getZ()); EXPECT_TRUE( bbIntersection.getUb().getX() == bb2.getUb().getX() && bbIntersection.getUb().getY() == bb2.getUb().getY() && bbIntersection.getUb().getZ() == bb2.getUb().getZ()); Point lb3(2,3,0); Point ub3(2,4,0); BoundingBox bb3(lb3, ub3); bbIntersection = bb2.intersection(bb3); // lower bound is the value of of bb3 EXPECT_TRUE( bbIntersection.getLb().getX() == lb3.getX() && bbIntersection.getLb().getY() == lb3.getY() && bbIntersection.getLb().getZ() == lb3.getZ()); // upper bound should not change EXPECT_TRUE( bbIntersection.getUb().getX() == bb2.getUb().getX() && bbIntersection.getUb().getY() == bb2.getUb().getY() && bbIntersection.getUb().getZ() == bb2.getUb().getZ()); }
TEST(BoundingBox, NoIntersection){ Point lb(1,2,0), ub(2,4,0), lb2(3,5,0), ub2(4,6,0); BoundingBox bb1(lb, ub); BoundingBox bb2(lb2, ub2); // Intersection should return an bounding box equal to bb2 and bb1, // they are the same bb BoundingBox bbInter = bb2.intersection(bb1); EXPECT_FALSE( bb1.doesIntersect(bb2)); // Lower bound of intersection should contain greater values // among lower bound of both bounding boxes (lb2) EXPECT_TRUE( bbInter.getLb().getX() == lb2.getX() && bbInter.getLb().getY() == lb2.getY() && bbInter.getLb().getZ() == lb2.getZ()); // Upper bound of intersection should contain smaller values // among upper bound of both bounding boxes (ub) EXPECT_TRUE( bbInter.getUb().getX() == ub.getX() && bbInter.getUb().getY() == ub.getY() && bbInter.getUb().getZ() == ub.getZ()); }
bool test(bool is_kernel_exact = true) { // types typedef typename K::FT FT; typedef typename K::Line_3 Line; typedef typename K::Point_3 Point; typedef typename K::Segment_3 Segment; typedef typename K::Ray_3 Ray; typedef typename K::Line_3 Line; typedef typename K::Triangle_3 Triangle; /* ------------------------------------- // Test data is something like that (in t supporting plane) // Triangle is (p1,p2,p3) // // +E +1 // / \ // +C 6+ +8 +4 +B // / 9++7 \ // 3+-------+5--+2 // // +F +A ------------------------------------- */ Point p1(FT(1.), FT(0.), FT(0.)); Point p2(FT(0.), FT(1.), FT(0.)); Point p3(FT(0.), FT(0.), FT(1.)); Triangle t(p1,p2,p3); // Edges of t Segment s12(p1,p2); Segment s21(p2,p1); Segment s13(p1,p3); Segment s23(p2,p3); Segment s32(p3,p2); Segment s31(p3,p1); bool b = test_aux(is_kernel_exact,t,s12,"t-s12",s12); b &= test_aux(is_kernel_exact,t,s21,"t-s21",s21); b &= test_aux(is_kernel_exact,t,s13,"t-s13",s13); b &= test_aux(is_kernel_exact,t,s23,"t-s23",s23); // Inside points Point p4(FT(0.5), FT(0.5), FT(0.)); Point p5(FT(0.), FT(0.75), FT(0.25)); Point p6(FT(0.5), FT(0.), FT(0.5)); Point p7(FT(0.25), FT(0.625), FT(0.125)); Point p8(FT(0.5), FT(0.25), FT(0.25)); Segment s14(p1,p4); Segment s41(p4,p1); Segment s24(p2,p4); Segment s42(p4,p2); Segment s15(p1,p5); Segment s25(p2,p5); Segment s34(p3,p4); Segment s35(p3,p5); Segment s36(p3,p6); Segment s45(p4,p5); Segment s16(p1,p6); Segment s26(p2,p6); Segment s62(p6,p2); Segment s46(p4,p6); Segment s48(p4,p8); Segment s56(p5,p6); Segment s65(p6,p5); Segment s64(p6,p4); Segment s17(p1,p7); Segment s67(p6,p7); Segment s68(p6,p8); Segment s86(p8,p6); Segment s78(p7,p8); Segment s87(p8,p7); b &= test_aux(is_kernel_exact,t,s14,"t-s14",s14); b &= test_aux(is_kernel_exact,t,s41,"t-s41",s41); b &= test_aux(is_kernel_exact,t,s24,"t-s24",s24); b &= test_aux(is_kernel_exact,t,s42,"t-s42",s42); b &= test_aux(is_kernel_exact,t,s15,"t-s15",s15); b &= test_aux(is_kernel_exact,t,s25,"t-s25",s25); b &= test_aux(is_kernel_exact,t,s34,"t-s34",s34); b &= test_aux(is_kernel_exact,t,s35,"t-s35",s35); b &= test_aux(is_kernel_exact,t,s36,"t-s36",s36); b &= test_aux(is_kernel_exact,t,s45,"t-s45",s45); b &= test_aux(is_kernel_exact,t,s16,"t-s16",s16); b &= test_aux(is_kernel_exact,t,s26,"t-s26",s26); b &= test_aux(is_kernel_exact,t,s62,"t-s62",s62); b &= test_aux(is_kernel_exact,t,s46,"t-s46",s46); b &= test_aux(is_kernel_exact,t,s65,"t-s65",s65); b &= test_aux(is_kernel_exact,t,s64,"t-s64",s64); b &= test_aux(is_kernel_exact,t,s48,"t-s48",s48); b &= test_aux(is_kernel_exact,t,s56,"t-s56",s56); b &= test_aux(is_kernel_exact,t,s17,"t-t17",s17); b &= test_aux(is_kernel_exact,t,s67,"t-t67",s67); b &= test_aux(is_kernel_exact,t,s68,"t-s68",s68); b &= test_aux(is_kernel_exact,t,s86,"t-s86",s86); b &= test_aux(is_kernel_exact,t,s78,"t-t78",s78); b &= test_aux(is_kernel_exact,t,s87,"t-t87",s87); // Outside points (in triangle plane) Point pA(FT(-0.5), FT(1.), FT(0.5)); Point pB(FT(0.5), FT(1.), FT(-0.5)); Point pC(FT(0.5), FT(-0.5), FT(1.)); Point pE(FT(1.), FT(-1.), FT(1.)); Point pF(FT(-1.), FT(0.), FT(2.)); Segment sAB(pA,pB); Segment sBC(pB,pC); Segment s2E(p2,pE); Segment sE2(pE,p2); Segment s2A(p2,pA); Segment s6E(p6,pE); Segment sB8(pB,p8); Segment sC8(pC,p8); Segment s8C(p8,pC); Segment s1F(p1,pF); Segment sF6(pF,p6); b &= test_aux(is_kernel_exact,t,sAB,"t-sAB",p2); b &= test_aux(is_kernel_exact,t,sBC,"t-sBC",s46); b &= test_aux(is_kernel_exact,t,s2E,"t-s2E",s26); b &= test_aux(is_kernel_exact,t,sE2,"t-sE2",s62); b &= test_aux(is_kernel_exact,t,s2A,"t-s2A",p2); b &= test_aux(is_kernel_exact,t,s6E,"t-s6E",p6); b &= test_aux(is_kernel_exact,t,sB8,"t-sB8",s48); b &= test_aux(is_kernel_exact,t,sC8,"t-sC8",s68); b &= test_aux(is_kernel_exact,t,s8C,"t-s8C",s86); b &= test_aux(is_kernel_exact,t,s1F,"t-s1F",s13); b &= test_aux(is_kernel_exact,t,sF6,"t-sF6",s36); // Outside triangle plane Point pa(FT(0.), FT(0.), FT(0.)); Point pb(FT(2.), FT(0.), FT(0.)); Point pc(FT(1.), FT(0.), FT(1.)); Point pe(FT(1.), FT(0.5), FT(0.5)); Segment sab(pa,pb); Segment sac(pa,pc); Segment sae(pa,pe); Segment sa8(pa,p8); Segment sb2(pb,p2); b &= test_aux(is_kernel_exact,t,sab,"t-sab",p1); b &= test_aux(is_kernel_exact,t,sac,"t-sac",p6); b &= test_aux(is_kernel_exact,t,sae,"t-sae",p8); b &= test_aux(is_kernel_exact,t,sa8,"t-sa8",p8); b &= test_aux(is_kernel_exact,t,sb2,"t-sb2",p2); // ----------------------------------- // ray queries // ----------------------------------- // Edges of t Ray r12(p1,p2); Ray r21(p2,p1); Ray r13(p1,p3); Ray r23(p2,p3); b &= test_aux(is_kernel_exact,t,r12,"t-r12",s12); b &= test_aux(is_kernel_exact,t,r21,"t-r21",s21); b &= test_aux(is_kernel_exact,t,r13,"t-r13",s13); b &= test_aux(is_kernel_exact,t,r23,"t-r23",s23); // In triangle Point p9_(FT(0.), FT(0.5), FT(0.5)); Point p9(FT(0.25), FT(0.375), FT(0.375)); Ray r14(p1,p4); Ray r41(p4,p1); Ray r24(p2,p4); Ray r42(p4,p2); Ray r15(p1,p5); Ray r25(p2,p5); Ray r34(p3,p4); Ray r35(p3,p5); Ray r36(p3,p6); Ray r45(p4,p5); Ray r16(p1,p6); Ray r26(p2,p6); Ray r62(p6,p2); Ray r46(p4,p6); Ray r48(p4,p8); Ray r56(p5,p6); Ray r47(p4,p7); Ray r89(p8,p9); Ray r86(p8,p6); Ray r68(p6,p8); Segment r89_res(p8,p9_); b &= test_aux(is_kernel_exact,t,r14,"t-r14",s12); b &= test_aux(is_kernel_exact,t,r41,"t-r41",s41); b &= test_aux(is_kernel_exact,t,r24,"t-r24",s21); b &= test_aux(is_kernel_exact,t,r42,"t-r42",s42); b &= test_aux(is_kernel_exact,t,r15,"t-r15",s15); b &= test_aux(is_kernel_exact,t,r25,"t-r25",s23); b &= test_aux(is_kernel_exact,t,r34,"t-r34",s34); b &= test_aux(is_kernel_exact,t,r35,"t-r35",s32); b &= test_aux(is_kernel_exact,t,r36,"t-r36",s31); b &= test_aux(is_kernel_exact,t,r45,"t-r45",s45); b &= test_aux(is_kernel_exact,t,r16,"t-r16",s13); b &= test_aux(is_kernel_exact,t,r26,"t-r26",s26); b &= test_aux(is_kernel_exact,t,r62,"t-r62",s62); b &= test_aux(is_kernel_exact,t,r46,"t-r46",s46); b &= test_aux(is_kernel_exact,t,r48,"t-r48",s46); b &= test_aux(is_kernel_exact,t,r56,"t-r56",s56); b &= test_aux(is_kernel_exact,t,r47,"t-r47",s45); b &= test_aux(is_kernel_exact,t,r89,"t-t89",r89_res); b &= test_aux(is_kernel_exact,t,r68,"t-r68",s64); b &= test_aux(is_kernel_exact,t,r86,"t-r86",s86); // Outside points (in triangre prane) Ray rAB(pA,pB); Ray rBC(pB,pC); Ray r2E(p2,pE); Ray rE2(pE,p2); Ray r2A(p2,pA); Ray r6E(p6,pE); Ray rB8(pB,p8); Ray rC8(pC,p8); Ray r8C(p8,pC); Ray r1F(p1,pF); Ray rF6(pF,p6); b &= test_aux(is_kernel_exact,t,rAB,"t-rAB",p2); b &= test_aux(is_kernel_exact,t,rBC,"t-rBC",s46); b &= test_aux(is_kernel_exact,t,r2E,"t-r2E",s26); b &= test_aux(is_kernel_exact,t,rE2,"t-rE2",s62); b &= test_aux(is_kernel_exact,t,r2A,"t-r2A",p2); b &= test_aux(is_kernel_exact,t,r6E,"t-r6E",p6); b &= test_aux(is_kernel_exact,t,rB8,"t-rB8",s46); b &= test_aux(is_kernel_exact,t,rC8,"t-rC8",s64); b &= test_aux(is_kernel_exact,t,r8C,"t-r8C",s86); b &= test_aux(is_kernel_exact,t,r1F,"t-r1F",s13); b &= test_aux(is_kernel_exact,t,rF6,"t-rF6",s31); // Outside triangle plane Ray rab(pa,pb); Ray rac(pa,pc); Ray rae(pa,pe); Ray ra8(pa,p8); Ray rb2(pb,p2); b &= test_aux(is_kernel_exact,t,rab,"t-rab",p1); b &= test_aux(is_kernel_exact,t,rac,"t-rac",p6); b &= test_aux(is_kernel_exact,t,rae,"t-rae",p8); b &= test_aux(is_kernel_exact,t,ra8,"t-ra8",p8); b &= test_aux(is_kernel_exact,t,rb2,"t-rb2",p2); // ----------------------------------- // Line queries // ----------------------------------- // Edges of t Line l12(p1,p2); Line l21(p2,p1); Line l13(p1,p3); Line l23(p2,p3); b &= test_aux(is_kernel_exact,t,l12,"t-l12",s12); b &= test_aux(is_kernel_exact,t,l21,"t-l21",s21); b &= test_aux(is_kernel_exact,t,l13,"t-l13",s13); b &= test_aux(is_kernel_exact,t,l23,"t-l23",s23); // In triangle Line l14(p1,p4); Line l41(p4,p1); Line l24(p2,p4); Line l42(p4,p2); Line l15(p1,p5); Line l25(p2,p5); Line l34(p3,p4); Line l35(p3,p5); Line l36(p3,p6); Line l45(p4,p5); Line l16(p1,p6); Line l26(p2,p6); Line l62(p6,p2); Line l46(p4,p6); Line l48(p4,p8); Line l56(p5,p6); Line l47(p4,p7); Line l89(p8,p9); Line l86(p8,p6); Line l68(p6,p8); Segment l89_res(p1,p9_); b &= test_aux(is_kernel_exact,t,l14,"t-l14",s12); b &= test_aux(is_kernel_exact,t,l41,"t-l41",s21); b &= test_aux(is_kernel_exact,t,l24,"t-l24",s21); b &= test_aux(is_kernel_exact,t,l42,"t-l42",s12); b &= test_aux(is_kernel_exact,t,l15,"t-l15",s15); b &= test_aux(is_kernel_exact,t,l25,"t-l25",s23); b &= test_aux(is_kernel_exact,t,l34,"t-l34",s34); b &= test_aux(is_kernel_exact,t,l35,"t-l35",s32); b &= test_aux(is_kernel_exact,t,l36,"t-l36",s31); b &= test_aux(is_kernel_exact,t,l45,"t-l45",s45); b &= test_aux(is_kernel_exact,t,l16,"t-l16",s13); b &= test_aux(is_kernel_exact,t,l26,"t-l26",s26); b &= test_aux(is_kernel_exact,t,l62,"t-l62",s62); b &= test_aux(is_kernel_exact,t,l46,"t-l46",s46); b &= test_aux(is_kernel_exact,t,l48,"t-l48",s46); b &= test_aux(is_kernel_exact,t,l56,"t-l56",s56); b &= test_aux(is_kernel_exact,t,l47,"t-l47",s45); b &= test_aux(is_kernel_exact,t,l89,"t-t89",l89_res); b &= test_aux(is_kernel_exact,t,l68,"t-l68",s64); b &= test_aux(is_kernel_exact,t,l86,"t-l86",s46); // Outside points (in triangle plane) Line lAB(pA,pB); Line lBC(pB,pC); Line l2E(p2,pE); Line lE2(pE,p2); Line l2A(p2,pA); Line l6E(p6,pE); Line lB8(pB,p8); Line lC8(pC,p8); Line l8C(p8,pC); Line l1F(p1,pF); Line lF6(pF,p6); b &= test_aux(is_kernel_exact,t,lAB,"t-lAB",p2); b &= test_aux(is_kernel_exact,t,lBC,"t-lBC",s46); b &= test_aux(is_kernel_exact,t,l2E,"t-l2E",s26); b &= test_aux(is_kernel_exact,t,lE2,"t-lE2",s62); b &= test_aux(is_kernel_exact,t,l2A,"t-l2A",p2); b &= test_aux(is_kernel_exact,t,l6E,"t-l6E",s26); b &= test_aux(is_kernel_exact,t,lB8,"t-lB8",s46); b &= test_aux(is_kernel_exact,t,lC8,"t-lC8",s64); b &= test_aux(is_kernel_exact,t,l8C,"t-l8C",s46); b &= test_aux(is_kernel_exact,t,l1F,"t-l1F",s13); b &= test_aux(is_kernel_exact,t,lF6,"t-lF6",s31); // Outside triangle plane Line lab(pa,pb); Line lac(pa,pc); Line lae(pa,pe); Line la8(pa,p8); Line lb2(pb,p2); b &= test_aux(is_kernel_exact,t,lab,"t-lab",p1); b &= test_aux(is_kernel_exact,t,lac,"t-lac",p6); b &= test_aux(is_kernel_exact,t,lae,"t-lae",p8); b &= test_aux(is_kernel_exact,t,la8,"t-la8",p8); b &= test_aux(is_kernel_exact,t,lb2,"t-lb2",p2); return b; }
bool hitboxCollision(int a_x,int a_y,int a_width,int a_height,float a_angle, int b_x,int b_y,int b_width,int b_height,float b_angle) { Point pa1(a_x, a_y); Point pa2(a_x + cos (a_angle*PI/180) * a_width ,a_y - sin (a_angle*PI/180) * a_width); Point pa3(a_x + cos (a_angle*PI/180) * a_width + sin (a_angle*PI/180) * a_height, a_y - sin (a_angle*PI/180) * a_width + cos (a_angle*PI/180) * a_height); Point pa4(a_x + sin (a_angle*PI/180) * a_height, a_y + cos (a_angle*PI/180) * a_height); Point pb1(b_x, b_y); Point pb2(b_x + cos (b_angle*PI/180) * b_width ,b_y - sin (b_angle*PI/180) * b_width); Point pb3(b_x + cos (b_angle*PI/180) * b_width + sin (b_angle*PI/180) * b_height, b_y - sin (b_angle*PI/180) * b_width + cos (b_angle*PI/180) * b_height); Point pb4(b_x + sin (b_angle*PI/180) * b_height, b_y + cos (b_angle*PI/180) * b_height); Line la1(pa1,pa2); Line la2(pa2,pa3); Line la3(pa3,pa4); Line la4(pa4,pa1); Line lb1(pb1,pb2); Line lb2(pb2,pb3); Line lb3(pb3,pb4); Line lb4(pb4,pb1); if(segmentIntersection(la1,lb1)) return true; if(segmentIntersection(la1,lb2)) return true; if(segmentIntersection(la1,lb3)) return true; if(segmentIntersection(la1,lb4)) return true; if(segmentIntersection(la2,lb1)) return true; if(segmentIntersection(la2,lb2)) return true; if(segmentIntersection(la2,lb3)) return true; if(segmentIntersection(la2,lb4)) return true; if(segmentIntersection(la3,lb1)) return true; if(segmentIntersection(la3,lb2)) return true; if(segmentIntersection(la3,lb3)) return true; if(segmentIntersection(la3,lb4)) return true; if(segmentIntersection(la4,lb1)) return true; if(segmentIntersection(la4,lb2)) return true; if(segmentIntersection(la4,lb3)) return true; if(segmentIntersection(la4,lb4)) return true; return false; /* vector<Point*>intersections; intersections.push_back(lineIntersection(la1,lb1)); intersections.push_back(lineIntersection(la1,lb2)); intersections.push_back(lineIntersection(la1,lb3)); intersections.push_back(lineIntersection(la1,lb4)); intersections.push_back(lineIntersection(la2,lb1)); intersections.push_back(lineIntersection(la2,lb2)); intersections.push_back(lineIntersection(la2,lb3)); intersections.push_back(lineIntersection(la2,lb4)); intersections.push_back(lineIntersection(la3,lb1)); intersections.push_back(lineIntersection(la3,lb2)); intersections.push_back(lineIntersection(la3,lb3)); intersections.push_back(lineIntersection(la3,lb4)); intersections.push_back(lineIntersection(la4,lb1)); intersections.push_back(lineIntersection(la4,lb2)); intersections.push_back(lineIntersection(la4,lb3)); intersections.push_back(lineIntersection(la4,lb4)); int x_min=0;int x_max=0; int y_max=0;int y_min=0; if(a_width*a_height>b_width*b_height) { x_min = pa1.x; x_min=min(x_min,pa2.x); x_min=min(x_min,pa3.x); x_min=min(x_min,pa4.x); x_max = pa1.x; x_max=max(x_max,pa2.x); x_max=max(x_max,pa3.x); x_max=max(x_max,pa4.x); y_min = pa1.y; y_min=min(y_min,pa2.y); y_min=min(y_min,pa3.y); y_min=min(y_min,pa4.y); y_max = pa1.y; y_max=max(y_max,pa2.y); y_max=max(y_max,pa3.y); y_max=max(y_max,pa4.y); }else { x_min = pb1.x; x_min=min(x_min,pb2.x); x_min=min(x_min,pb3.x); x_min=min(x_min,pb4.x); x_max = pb1.x; x_max=max(x_max,pb2.x); x_max=max(x_max,pb3.x); x_max=max(x_max,pb4.x); y_min = pb1.y; y_min=min(y_min,pb2.y); y_min=min(y_min,pb3.y); y_min=min(y_min,pb4.y); y_max = pb1.y; y_max=max(y_max,pb2.y); y_max=max(y_max,pb3.y); y_max=max(y_max,pb4.y); } int cont=0; for(int i=0;i<(int)intersections.size();i++) { Point* point=intersections[i]; if(point!=NULL) { if(point->x > x_min && point->x < x_max && point->y > y_min && point->y < y_max) { cont++; } } } vector<Point*>::iterator i; for ( i = intersections.begin() ; i < intersections.end(); i++ ) { delete * i; } if(cont>=8) return true; */ return false; }
//Construct the kdTree kdTree::kdTree(vector<vector<double>> points, const string& method, int cutdimension): splitMethod(method){ if (points.empty()) { kdTreeRoot = nullptr; return; } // Select intial splitting axis int dimension = (int)(points[0].size()); int axis = cutdimension % dimension; size_t lb1(0),lb2(0),ub1(0),ub2(0); size_t pivotLocation; size_t numpoints = points.size(); if(numpoints == 1) { kdTreeRoot = shared_ptr<kdTreeNode>(new kdTreeNode(points[0])); } else { sort(points.begin(), points.end(), sorter(axis)); if (method == "median") { pivotLocation = (size_t)(numpoints/2); } else if (method == "mean") { double mean(0.0); for (size_t i=0;i<numpoints;i++) { mean = mean + points[i][axis]; } mean =mean/(double)numpoints; for (size_t i=0;i<numpoints;i++) { if (points[i][axis]>= mean) { pivotLocation = i; break; } } } /* lb1 = 0; */ ub1 = pivotLocation; lb2 = pivotLocation +1; ub2 = (size_t)points.size(); // Recursively create Left SubTree unique_ptr<kdTree> left_child = move(unique_ptr<kdTree> (new kdTree( slice<vector<double>>(points,lb1,ub1), method,axis+1))); // Recursively create Right SubTree unique_ptr<kdTree> right_child = move(unique_ptr<kdTree> (new kdTree( slice<vector<double>>(points,lb2,ub2), method,axis+1))); kdTreeRoot = shared_ptr<kdTreeNode>( new kdTreeNode( points[pivotLocation], axis, right_child->kdTreeRoot, left_child->kdTreeRoot)); } }
void propagate::mousemoved(Vec2 pos){ which = Vec2i((pos-Vec2(10,10))/scale); lb2(which); hover.setPosition(Vec2(which)*scale+Vec2(10,10)); }
//Compute continuity with brep2. int MGSBRep::continuity( // Reuturn value is the continuity. const MGSBRep& brep2, // Input second SBRep int is_u1, // Input if u-direction of this. int is_u2, // Input if u-direction of brep2. int opposite, // Input if parameter direction of which2 is equal or not. int& which1, // Outputs which perimeter(which1) of this is int& which2, // connected to which(which2) of brep2. // These are valid only when continuity>=0. double& ratio // Ratio of 1st derivatives of the two surfaces will // be returned. // ratio= d2/d1, where d1=1st deriv of this and d2=of brep2 ) const // Function's return value is: // -1: G(-1) continuity, i.e. two surfaces are discontinuous. // 0: G0 continuity, i.e. two surfaces are connected, // but tangents are discontinuous // 1: G1 continuity, i.e. two surfaces are connected, // and tangents are also continuous. // 2: G2 continuity, i.e. two surfaces are connected, // and tangents and curvatures are also continuous. { size_t i,j,k,i2; int incrmnt; double ratio2; int which; int cont, contold; size_t dim1=sdim(), dim2=brep2.sdim(); size_t ns1,nt1, ns2,nt2; MGLBRep p1a, p1b, p2a, p2b; // Test if perimeter of this is continuous to perimeter brep2. const MGKnotVector *s1,*s2,*t1,*t2; if(is_u1){ which1=0; s1=&knot_vector_u(); t1=&knot_vector_v(); p1a=perimeter(0); p1b=perimeter(2); } else{ which1=1; s1=&knot_vector_v(); t1=&knot_vector_u(); p1a=perimeter(1); p1b=perimeter(3); } if(is_u2){ which2=0; s2=&(brep2.knot_vector_u()); t2=&(brep2.knot_vector_v()); p2a=brep2.perimeter(0); p2b=brep2.perimeter(2); } else{ which2=1; s2=&(brep2.knot_vector_v()); t2=&(brep2.knot_vector_u()); p2a=brep2.perimeter(1); p2b=brep2.perimeter(3); } ns1=(*s1).bdim(); ns2=(*s2).bdim(); nt1=(*t1).bdim(); nt2=(*t2).bdim(); cont=0; // 1. Test if positional data of two perimeters are equal. if(opposite){ p2a.negate(); p2b.negate();} if (p1a.line_bcoef()==p2a.line_bcoef()){ cont=1;} else if(p1a.line_bcoef()==p2b.line_bcoef()){ which2+=2; cont=1;} else if(p1b.line_bcoef()==p2a.line_bcoef()){ which1+=2; cont=1;} else if(p1b.line_bcoef()==p2b.line_bcoef()){ which1+=2; which2+=2; cont=1;} if(cont==0) return -1; // There exists a possibility of continuity 1. // 2. Test if derivatives along v direction are equal. i2=0; incrmnt=1; if(opposite) {i2=ns2-1; incrmnt=-1;} MGBPointSeq b1(nt1,dim1), b2(nt2,dim2); contold=0; for(i=0; i<ns1; i++){ if(is_u1){ for(j=0; j<nt1; j++) for(k=0; k<dim1; k++) b1(j,k)=coef(i,j,k); } else{ for(j=0; j<nt1; j++) for(k=0; k<dim1; k++) b1(j,k)=coef(j,i,k); } if(is_u2){ for(j=0; j<nt2; j++) for(k=0; k<dim2; k++) b2(j,k)=brep2.coef(i2,j,k); } else{ for(j=0; j<nt2; j++) for(k=0; k<dim2; k++) b2(j,k)=brep2.coef(j,i2,k); } i2=i2+incrmnt; MGLBRep lb1(*t1,b1), lb2(*t2, b2); cont=lb1.continuity(lb2,which,ratio2); if(cont<=0) return 0; //Continuity is C0. if(contold==0) {contold=cont; ratio=ratio2;} else{ if(!MGREqual2(ratio2,ratio)) return 0; //Continuity is C0. else if(contold>cont) contold=cont; } } return contold; }