commit 638f759b9cf717f826b80291c60f330ad3eae652
parent 208abec3476f66e8abd67137432912a28d98a588
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 13 Jan 2017 14:59:35 +0100
Merge remote-tracking branch 'origin/master' into receiver
Diffstat:
8 files changed, 352 insertions(+), 169 deletions(-)
diff --git a/cmake/parser/CMakeLists.txt b/cmake/parser/CMakeLists.txt
@@ -49,7 +49,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
endif()
add_library(solparser STATIC ${SOLPARSER_FILES_SRC} ${SOLPARSER_FILES_INC})
-target_link_libraries(solparser ${MATH_LIB})
+target_link_libraries(solparser LibYAML ${MATH_LIB})
################################################################################
# Tests
@@ -76,13 +76,12 @@ if(NOT NO_TEST)
${SOLPARSER_SOURCE_DIR}/yaml/test_ok_2.yaml)
add_test(test_solparser_ok_2 test_solparser
${SOLPARSER_SOURCE_DIR}/yaml/test_ok_3.yaml)
-# TODO rewrite them wrt the update of the input specification
-# add_test(test_solstice_parser_ko_0 test_solstice_parser -e
-# ${SOLSTICE_SOURCE_DIR}/yaml/test_ko_0.yaml)
-# add_test(test_solstice_parser_ko_1 test_solstice_parser -e
-# ${SOLSTICE_SOURCE_DIR}/yaml/test_ko_1.yaml)
-# add_test(test_solstice_parser_ko_2 test_solstice_parser -e
-# ${SOLSTICE_SOURCE_DIR}/yaml/test_ko_2.yaml)
+ add_test(test_solstice_parser_ko_0 test_solparser -e
+ ${SOLPARSER_SOURCE_DIR}/yaml/test_ko_0.yaml)
+ add_test(test_solstice_parser_ko_1 test_solparser -e
+ ${SOLPARSER_SOURCE_DIR}/yaml/test_ko_1.yaml)
+ add_test(test_solstice_parser_ko_2 test_solparser -e
+ ${SOLPARSER_SOURCE_DIR}/yaml/test_ko_2.yaml)
new_test(test_solparser2)
new_test(test_solparser3)
diff --git a/doc/input b/doc/input
@@ -242,7 +242,7 @@
<spectrum>
[ <radial-angular-distribution> ]
-<radia-angular-distribution> ::=
+<radial-angular-distribution> ::=
<pillbox> | <buie>
<buie> ::=
diff --git a/src/parser/solparser.c b/src/parser/solparser.c
@@ -364,9 +364,23 @@ parse_real
goto error;
}
- if(*dst < lower_bound || *dst > upper_bound) {
- log_err(parser, real, "%g is not in [%g, %g].\n",
- *dst, lower_bound, upper_bound);
+ if (*dst < lower_bound || *dst > upper_bound) {
+ double l = nextafter(lower_bound, -DBL_MAX);
+ double u = nextafter(upper_bound, DBL_MAX);
+ int l_excluded = (l == (double) (int) l);
+ int u_excluded = (u == (double) (int) u);
+ if (l_excluded && u_excluded)
+ log_err(parser, real, "%g is not in ]%g, %g[.\n",
+ *dst, l, u);
+ else if (l_excluded)
+ log_err(parser, real, "%g is not in ]%g, %g].\n",
+ *dst, l, upper_bound);
+ else if (u_excluded)
+ log_err(parser, real, "%g is not in [%g, %g[.\n",
+ *dst, lower_bound, u);
+ else
+ log_err(parser, real, "%g is not in [%g, %g].\n",
+ *dst, lower_bound, upper_bound);
res = RES_BAD_ARG;
goto error;
}
@@ -558,6 +572,11 @@ parse_transform
} else if(!strcmp((char*)key->data.scalar.value, "rotation")) {
SETUP_MASK(ROTATION, "rotation");
res = parse_real3(parser, doc, val, -DBL_MAX, DBL_MAX, rotation);
+ if(res == RES_OK) {
+ rotation[0] = MDEG2RAD(rotation[0]);
+ rotation[1] = MDEG2RAD(rotation[1]);
+ rotation[2] = MDEG2RAD(rotation[2]);
+ }
} else {
log_err(parser, key, "unknown transform parameter `%s'.\n",
key->data.scalar.value);
@@ -1298,7 +1317,7 @@ parse_cuboid
goto error;
}
mask |= BIT(SIZE);
- res = parse_real3(parser, doc, val, 0, DBL_MAX, shape->size);
+ res = parse_real3(parser, doc, val, nextafter(0, 1), DBL_MAX, shape->size);
} else {
log_err(parser, key, "unknown cuboid parameter `%s'.\n",
key->data.scalar.value);
@@ -3062,7 +3081,7 @@ solparser_load(struct solparser* parser)
}
if(!parser->sun_key) {
- log_err(parser, root, "%s: no sun definition in the document.\n");
+ log_err(parser, root, "no sun definition in the document.\n");
res = RES_BAD_ARG;
goto error;
}
diff --git a/src/parser/test_solparser2.c b/src/parser/test_solparser2.c
@@ -166,7 +166,9 @@ main(int argc, char** argv)
entity_id = solparser_entity_get_child(entity, 1);
entity1b = solparser_get_entity(parser, entity_id);
CHECK(d3_eq(entity1b->translation, d3_splat(tmp, 0)), 1);
- CHECK(d3_eq(entity1b->rotation, d3(tmp, 3.14, 0, -1)), 1);
+ tmp[0] = MDEG2RAD(3.14);
+ tmp[2] = MDEG2RAD(-1);
+ CHECK(d3_eq_eps(entity1b->rotation, tmp, 1.e-6), 1);
CHECK(strcmp("lvl1b", str_cget(&entity1b->name)), 0);
CHECK(solparser_entity_get_children_count(entity1b), 1);
CHECK(entity1b->type, SOLPARSER_ENTITY_GEOMETRY);
diff --git a/src/parser/yaml/test_ko_0.yaml b/src/parser/yaml/test_ko_0.yaml
@@ -1,164 +1,318 @@
-instance:
- object:
- material: { matte: { reflectivity: -1 } }
- cuboid: { size: [1, 2, 3] }
----
-- instance:
- object:
- material: { matte: { reflectivity: -1 } }
- cuboid: { size: [1, 2, 3] }
----
-- instance:
- object:
- cuboid: { size: [1, 2, 3] }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [1, 2, 3] }
- sphere: { radius: 1 }
----
-- instance:
- object:
- transform:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [1, 2, 3] }
----
-- instance:
- object:
- material: { matte: }
- cuboid: { size: [1, 2, 3] }
----
-- instance:
- object:
- material:
- cuboid: { size: [1, 2, 3] }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: { x: 0, y: 1, z: 2} }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid:
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [ 0, 1 ] }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [ 0, 1, 3, 4 ] }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [ 0, 1, 3 ] }
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [ 0, 1, 3 ] }
----
-- instance:
- transform: { translation: [ 1, 2, 0 ] }
- transform: { translation: [ 3, 4, 4 ] }
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [1, 2, 3] }
+# unknown item dummy
+- dummy:
+ geometry:
+ - cuboid: { size: [1, 2, 3] }
+ material: { matte: { reflectivity: -1 } }
+---
+# missing spectrum
+- sun: { dni: 1 }
+---
+# missing dni
+- sun: { spectrum: [{wavelength: 1, data: 1}] }
+---
+# missing wavelength
+- sun: { dni: 1, spectrum: [{data: 1}] }
+---
+# missing data
+- sun: { dni: 1, spectrum: [{wavelength: 1}] }
+---
+# unknown dummy parameter
+- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}], dummy: { aperture: 1} }
+---
+# missing pillbox definition
+- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}], pillbox: }
+---
+# missing aperture value
+- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}], pillbox: { aperture: } }
+---
+# -1 invalid
+- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}], pillbox: { aperture: -1} }
+---
+# unknown aperture parameter
+- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}], buie: { aperture: 1} }
+---
+# 1 invalid
+- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}], buie: { csr: 1} }
+---
+# -1 invalid
+- sun: { dni: -1, spectrum: [{wavelength: 1, data: 1}] }
+---
+# -1 invalid
+- sun: { dni: 1, spectrum: [{wavelength: -1, data: 1}] }
+---
+# -1 invalid
+- sun: { dni: 1, spectrum: [{wavelength: 1, data: -1}] }
+---
+- entity:
+ # missing transform parameters
+ transform:
+---
+- entity:
+ transform:
+ # missing rotation parameters
+ rotation:
+---
+- entity:
+ transform:
+ # missing translation parameters
+ translation:
+---
+- entity:
+ transform:
+ # 2x translation
+ translation: [ -4, 5.2, -6.5 ]
+ translation: [ -4, 5.2, -6.5 ]
+---
+- entity:
+ transform:
+ # translation should have 3 parameters
+ translation: [ -4, 5.2 ]
+---
+- entity:
+ transform:
+ # translation should have 3 parameters
+ translation: [ -4, 5.2,0 ,1 ]
+---
+- entity:
+ transform:
+ # 2x rotation
+ rotation: [ -4, 5.2, -6.5 ]
+ rotation: [ -4, 5.2, -6.5 ]
+---
+- entity:
+ transform:
+ # rotation should have 3 parameters
+ rotation: [ -4, 5.2 ]
+---
+- entity:
+ transform:
+ # rotation should have 3 parameters
+ rotation: [ -4, 5.2,0 ,1 ]
+---
+- entity:
+ # 2x transform
+ transform:
+ rotation: [ -4, 5.2, 1 ]
+ transform:
+ rotation: [ -4, 5.2, 1 ]
+---
+- entity:
+ # missing object(s)
+ geometry:
+---
+- entity:
+ geometry:
+ # missing transform parameters
+ - transform:
+---
+- entity:
+ geometry:
+ - transform:
+ # missing rotation parameters
+ rotation:
+---
+- entity:
+ geometry:
+ - transform:
+ # missing translation parameters
+ translation:
+---
+- entity:
+ geometry:
+ - transform:
+ # 2x translation
+ translation: [ -4, 5.2, -6.5 ]
+ translation: [ -4, 5.2, -6.5 ]
---
-- instance:
- transform: { translation: [ 3, 4, 4 ] }
+- entity:
+ geometry:
+ - transform:
+ # translation should have 3 parameters
+ translation: [ -4, 5.2 ]
---
-- instance:
- object:
- material: { matte: { reflectivity: } }
- cuboid: { size: [ 0, 1, 3 ] }
+- entity:
+ geometry:
+ - transform:
+ # translation should have 3 parameters
+ translation: [ -4, 5.2,0 ,1 ]
---
-- instance:
- object:
- material: { matte: { reflectivity: 1, dummy: "none" } }
- cuboid: { size: [1, 2, 3] }
+- entity:
+ geometry:
+ - transform:
+ # 2x rotation
+ rotation: [ -4, 5.2, -6.5 ]
+ rotation: [ -4, 5.2, -6.5 ]
---
-- instance:
- object:
- material:
- matte: { reflectivity: 1 }
- dummy: 123
- cuboid: { size: [1, 2, 3] }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [1, 2, 3], dummy: 3.14 }
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [1, 2, 3] }
- dummy: 1
----
-- instance:
- object:
- material: { matte: { reflectivity: 1 } }
- cuboid: { size: [1, 2, 3] }
+- entity:
+ geometry:
+ - transform:
+ # rotation should have 3 parameters
+ rotation: [ -4, 5.2 ]
+---
+- entity:
+ geometry:
+ - transform:
+ # rotation should have 3 parameters
+ rotation: [ -4, 5.2,0 ,1 ]
+---
+- entity:
+ geometry:
+ # missing shape & material
+ - transform:
+ rotation: [ -4, 5.2, 1 ]
+---
+- entity:
+ geometry:
+ # missing size parameters
+ - cuboid: { size: }
+---
+- entity:
+ geometry:
+ # size should have 3 parameters
+ - cuboid: { size: [1, 2] }
+---
+- entity:
+ geometry:
+ # size should have 3 parameters
+ - cuboid: { size: [1, 2, 3, 4] }
+---
+- entity:
+ geometry:
+ # -1 invalid
+ - cuboid: { size: [-1, 2, 3] }
+---
+- entity:
+ geometry:
+ # 0 invalid
+ - cuboid: { size: [0, 2, 3] }
+---
+- entity:
+ geometry:
+ - cuboid: { size: [1, 2, 3] }
+ # missing material
+---
+- entity:
+ geometry:
+ # missing material definition
+ - material:
+---
+- entity:
+ geometry:
+ # missing matte parameters
+ - material: { matte: }
+---
+- entity:
+ geometry:
+ # missing reflectivity value
+ - material: { matte: { reflectivity: } }
+---
+- entity:
+ geometry:
+ - cuboid: { size: [1, 2, 3] }
+ # -1 invalid
+ material: { matte: { reflectivity: -1 } }
+---
+- entity:
+ geometry:
+ - material: { matte: { reflectivity: 1 } }
+ # missing shape definition
+---
+- entity:
+ # missing entity name
+ geometry:
+ - cuboid: { size: [1, 2, 3] }
+ material: { matte: { reflectivity: 1 } }
+---
+# missing sun
+- entity:
+ name: foo
+ geometry:
+ - cuboid: { size: [1, 2, 3] }
+ transform:
+ rotation: [ 0, 1, 2 ]
+ translation: [ -4, 5.2, -6.5 ]
+ material: { matte: { reflectivity: 1 } }
+---
+- entity:
+ geometry:
+ # unknown dummy parameter
+ - material: { matte: { reflectivity: 1, dummy: "none" } }
+---
+- entity:
+ geometry:
+ - material:
+ # unknown dummy parameter
+ matte: { reflectivity: 1 }
+ dummy: 123
+---
+- entity:
+ geometry:
+ # unknown dummy parameter
+ - cuboid: { size: [1, 2, 3], dummy: 3.14 }
+---
+- entity:
+ geometry:
+ - material: { matte: { reflectivity: 1 } }
+ cuboid: { size: [1, 2, 3] }
+ # unknown dummy parameter
+ dummy: 1
+---
+- entity:
+ geometry:
+ - material: { matte: { reflectivity: 1 } }
+ cuboid: { size: [1, 2, 3] }
+ # unknown dummy parameter
dummy: 1
---
- material: &front { matte: { reflectivity: 1 } }
- material: &back { matte: { reflectivity: 0.5 } }
-- object: &cuboid
- cuboid: { size: [1, 2, 3] }
- material:
- front: *front
- back: *back
- front: *front
-- instance: { object: *cuboid }
+- geometry: &cuboid
+ - cuboid: { size: [1, 2, 3] }
+ material:
+ # missing back description
+ front: *front
+- entity: { geometry: *cuboid }
---
- material: &front { matte: { reflectivity: 1 } }
- material: &back { matte: { reflectivity: 0.5 } }
-- object: &cuboid
- cuboid: { size: [1, 2, 3] }
- material:
- front: *front
-- instance: { object: *cuboid }
+- geometry: &cuboid
+ - cuboid: { size: [1, 2, 3] }
+ material:
+ # missing front description
+ back: *back
+- entity: { geometry: *cuboid }
---
- material: &front { matte: { reflectivity: 1 } }
- material: &back { matte: { reflectivity: 0.5 } }
-- object: &cuboid
- cuboid: { size: [1, 2, 3] }
- material:
- back: *back
-- instance: { object: *cuboid }
----
-- object: &cuboid
- cuboid: { size: [1, 2, 3] }
- material:
- front:
- matte: { reflectivity: 1 }
- dummy: 1
- back:
- material: { matte: { reflectivity: 0.1 } }
-- instance: { object: *cuboid }
----
-- object: &cuboid
- cuboid: { size: [1, 2, 3] }
- material:
- front:
- matte: { reflectivity: 1 }
- back:
- matte: { reflectivity: 0.1 }
- dummy: 1234
-- instance: { object: *cuboid }
+- geometry: &cuboid
+ - cuboid: { size: [1, 2, 3] }
+ material:
+ front: *front
+ back: *back
+ # 2x front
+ front: *front
+- entity: { geometry: *cuboid }
+---
+- geometry: &cuboid
+ - cuboid: { size: [1, 2, 3] }
+ material:
+ front:
+ matte: { reflectivity: 1 }
+ # unknown dummy parameter
+ dummy: 1
+ back:
+ material: { matte: { reflectivity: 0.1 } }
+- entity: { geometry: *cuboid }
+---
+- geometry: &cuboid
+ - cuboid: { size: [1, 2, 3] }
+ material:
+ front:
+ matte: { reflectivity: 1 }
+ back:
+ matte: { reflectivity: 0.1 }
+ # unknown dummy parameter
+ dummy: 1234
+- entity: { geometry: *cuboid }
diff --git a/src/solstice.c b/src/solstice.c
@@ -410,7 +410,7 @@ solstice_release(struct solstice* solstice)
clear_materials(&solstice->materials);
clear_objects(&solstice->objects);
clear_nodes(&solstice->roots);
- /* don't clear pivots, as they are cleared from some root */
+ /* Don't clear pivots, as they are cleared from some root */
if(solstice->ssol) SSOL(device_ref_put(solstice->ssol));
if(solstice->scene) SSOL(scene_ref_put(solstice->scene));
if(solstice->parser) solparser_ref_put(solstice->parser);
diff --git a/src/solstice_entity.c b/src/solstice_entity.c
@@ -271,7 +271,10 @@ solstice_setup_entities(struct solstice* solstice)
entity = solparser_get_entity(solstice->parser, entity_id);
root = create_node(solstice, entity);
- if(!root) goto error;
+ if(!root) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
/* Initialialised the world space position of the entity geometry */
res = sanim_node_visit_tree
diff --git a/src/solstice_object.c b/src/solstice_object.c
@@ -379,7 +379,7 @@ create_shaded_shape
/* Define the shape transformation */
d33_rotation(transform, obj->rotation[0], obj->rotation[1], obj->rotation[2]);
- d33_muld3(transform+9, transform, obj->translation);
+ d3_set(transform+9, obj->translation);
shape = solparser_get_shape(solstice->parser, obj->shape);
switch(shape->type) {
@@ -426,9 +426,12 @@ solstice_instantiate_geometry
struct ssol_instance** out_inst)
{
struct ssol_instance* inst = NULL;
+ struct ssol_material* front = NULL;
+ struct ssol_material* back = NULL;
struct ssol_object** pssol_obj = NULL;
struct ssol_object* ssol_obj = NULL;
struct ssol_object* ssol_obj_new = NULL;
+ struct ssol_shape* shape = NULL;
int is_attached_to_scn = 0;
int is_registered = 0;
res_T res = RES_OK;
@@ -452,9 +455,6 @@ solstice_instantiate_geometry
nobjs = solparser_geometry_get_objects_count(geom);
FOR_EACH(iobj, 0, nobjs) {
struct solparser_object_id obj_id;
- struct ssol_shape* shape = NULL;
- struct ssol_material* front;
- struct ssol_material* back;
obj_id = solparser_geometry_get_object(geom, iobj);
res = create_shaded_shape(solstice, obj_id, &front, &back, &shape);
@@ -472,6 +472,9 @@ solstice_instantiate_geometry
SSOL(shape_ref_put(shape));
SSOL(material_ref_put(front));
SSOL(material_ref_put(back));
+ shape = NULL;
+ front = NULL;
+ back = NULL;
}
}
@@ -504,6 +507,9 @@ error:
if(is_registered) htable_object_erase(&solstice->objects, &geom_id.i);
if(inst) SSOL(instance_ref_put(inst)), inst = NULL;
if(ssol_obj_new) SSOL(object_ref_put(ssol_obj_new));
+ if(shape) SSOL(shape_ref_put(shape));
+ if(front) SSOL(material_ref_put(front));
+ if(back) SSOL(material_ref_put(back));
goto exit;
}