1 |
/*
|
2 |
* This file is a part of Poly2Tri-C
|
3 |
* (c) Barak Itkin <lightningismyname@gmail.com>
|
4 |
* http://code.google.com/p/poly2tri-c/
|
5 |
*
|
6 |
* All rights reserved.
|
7 |
*
|
8 |
* Redistribution and use in source and binary forms, with or without modification,
|
9 |
* are permitted provided that the following conditions are met:
|
10 |
*
|
11 |
* * Redistributions of source code must retain the above copyright notice,
|
12 |
* this list of conditions and the following disclaimer.
|
13 |
* * Redistributions in binary form must reproduce the above copyright notice,
|
14 |
* this list of conditions and the following disclaimer in the documentation
|
15 |
* and/or other materials provided with the distribution.
|
16 |
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
17 |
* used to endorse or promote products derived from this software without specific
|
18 |
* prior written permission.
|
19 |
*
|
20 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
24 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
25 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
26 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
27 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
28 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
29 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
30 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31 |
*/
|
32 |
|
33 |
#include <math.h>
|
34 |
#include <glib.h>
|
35 |
#include "vector2.h"
|
36 |
|
37 |
gdouble
|
38 |
p2tr_vector2_dot (const P2trVector2 *a,
|
39 |
const P2trVector2 *b)
|
40 |
{
|
41 |
return P2TR_VECTOR2_DOT (a, b);
|
42 |
}
|
43 |
|
44 |
gboolean
|
45 |
p2tr_vector2_is_same (const P2trVector2 *a,
|
46 |
const P2trVector2 *b)
|
47 |
{
|
48 |
if (a == NULL || b == NULL)
|
49 |
return ! ((a == NULL) ^ (b == NULL));
|
50 |
else
|
51 |
return a->x == b->x && a->y == b->y;
|
52 |
}
|
53 |
|
54 |
void
|
55 |
p2tr_vector2_sub (const P2trVector2 *a,
|
56 |
const P2trVector2 *b,
|
57 |
P2trVector2 *dest)
|
58 |
{
|
59 |
dest->x = a->x - b->x;
|
60 |
dest->y = a->y - b->y;
|
61 |
}
|
62 |
|
63 |
void
|
64 |
p2tr_vector2_center (const P2trVector2 *a,
|
65 |
const P2trVector2 *b,
|
66 |
P2trVector2 *dest)
|
67 |
{
|
68 |
dest->x = (a->x + b->x) * 0.5;
|
69 |
dest->y = (a->y + b->y) * 0.5;
|
70 |
}
|
71 |
|
72 |
gdouble
|
73 |
p2tr_vector2_norm (const P2trVector2 *v)
|
74 |
{
|
75 |
return sqrt (P2TR_VECTOR2_LEN_SQ (v));
|
76 |
}
|
77 |
|
78 |
void
|
79 |
p2tr_vector2_copy (P2trVector2 *dest,
|
80 |
const P2trVector2 *src)
|
81 |
{
|
82 |
dest->x = src->x;
|
83 |
dest->y = src->y;
|
84 |
}
|