return 0;
}
+/*
+ * Merge planets a and b into planet a
+ *
+ * It is left for the caller to deal with the scrap planet b
+ */
+static void _merge_planets(struct planet *a, struct planet *b)
+{
+ struct vector pa, pb, p;
+
+ vector_scale(&a->speed, a->mass, &pa);
+ vector_scale(&b->speed, b->mass, &pb);
+ vector_add(&pa, &pb, &p);
+
+ vector_scale(&a->pos, a->mass, &a->pos);
+ vector_scale(&b->pos, b->mass, &b->pos);
+
+ a->mass += b->mass;
+ vector_div(&a->pos, a->mass, &a->pos);
+ reshape_planet(a);
+ vector_div(&p, a->mass, &a->speed);
+}
+
+/*
+ * Merge planets a and b into a the new planet a, which pointer is
+ * returned to the caller. Planet b is removed from the linked list
+ * and it's memory is freed. The merged planet will retain in the
+ * list.
+ */
+struct planet *merge_planets(struct planet *a, struct planet *b)
+{
+ _merge_planets(a, b);
+
+ list_del(&b->list);
+ free(b);
+ return a;
+}
+
void move_planet(struct planet *p, const double time)
{
struct vector tmp;
void init_planet(const SDL_Surface *screen, struct planet *p);
void draw_planet(SDL_Surface *screen, struct planet *p);
int gravitize_planets(struct planet *a, struct planet *b, const double time);
+struct planet *merge_planets(struct planet *a, struct planet *b);
void move_planet(struct planet *p, const double time);
void print_planet(const struct planet *p);