commit 08a8704f86979b3821b3672e1445842ee84bad55
parent 2183a704e5553ca8088b57207c1c48c5fdd969e6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 6 Dec 2016 12:19:54 +0100
Fix the polyclip file format
Replace the list of 3D vertices by a list of 2D positions.
Diffstat:
3 files changed, 91 insertions(+), 20 deletions(-)
diff --git a/doc/input b/doc/input
@@ -22,7 +22,7 @@
focal: 1
clip:
- operation: SUB
- vertices: [ [1, 2, 3], [3, 4, 5], [6, 7, 8] ]
+ vertices: [ [1, 2], [3, 4], [6, 7] ]
# Create the solar factory
- entity:
@@ -174,10 +174,10 @@
vertices: <vertices-list>
<vertices-list> ::=
- - <real3>
- - <real3>
- - <real3>
-[ - <real3> ... ]
+ - <real2>
+ - <real2>
+ - <real2>
+[ - <real2> ... ]
----------------------------------------
<material> ::=
@@ -259,6 +259,10 @@
translation: <real3>
rotation: <real3>
+<real2> ::=
+ - REAL
+ - REAL
+
<real3> ::=
- REAL
- REAL
diff --git a/src/parser/solparser.c b/src/parser/solparser.c
@@ -377,35 +377,36 @@ error:
}
static res_T
-parse_real3
+parse_realX
(struct solparser* parser,
yaml_document_t* doc,
- const yaml_node_t* real3,
+ const yaml_node_t* realX,
const double lower_bound,
const double upper_bound,
- double dst[3])
+ const size_t dim,
+ double dst[])
{
intptr_t i, n;
res_T res = RES_OK;
- ASSERT(doc && real3 && dst);
+ ASSERT(doc && realX && dst && dim > 0);
- if(real3->type != YAML_SEQUENCE_NODE) {
- log_err(parser, real3, "expect a sequence of 3 reals.\n");
+ if(realX->type != YAML_SEQUENCE_NODE) {
+ log_err(parser, realX, "expect a sequence of 3 reals.\n");
res = RES_BAD_ARG;
goto error;
}
- n = real3->data.sequence.items.top - real3->data.sequence.items.start;
- if(n != 3) {
- log_err(parser, real3, "expect 3 reals while `%li' %s submitted.\n",
- n, n > 1 ? "are" : "is");
+ n = realX->data.sequence.items.top - realX->data.sequence.items.start;
+ if((size_t)n != dim) {
+ log_err(parser, realX, "expect %lu reals while `%li' %s submitted.\n",
+ (unsigned long)dim, n, n > 1 ? "are" : "is");
res = RES_BAD_ARG;
goto error;
}
FOR_EACH(i, 0, n) {
yaml_node_t* real;
- real = yaml_document_get_node(doc, real3->data.sequence.items.start[i]);
+ real = yaml_document_get_node(doc, realX->data.sequence.items.start[i]);
res = parse_real(parser, real, lower_bound, upper_bound, dst + i);
if(res != RES_OK) goto error;
}
@@ -416,6 +417,30 @@ error:
goto exit;
}
+static FINLINE res_T
+parse_real3
+ (struct solparser* parser,
+ yaml_document_t* doc,
+ const yaml_node_t* real3,
+ const double lower_bound,
+ const double upper_bound,
+ double dst[3])
+{
+ return parse_realX(parser, doc, real3, lower_bound, upper_bound, 3, dst);
+}
+
+static FINLINE res_T
+parse_real2
+ (struct solparser* parser,
+ yaml_document_t* doc,
+ const yaml_node_t* real2,
+ const double lower_bound,
+ const double upper_bound,
+ double dst[2])
+{
+ return parse_realX(parser, doc, real2, lower_bound, upper_bound, 2, dst);
+}
+
static res_T
parse_integer
(struct solparser* parser,
@@ -1083,7 +1108,7 @@ parse_vertices
goto error;
}
- res = darray_double_resize(coords, (size_t)n*3/*#coords per vertex*/);
+ res = darray_double_resize(coords, (size_t)n*2/*#coords per vertex*/);
if(res != RES_OK) {
log_err(parser, vertices, "could not allocate the array of vertices.\n");
goto error;
@@ -1091,10 +1116,10 @@ parse_vertices
FOR_EACH(i, 0, n) {
yaml_node_t* vertex;
- double* real3 = darray_double_data_get(coords) + i*3/*#coords per vertex*/;
+ double* real2 = darray_double_data_get(coords) + i*2/*#coords per vertex*/;
vertex = yaml_document_get_node(doc, vertices->data.sequence.items.start[i]);
- res = parse_real3(parser, doc, vertex, -DBL_MAX, DBL_MAX, real3);
+ res = parse_real2(parser, doc, vertex, -DBL_MAX, DBL_MAX, real2);
if(res != RES_OK) goto error;
}
diff --git a/src/parser/solparser_shape.h b/src/parser/solparser_shape.h
@@ -79,6 +79,29 @@ solparser_polyclip_copy_and_release
return darray_double_copy_and_release(&dst->vertices, &src->vertices);
}
+static INLINE size_t
+solparser_polyclip_get_vertices_count
+ (const struct solparser_polyclip* polyclip)
+{
+ size_t n;
+ ASSERT(polyclip);
+ n = darray_double_size_get(&polyclip->vertices);
+ ASSERT((n % 2/*#coords per vertex*/) == 0);
+ return n / 2/*#coords per vertex*/;
+}
+
+static INLINE void
+solparser_polyclip_get_vertex
+ (const struct solparser_polyclip* polyclip,
+ const size_t ivert,
+ double pos[2])
+{
+ ASSERT(polyclip && ivert < solparser_polyclip_get_vertices_count(polyclip));
+ pos[0] = darray_double_cdata_get(&polyclip->vertices)[ivert*2+0];
+ pos[1] = darray_double_cdata_get(&polyclip->vertices)[ivert*2+1];
+}
+
+
/* Declare the array of clipping polygons */
#define DARRAY_NAME polyclip
#define DARRAY_DATA struct solparser_polyclip
@@ -135,7 +158,8 @@ solparser_shape_imported_geometry_copy_and_release
******************************************************************************/
struct solparser_shape_paraboloid {
double focal;
- struct darray_polyclip polyclips;
+ /* Internal data. Should not be accessed directly */
+ struct darray_polyclip polyclips;
};
static INLINE void
@@ -174,6 +198,24 @@ solparser_shape_paraboloid_copy_and_release
return darray_polyclip_copy_and_release(&dst->polyclips, &src->polyclips);
}
+static INLINE size_t
+solparser_shape_paraboloid_get_polyclips_count
+ (const struct solparser_shape_paraboloid* paraboloid)
+{
+ ASSERT(paraboloid);
+ return darray_polyclip_size_get(¶boloid->polyclips);
+}
+
+static INLINE const struct solparser_polyclip*
+solparser_shape_paraboloid_get_polyclip
+ (const struct solparser_shape_paraboloid* paraboloid,
+ const size_t i)
+{
+ ASSERT(paraboloid);
+ ASSERT(i < solparser_shape_paraboloid_get_polyclips_count(paraboloid));
+ return darray_polyclip_cdata_get(¶boloid->polyclips) + i;
+}
+
/*******************************************************************************
* Plane shape
******************************************************************************/