commit c917b8bec4cc2abdf1d34e817df4c5c7718397ba
parent 8387a8776375f7e6ac91d2672bffc2544307ca95
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 7 Oct 2016 14:57:11 +0200
Implement and test the ssol_shape_get_id function
Diffstat:
3 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/src/ssol.h b/src/ssol.h
@@ -345,6 +345,12 @@ SSOL_API res_T
ssol_shape_ref_put
(struct ssol_shape* shape);
+/* Retrieve the id of the shape */
+SSOL_API res_T
+ssol_shape_get_id
+ (struct ssol_shape* shape,
+ uint32_t* id);
+
/* Define a punched surface in local space, i.e. no translation & no orientation */
SSOL_API res_T
ssol_punched_surface_setup
diff --git a/src/ssol_shape.c b/src/ssol_shape.c
@@ -569,38 +569,38 @@ quadric_solve_second
double* dist)
{
ASSERT(dist);
- if (a != 0) {
+ if(a != 0) {
/* Standard case: 2nd degree */
const double delta = b * b - 4 * a * c;
- if (delta > 0) {
+ if(delta > 0) {
const double sqrt_delta = sqrt(delta);
/* Precise formula */
const double t1 = (-b - inject_same_sign(sqrt_delta, b)) / (2 * b);
const double t2 = c / (a * t1);
- if (t1 < 0 && t2 < 0) return 0; /* no positive solution */
- if (t1 < 0) {
+ if(t1 < 0 && t2 < 0) return 0; /* no positive solution */
+ if(t1 < 0) {
*dist = t2; /* t2 is the only positive solution */
return 1;
}
- if (t2 < 0) {
+ if(t2 < 0) {
*dist = t1; /* t1 is the only positive solution */
return 1;
}
/* Both t1 and t2 are positive: choose the closest value to hint */
*dist = fabs(t1 - hint) < fabs(t2 - hint) ? t1 : t2;
return 1;
- } else if (delta == 0) {
+ } else if(delta == 0) {
const double t = -b / (2 * a);
- if (t < 0) return 0; /* no positive solution */
+ if(t < 0) return 0; /* no positive solution */
*dist = t;
return 1;
} else {
return 0;
}
- } else if (b != 0) {
+ } else if(b != 0) {
/* degenerated case: 1st degree only */
const double t = -c / b;
- if (t < 0) return 0; /* no positive solution */
+ if(t < 0) return 0; /* no positive solution */
*dist = t;
return 1;
}
@@ -651,7 +651,7 @@ quadric_plane_intersect_local
const double b = dir[2];
const double c = org[2];
int sol = quadric_solve_second(a, b, c, 0, dist);
- if (!sol) return 0;
+ if(!sol) return 0;
d3_add(pt, org, d3_muld(pt, dir, *dist));
quadric_plane_gradient_local(grad);
return 1;
@@ -673,7 +673,7 @@ quadric_parabol_intersect_local
2 * org[0] * dir[0] + 2 * org[1] * dir[1] - 4 * quad->focal * dir[2];
const double c = org[0] * org[0] + org[1] * org[1] - 4 * quad->focal * org[2];
const int sol = quadric_solve_second(a, b, c, hint, dist);
- if (!sol) return 0;
+ if(!sol) return 0;
d3_add(pt, org, d3_muld(pt, dir, *dist));
quadric_parabol_gradient_local(quad, pt, grad);
return 1;
@@ -694,7 +694,7 @@ quadric_parabolic_cylinder_intersect_local
const double b = 2 * org[1] * dir[1] - 4 * quad->focal * dir[2];
const double c = org[1] * org[1] - 4 * quad->focal * org[2];
const int sol = quadric_solve_second(a, b, c, hint, dist);
- if (!sol) return 0;
+ if(!sol) return 0;
d3_add(pt, org, d3_muld(pt, dir, *dist));
quadric_parabolic_cylinder_gradient_local(quad, pt, grad);
return 1;
@@ -840,6 +840,17 @@ ssol_shape_ref_put(struct ssol_shape* shape)
}
res_T
+ssol_shape_get_id(struct ssol_shape* shape, uint32_t* id)
+{
+ unsigned ui;
+ STATIC_ASSERT(sizeof(unsigned) <= sizeof(uint32_t), Unexpected_sizeof_unsigned);
+ if(!shape || !id) return RES_BAD_ARG;
+ S3D(shape_get_id(shape->shape_rt, &ui));
+ *id = (uint32_t)ui;
+ return RES_OK;
+}
+
+res_T
ssol_punched_surface_setup
(struct ssol_shape* shape,
const struct ssol_punched_surface* psurf)
diff --git a/src/test_ssol_shape.c b/src/test_ssol_shape.c
@@ -37,6 +37,7 @@ main(int argc, char** argv)
struct ssol_punched_surface punched_surface;
struct ssol_carving carving;
struct ssol_quadric quadric;
+ uint32_t id;
double polygon[] = {
-1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.f, -2.f
};
@@ -58,6 +59,11 @@ main(int argc, char** argv)
CHECK(ssol_shape_create_mesh(NULL, &shape), RES_BAD_ARG);
CHECK(ssol_shape_create_mesh(dev, &shape), RES_OK);
+ CHECK(ssol_shape_get_id(NULL, NULL), RES_BAD_ARG);
+ CHECK(ssol_shape_get_id(shape, NULL), RES_BAD_ARG);
+ CHECK(ssol_shape_get_id(NULL, &id), RES_BAD_ARG);
+ CHECK(ssol_shape_get_id(shape, &id), RES_OK);
+
CHECK(ssol_shape_ref_get(NULL), RES_BAD_ARG);
CHECK(ssol_shape_ref_get(shape), RES_OK);