Ignore:
Timestamp:
05/23/23 16:20:10 (14 months ago)
Author:
jderouillat
Message:

Backport 2500, 2502 (convex cells) and 2503 (memory_report option) from XIOS2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/branches/xios-3.0-beta/extern/remap/src/polyg.cpp

    r2282 r2505  
    1818  (because computing intersection area requires both polygons to have same orientation) 
    1919*/ 
     20 
    2021void orient(int N, Coord *vertex, Coord *edge, double *d, const Coord &g) 
    2122{ 
     
    2425  Coord vertical = crossprod(ga, gb); 
    2526  if (N > 2 && scalarprod(g, vertical) < 0)  // (GAxGB).G 
    26   { 
    27     for (int i = 0; i < N/2; i++) 
    28       swap(vertex[i], vertex[N-1-i]); 
    29  
    30     for (int i = 0; i < (N-1)/2; i++) 
    31     { 
    32       swap(edge[N-2-i], edge[i]); 
    33       swap(d[i], d[N-2-i]); 
    34     } 
    35   } 
    36 } 
    37  
     27    switchOrientation(N, vertex, edge, d) ; 
     28   
     29} 
     30 
     31void switchOrientation(int N, Coord *vertex, Coord *edge, double *d) 
     32{ 
     33  for (int i = 0; i < N/2; i++) swap(vertex[i], vertex[N-1-i]); 
     34 
     35  for (int i = 0; i < (N-1)/2; i++) 
     36  { 
     37    swap(edge[N-2-i], edge[i]); 
     38    swap(d[i], d[N-2-i]); 
     39  } 
     40   
     41} 
    3842 
    3943void normals(Coord *x, int n, Coord *a) 
     
    9498  { 
    9599    return  proj(gc_normalintegral(x, n)); 
     100    //return new_barycentre(x,n) ; 
    96101  } 
    97102  else if (n == 0) return ORIGIN; 
    98103  else if (n == 2) return midpoint(x[0], x[1]); 
    99104  else if (n == 1) return x[0]; 
    100  
    101   error_exit( "Missing return in : Coord exact_barycentre(const Coord *x, int n)" ); 
    102   return ORIGIN; 
    103 } 
     105} 
     106 
     107/* other methode to compute barycenter of spherical polygon 
     108   for a spherical polygon, the moment is half the sum of (a x b) / ||a x b|| * (angle between a and b)  
     109   for each pair of consecutive vertices a,b. 
     110*/  
     111 
     112Coord new_barycentre(const Coord *x, int n) 
     113{ 
     114  if (n >= 3) 
     115  { 
     116    Coord sum=ORIGIN ; 
     117    for (int i = 0; i < n; i++) 
     118    {  
     119      sum=sum+crossprod(x[i],x[(i+1)%n])*(1./norm(crossprod(x[i],x[(i+1)%n]))*2.*atan2(norm(x[i]-x[(i+1)%n]),norm(x[i]+x[(i+1)%n]))) ;  
     120    } 
     121    return proj(sum) ;  
     122  } 
     123  else if (n == 0) return ORIGIN; 
     124  else if (n == 2) return midpoint(x[0], x[1]); 
     125  else if (n == 1) return x[0]; 
     126} 
     127 
     128 
    104129 
    105130Coord sc_gc_moon_normalintegral(Coord a, Coord b, Coord pole) 
Note: See TracChangeset for help on using the changeset viewer.