mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 05:52:59 +00:00 
			
		
		
		
	refactored compute_area
This commit is contained in:
		| @@ -1991,4 +1991,25 @@ EX bool same_point_may_warn(hyperpoint a, hyperpoint b) { | ||||
|   return true; | ||||
|   } | ||||
|  | ||||
| /** compute the area of a shape -- v.back() must equal v[0] */ | ||||
| EX ld compute_area(const vector<hyperpoint>& v) { | ||||
|   ld area = 0; | ||||
|   for(int i=0; i<v.size()-1; i++) { | ||||
|     hyperpoint h1 = v[i]; | ||||
|     hyperpoint h2 = v[i+1]; | ||||
|     if(euclid) | ||||
|       area += (h2[1] + h1[1]) * (h2[0] - h1[0]) / 2; | ||||
|     else { | ||||
|       hyperpoint rh2 = gpushxto0(h1) * h2; | ||||
|       hyperpoint rh1 = gpushxto0(h2) * h1; | ||||
|       ld b1 = atan2(rh1[1], rh1[0]); | ||||
|       ld b2 = atan2(rh2[1], rh2[0]); | ||||
|       ld x = b2 - b1 + M_PI; | ||||
|       cyclefix(x, 0); | ||||
|       area += x; | ||||
|       } | ||||
|     } | ||||
|   return area; | ||||
|   } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -2209,30 +2209,9 @@ EX namespace mapeditor { | ||||
|  | ||||
|   ld compute_area(hpcshape& sh) { | ||||
|     ld area = 0; | ||||
|     for(int i=sh.s; i<sh.e-1; i++) { | ||||
|       hyperpoint h1 = cgi.hpc[i]; | ||||
|       hyperpoint h2 = cgi.hpc[i+1]; | ||||
|       if(euclid) | ||||
|         area += (h2[1] + h1[1]) * (h2[0] - h1[0]) / 2; | ||||
|       else { | ||||
|         hyperpoint rh2 = gpushxto0(h1) * h2; | ||||
|         hyperpoint rh1 = gpushxto0(h2) * h1; | ||||
|         // ld a1 = atan2(h1[1], h1[0]); | ||||
|         // ld a2 = atan2(h2[1], h2[0]); | ||||
|         ld b1 = atan2(rh1[1], rh1[0]); | ||||
|         ld b2 = atan2(rh2[1], rh2[0]); | ||||
|         // C0 -> H1 -> H2 -> C0 | ||||
|         // at C0: (a1-a2) | ||||
|         // at H1: (rh2 - a1 - M_PI) | ||||
|         // at H2: (a2+M_PI - rh1) | ||||
|         // total: rh2 - rh1 | ||||
|         // ld z = degree; | ||||
|         ld x = b2 - b1 + M_PI; | ||||
|         cyclefix(x, 0); | ||||
|         area += x; | ||||
|         } | ||||
|       } | ||||
|     return area; | ||||
|     vector<hyperpoint> h; | ||||
|     for(int i=sh.s; i<sh.e; i++) h.push_back(cgi.hpc[i]); | ||||
|     return compute_area(h); | ||||
|     } | ||||
|  | ||||
| #define EDITING_TRIANGLES (GDIM == 3) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue