1 | /* graphene-triangle.h: A triangle |
2 | * |
3 | * SPDX-License-Identifier: MIT |
4 | * |
5 | * Copyright 2014 Emmanuele Bassi |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | * of this software and associated documentation files (the "Software"), to deal |
9 | * in the Software without restriction, including without limitation the rights |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | * copies of the Software, and to permit persons to whom the Software is |
12 | * furnished to do so, subject to the following conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23 | * THE SOFTWARE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if !defined(GRAPHENE_H_INSIDE) && !defined(GRAPHENE_COMPILATION) |
29 | #error "Only graphene.h can be included directly." |
30 | #endif |
31 | |
32 | #include "graphene-types.h" |
33 | #include "graphene-vec3.h" |
34 | |
35 | GRAPHENE_BEGIN_DECLS |
36 | |
37 | /** |
38 | * graphene_triangle_t: |
39 | * |
40 | * A triangle. |
41 | * |
42 | * Since: 1.2 |
43 | */ |
44 | struct _graphene_triangle_t |
45 | { |
46 | /*< private >*/ |
47 | GRAPHENE_PRIVATE_FIELD (graphene_vec3_t, a); |
48 | GRAPHENE_PRIVATE_FIELD (graphene_vec3_t, b); |
49 | GRAPHENE_PRIVATE_FIELD (graphene_vec3_t, c); |
50 | }; |
51 | |
52 | GRAPHENE_AVAILABLE_IN_1_2 |
53 | graphene_triangle_t * graphene_triangle_alloc (void); |
54 | GRAPHENE_AVAILABLE_IN_1_2 |
55 | void graphene_triangle_free (graphene_triangle_t *t); |
56 | |
57 | GRAPHENE_AVAILABLE_IN_1_2 |
58 | graphene_triangle_t * graphene_triangle_init_from_point3d (graphene_triangle_t *t, |
59 | const graphene_point3d_t *a, |
60 | const graphene_point3d_t *b, |
61 | const graphene_point3d_t *c); |
62 | GRAPHENE_AVAILABLE_IN_1_2 |
63 | graphene_triangle_t * graphene_triangle_init_from_vec3 (graphene_triangle_t *t, |
64 | const graphene_vec3_t *a, |
65 | const graphene_vec3_t *b, |
66 | const graphene_vec3_t *c); |
67 | GRAPHENE_AVAILABLE_IN_1_10 |
68 | graphene_triangle_t * graphene_triangle_init_from_float (graphene_triangle_t *t, |
69 | const float *a, |
70 | const float *b, |
71 | const float *c); |
72 | GRAPHENE_AVAILABLE_IN_1_2 |
73 | void graphene_triangle_get_points (const graphene_triangle_t *t, |
74 | graphene_point3d_t *a, |
75 | graphene_point3d_t *b, |
76 | graphene_point3d_t *c); |
77 | GRAPHENE_AVAILABLE_IN_1_2 |
78 | void graphene_triangle_get_vertices (const graphene_triangle_t *t, |
79 | graphene_vec3_t *a, |
80 | graphene_vec3_t *b, |
81 | graphene_vec3_t *c); |
82 | GRAPHENE_AVAILABLE_IN_1_2 |
83 | float graphene_triangle_get_area (const graphene_triangle_t *t); |
84 | GRAPHENE_AVAILABLE_IN_1_2 |
85 | void graphene_triangle_get_midpoint (const graphene_triangle_t *t, |
86 | graphene_point3d_t *res); |
87 | GRAPHENE_AVAILABLE_IN_1_2 |
88 | void graphene_triangle_get_normal (const graphene_triangle_t *t, |
89 | graphene_vec3_t *res); |
90 | GRAPHENE_AVAILABLE_IN_1_2 |
91 | void graphene_triangle_get_plane (const graphene_triangle_t *t, |
92 | graphene_plane_t *res); |
93 | GRAPHENE_AVAILABLE_IN_1_2 |
94 | void graphene_triangle_get_bounding_box (const graphene_triangle_t *t, |
95 | graphene_box_t *res); |
96 | GRAPHENE_AVAILABLE_IN_1_2 |
97 | bool graphene_triangle_get_barycoords (const graphene_triangle_t *t, |
98 | const graphene_point3d_t *p, |
99 | graphene_vec2_t *res); |
100 | GRAPHENE_AVAILABLE_IN_1_10 |
101 | bool graphene_triangle_get_uv (const graphene_triangle_t *t, |
102 | const graphene_point3d_t *p, |
103 | const graphene_vec2_t *uv_a, |
104 | const graphene_vec2_t *uv_b, |
105 | const graphene_vec2_t *uv_c, |
106 | graphene_vec2_t *res); |
107 | |
108 | GRAPHENE_AVAILABLE_IN_1_2 |
109 | bool graphene_triangle_contains_point (const graphene_triangle_t *t, |
110 | const graphene_point3d_t *p); |
111 | GRAPHENE_AVAILABLE_IN_1_2 |
112 | bool graphene_triangle_equal (const graphene_triangle_t *a, |
113 | const graphene_triangle_t *b); |
114 | |
115 | GRAPHENE_END_DECLS |
116 | |