Ejemplo n.º 1
0
 polygon::polygon(const reshp::shp::polygon& poly)
 {
     for(int32_t part = 0; part < poly.num_parts; ++part)
     {
         reshp::polygon::ring ring;
         int32_t first_index = poly.parts[part];
         reshp::point first(poly.points[first_index].x, poly.points[first_index].y);
         
         for(int32_t p = first_index + 1; p < poly.num_points; ++p)
         {
             reshp::segment segment(reshp::point(poly.points[p - 1].x, poly.points[p - 1].y),
                                    reshp::point(poly.points[p].x, poly.points[p].y));
             
             ring.segments.push_back(segment);
             
             if(segment.end == first)
                 break;
         }
         
         int sum = 0;
         
         for(unsigned s = 0; s < ring.segments.size(); ++s)
             sum += (ring.segments[s].end.x - ring.segments[s].start.x) * (ring.segments[s].end.y + ring.segments[s].start.y);
         
         // Clockwise: Outer, Counter-clockwise: Inner
         ring.type = (sum > 0 ? ring::outer : ring::inner);
         
         ring.calculate_aabb();
         rings.push_back(ring);
     }
     
     calculate_aabb();
 }
Ejemplo n.º 2
0
const AABB &RenderObject::aabb() {
	if(aabb_dirty()) calculate_aabb();

	return aabb_;
}