Skip to content

Instantly share code, notes, and snippets.

@heronyang
Created August 3, 2019 19:54
Show Gist options
  • Save heronyang/fb0a644a81042a25c534a82ec810baf6 to your computer and use it in GitHub Desktop.
Save heronyang/fb0a644a81042a25c534a82ec810baf6 to your computer and use it in GitHub Desktop.
/* point.h */
struct Point;
struct Point* makePoint(double x, double y);
double getDistance(struct Point *p1, struct Point *p2);
/* point.c */
#include "point.h"
#include <stdlib.h>
#include <math.h>
struct Point {
double x, y;
}
struct Point* makePoint(double x, double y) {
struct Point* p = malloc(sizeof(struct Point));
p->x = x;
p->y = y;
return p;
}
double getDistance(struct Point* p1, struct Point *p2) {
double dx = p1->x - p2->x;
double dy = p1->y - p2->y;
return sqrt(dx*dx + dy*dy);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment