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 |
#ifndef __P2TR_REFINE_VECTOR2_H__
|
34 |
#define __P2TR_REFINE_VECTOR2_H__
|
35 |
|
36 |
#include <glib.h>
|
37 |
|
38 |
/**
|
39 |
* \struct P2trVector2
|
40 |
* A struct for representing a vector with 2 coordinates (a point in 2D)
|
41 |
*/
|
42 |
typedef struct {
|
43 |
/** The first coordinate of the vector */
|
44 |
gdouble x;
|
45 |
/** The second coordinate of the vector */
|
46 |
gdouble y;
|
47 |
} P2trVector2;
|
48 |
|
49 |
#define P2TR_VECTOR2_LEN_SQ2(X, Y) \
|
50 |
((X) * (X) + (Y) * (Y))
|
51 |
|
52 |
#define P2TR_VECTOR2_LEN_SQ(V) \
|
53 |
(P2TR_VECTOR2_LEN_SQ2((V)->x, (V)->y))
|
54 |
|
55 |
#define P2TR_VECTOR2_DOT(V1,V2) \
|
56 |
((V1)->x * (V2)->x + (V1)->y * (V2)->y)
|
57 |
|
58 |
#define P2TR_VECTOR2_DISTANCE_SQ2(X1,Y1,X2,Y2) \
|
59 |
(P2TR_VECTOR2_LEN_SQ2((X1) - (X2), (Y1) - (Y2)))
|
60 |
|
61 |
#define P2TR_VECTOR2_DISTANCE_SQ(V1,V2) \
|
62 |
(P2TR_VECTOR2_DISTANCE_SQ2((V1)->x, (V1)->y, (V2)->x, (V2)->y))
|
63 |
|
64 |
/** Compute the dot product of two vectors */
|
65 |
gdouble p2tr_vector2_dot (const P2trVector2 *a, const P2trVector2 *b);
|
66 |
|
67 |
/** Check if all the coordinates of the two vectors are the same */
|
68 |
gboolean p2tr_vector2_is_same (const P2trVector2 *a, const P2trVector2 *b);
|
69 |
|
70 |
/**
|
71 |
* Compute the difference of two vectors
|
72 |
* @param[in] a The vector to subtract from
|
73 |
* @param[in] b The vector to be subtracted
|
74 |
* @param[out] dest The vector in which the result should be stored
|
75 |
*/
|
76 |
void p2tr_vector2_sub (const P2trVector2 *a, const P2trVector2 *b, P2trVector2 *dest);
|
77 |
|
78 |
/**
|
79 |
* Compute the center point of the edge defined between two points
|
80 |
* @param[in] a The first side of the edge
|
81 |
* @param[in] b The second side of the edge
|
82 |
* @param[out] dest The vector in which the result should be stored
|
83 |
*/
|
84 |
void p2tr_vector2_center (const P2trVector2 *a, const P2trVector2 *b, P2trVector2 *dest);
|
85 |
|
86 |
/**
|
87 |
* Compute the norm of a vector (the length of the line from the origin
|
88 |
* to the 2D point it represents)
|
89 |
* @param[in] v The vector whose norm should be computed
|
90 |
* @return The norm of the vector
|
91 |
*/
|
92 |
gdouble p2tr_vector2_norm (const P2trVector2 *v);
|
93 |
|
94 |
/**
|
95 |
* Copy a vector
|
96 |
* @param[out] dest The destination of the copy operation
|
97 |
* @param[in] src The vector to copy
|
98 |
*/
|
99 |
void p2tr_vector2_copy (P2trVector2 *dest, const P2trVector2 *src);
|
100 |
|
101 |
#endif
|