bool operator()(INT i1,INT i2) { TPt p1 = _pts[i1] - _down_right; TPt p2 = _pts[i2] - _down_right; TScal pvect = p1^p2; if (pvect) return (pvect > 0); TScal n1 = dist4(p1); TScal n2 = dist4(p2); return _norm_croissante ? (n1<n2) : (n1>n2) ; }
void bench_pcc(TGr41 & gr, TSom41 *** TABS,Pt2di sz) { TPcc41 PCC; TPtSubGr41 GrAll; TSubGr41_xeg GrXeq; TSubGr41_xy2 Gr_xy2; TEmpGr41 GrEmpty; for (int k =0; k < 300 ; k ++) { INT x1 = ((INT)(NRrandom3() * 100)) % sz.x; INT y1 = ((INT)(NRrandom3() * 100)) % sz.y; INT x2 = (x1+13*k)%sz.x; INT y2 = (y1+3*k)%sz.y; Pt2di p1 (x1,y1); Pt2di p2 (x2,y2); TSom41 & s1 = *(TABS[y1][x1]); TSom41 & s2 = *(TABS[y2][x2]); //TSom41 * res = PCC.pcc(s1,s2,GrAll); TSom41 * res = PCC.pcc(s1,s2,GrAll,eModePCC_Somme); // __NEW BENCH_ASSERT(PCC.pds(s2)==dist4(p1-p2)); ElFilo<TSom41 *> f41; PCC.chemin(f41,s2); BENCH_ASSERT(PCC.pds(s2)==f41.nb()-1); for (INT S=1 ; S<f41.nb() ; S++) BENCH_ASSERT(gr.arc_s1s2(*f41[S-1],*f41[S])); //res = PCC.pcc(s1,s2,GrXeq); res = PCC.pcc(s1,s2,GrXeq,eModePCC_Somme); // __NEW BENCH_ASSERT((res==&s2) == (x1==x2)); //res = PCC.pcc(s1,GrEmpty,GrXeq); res = PCC.pcc(s1,GrEmpty,GrXeq,eModePCC_Somme); // __NEW BENCH_ASSERT(res==0); for ( TSIt41 sit = gr.begin(GrAll); sit.go_on(); sit ++ ) { TSom41 & s = (*sit); BENCH_ASSERT(PCC.reached(s) == (s.attr()._pt.x == x1)); if (PCC.reached(s)) { INT y = s.attr()._pt.y; INT x = s.attr()._pt.x; BENCH_ASSERT(PCC.pds(s) == std::abs(y-y1)); if (y == y1) BENCH_ASSERT(PCC.pere(s) == 0); else if (y> y1) BENCH_ASSERT(PCC.pere(s) == TABS[y-1][x]); else BENCH_ASSERT(PCC.pere(s) == TABS[y+1][x]); } } //res = PCC.pcc(s1,s2,Gr_xy2); res = PCC.pcc(s1,s2,Gr_xy2,eModePCC_Somme); // __NEW BENCH_ASSERT ( (res==&s2) == ( ((x1%2==0) || (y1%2==0)) && ((x2%2==0) || (y2%2==0)) ) ); if (res==&s2) BENCH_ASSERT(PCC.pds(s2)==dist4(p1-p2)); } }
double dist4_scaled(double *a, double *b) { return dist4(a, b) * ONE_OVER_SQRT2; }
INT num_4_freeman(Pt2di p) { ASSERT_INTERNAL(dist4(p) == 1, "incoherence in num_4_freeman"); return p.x ? 1-p.x : 2-p.y; }