#include <glib.h>\r
#include "math.h"\r
\r
-#define EDGE_LEN_SQ(X,Y) ((X) * (X) + (Y) * (Y))\r
-#define VECTOR2_LEN_SQ(V) (EDGE_LEN_SQ((V)->x, (V)->y))\r
-#define VECTOR2_DOT(V1,V2) ((V1)->x * (V2)->x + (V1)->y * (V2)->y)\r
-\r
gdouble\r
p2tr_math_length_sq (gdouble x1, gdouble y1,\r
gdouble x2, gdouble y2)\r
{\r
- return EDGE_LEN_SQ (x1 - x2, y1 - y2);\r
+ return P2TR_VECTOR2_DISTANCE_SQ2 (x1, y1, x2, y2);\r
}\r
\r
gdouble\r
p2tr_vector2_sub(P, A, &v2);\r
\r
/* Compute dot products */\r
- dot00 = VECTOR2_DOT(&v0, &v0);\r
- dot01 = VECTOR2_DOT(&v0, &v1);\r
- dot02 = VECTOR2_DOT(&v0, &v2);\r
- dot11 = VECTOR2_DOT(&v1, &v1);\r
- dot12 = VECTOR2_DOT(&v1, &v2);\r
+ dot00 = P2TR_VECTOR2_DOT(&v0, &v0);\r
+ dot01 = P2TR_VECTOR2_DOT(&v0, &v1);\r
+ dot02 = P2TR_VECTOR2_DOT(&v0, &v2);\r
+ dot11 = P2TR_VECTOR2_DOT(&v1, &v1);\r
+ dot12 = P2TR_VECTOR2_DOT(&v1, &v2);\r
\r
/* Compute barycentric coordinates */\r
invDenom = 1 / (dot00 * dot11 - dot01 * dot01);\r
* |Dx Dy Dx^2+Dy^2 1|\r
*/\r
gdouble result = p2tr_matrix_det4 (\r
- A->x, A->y, VECTOR2_LEN_SQ(A), 1,\r
- B->x, B->y, VECTOR2_LEN_SQ(B), 1,\r
- C->x, C->y, VECTOR2_LEN_SQ(C), 1,\r
- D->x, D->y, VECTOR2_LEN_SQ(D), 1\r
+ A->x, A->y, P2TR_VECTOR2_LEN_SQ(A), 1,\r
+ B->x, B->y, P2TR_VECTOR2_LEN_SQ(B), 1,\r
+ C->x, C->y, P2TR_VECTOR2_LEN_SQ(C), 1,\r
+ D->x, D->y, P2TR_VECTOR2_LEN_SQ(D), 1\r
);\r
\r
if (result > INCIRCLE_EPSILON)\r
p2tr_vector2_sub(X, W, &WX);\r
p2tr_vector2_sub(Y, W, &WY);\r
\r
- return VECTOR2_DOT(&WX, &WY)\r
+ return P2TR_VECTOR2_DOT(&WX, &WY)\r
<= 0.5 * p2tr_vector2_norm(&WX) * p2tr_vector2_norm(&WY);\r
}\r
P2trPoint*
p2tr_point_new (const P2trVector2 *c)
+{
+ return p2tr_point_new2 (c->x, c->y);
+}
+
+P2trPoint*
+p2tr_point_new2 (gdouble x, gdouble y)
{
P2trPoint *self = g_slice_new (P2trPoint);
- p2tr_vector2_copy (&self->c, c);
+ self->c.x = x;
+ self->c.y = y;
self->mesh = NULL;
self->outgoing_edges = NULL;
self->refcount = 1;
g_slice_free (P2trPoint, self);
}
-static P2trEdge*
-_p2tr_point_existing_edge_to (P2trPoint* self, P2trPoint *end)
+P2trEdge*
+p2tr_point_has_edge_to (P2trPoint *start,
+ P2trPoint *end)
{
GList *iter;
- for (iter = self->outgoing_edges; iter != NULL; iter = iter->next)
+ for (iter = start->outgoing_edges; iter != NULL; iter = iter->next)
{
P2trEdge *edge = (P2trEdge*) iter->data;
if (edge->end == end)
p2tr_point_get_edge_to (P2trPoint *start,
P2trPoint *end)
{
- P2trEdge* result = _p2tr_point_existing_edge_to (start, end);
+ P2trEdge* result = p2tr_point_has_edge_to (start, end);
if (result == NULL)
p2tr_exception_programmatic ("Tried to get an edge that doesn't exist!");
else
gdouble y;\r
} P2trVector2;\r
\r
+#define P2TR_VECTOR2_LEN_SQ2(X, Y) \\r
+ ((X) * (X) + (Y) * (Y))\r
+\r
+#define P2TR_VECTOR2_LEN_SQ(V) \\r
+ (P2TR_VECTOR2_LEN_SQ2((V)->x, (V)->y))\r
+\r
+#define P2TR_VECTOR2_DOT(V1,V2) \\r
+ ((V1)->x * (V2)->x + (V1)->y * (V2)->y)\r
+\r
+#define P2TR_VECTOR2_DISTANCE_SQ2(X1,Y1,X2,Y2) \\r
+ (P2TR_VECTOR2_LEN_SQ2((X1) - (X2), (Y1) - (Y2)))\r
+\r
+#define P2TR_VECTOR2_DISTANCE_SQ(V1,V2) \\r
+ (P2TR_VECTOR2_DISTANCE_SQ2((V1)->x, (V1)->y, (V2)->x, (V2)->y))\r
+\r
/** Compute the dot product of two vectors */\r
gdouble p2tr_vector2_dot (const P2trVector2 *a, const P2trVector2 *b);\r
\r