void bench_dist_InerMat_seg_droite() { for (int i = 0; i<100 ; i++) { Pt2dr p1 = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4); Pt2dr p2 = p1; while (euclid(p1-p2) < 1e2) p2 = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4); SegComp s(p1,p2); int nb = (int)(50 * NRrandom3()); REAL d0 = 0.0; RMat_Inertie m; for (int j =0; j<nb ; j++) { Pt2dr q = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4); REAL pds = NRrandom3(); m = m.plus_cple(q.x,q.y,pds); d0 += pds * s.square_dist_droite(q); } REAL d1 = square_dist_droite(s,m); BENCH_ASSERT(std::abs(d0 -d1) < BIG_epsilon); } }
REAL SegComp::square_dist(ModePrim mode,Pt2dr pt) const { switch (mode) { case droite : return square_dist_droite(pt); case demi_droite : return square_dist_demi_droite(pt); default : return square_dist_seg(pt); } }
double APP_cout_square_droite(SomApproxPoly * s1,SomApproxPoly * s2,const SegComp& seg,const ArgAPP &) { RMat_Inertie m = s1->inert_dif(s2); double d = square_dist_droite(seg,m); return sqrt(std::max(0.0,d*m.s())); }