Beispiel #1
0
int main(){
	struct rectangle rect1 = make_rectangle(make_point(2,1), make_point(4,6));
	struct rectangle rect2 = make_rectangle(make_point(3,3), make_point(9,9));
	
	printf("Intersection: %d\n", is_intersect(rect1, rect2));
	
	return 0;
}
Beispiel #2
0
void Map::generate(TCODRandom* random) {
    // Generate a random map
    
    // Throw out the old map
    map.clear();
    
    int numRooms = random->getInt(20, 30);
    
    for(int i = 0; i < numRooms; i++) {
        // Make some rooms
        make_rectangle(random->getInt(0, 20), random->getInt(0, 20), random->getInt(3, 10), random->getInt(3, 10));
    }
    
    // Flood fill from a single point and delete everything else.
    std::set<std::pair<int, int>> reachable;
    
    // We need to remember what we already queued
    std::set<std::pair<int, int>> tested;
    // Start at a random place and flood fill from there.
    std::list<std::pair<int, int>> queue = {findEmpty(random)};
    
    while(queue.size() > 0) {
        // Grab a random place
        auto toVisit = queue.front();
        queue.pop_front();
        
        if(getTile(toVisit.first, toVisit.second).isPassable()) {
            // We can go here!
            
            // This tile is reachable
            reachable.insert(toVisit);
            
            std::vector<std::pair<int, int>> offsets = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
            for(auto offset : offsets) {
                auto nextToVisit = std::make_pair(toVisit.first + offset.first, toVisit.second + offset.second);
                
                if(!tested.count(nextToVisit)) {
                
                    // Try this potentially reachable spot next.
                    queue.push_back(nextToVisit);
                    // Don't queue it again
                    tested.insert(nextToVisit);   
                }
                
            }
        }
    }
    
    for(auto& kv : map) {
        if(!reachable.count(kv.first) && kv.second.isPassable()) {
            // This is a passable place that isn't reachable.
            
            // Make it impassable as a hack. The player will never know because
            // they can never get there, but it won't be chosen when we ask for
            // a passable spot.
            kv.second = Tile(kv.second.getCharacter(), false);
        }
    }
    
}
/*^-----------------------------------------------------------------------------
| PF
| mod_image_gen_mkrect : command function for user command "mkrect"
|   struct lxrcmd *c: Command-control-block calling this command function.
|
|
|
| Returns : PASS/FAIL
+-----------------------------------------------------------------------------*/
PF mod_image_gen_mkrect ( struct lxrcmd *c ) 
{

    make_rectangle ( c->args[1].v.s, c->args[2].v.ld, c->args[3].v.ld, c->args[4].v.f, c->args[5].v.f, c->args[6].v.f, c->args[7].v.f);   


    c->results = NULL;   // NULL results block. Change as appropriate


    return(PASS);
}
Beispiel #4
0
static JSBool
get_rectangle_func(JSContext *context,
                   unsigned argc,
                   jsval *vp)
{
    PRELUDE;
    int i;
    JSObject *rect_obj;
    cairo_rectangle_int_t rect;
    jsval retval;

    if (!gjs_parse_call_args(context, "get_rectangle", "i", argv, "rect", &i))
        return JS_FALSE;

    cairo_region_get_rectangle(this_region, i, &rect);
    rect_obj = make_rectangle(context, &rect);

    retval = OBJECT_TO_JSVAL(rect_obj);
    argv.rval().set(retval);
    RETURN_STATUS;
}