solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

solparser_geometry.h (2620B)


      1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2016-2018 CNRS
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #ifndef SOLPARSER_GEOMETRY_H
     18 #define SOLPARSER_GEOMETRY_H
     19 
     20 #include "solparser_material.h"
     21 #include "solparser_shape.h"
     22 
     23 #include <rsys/dynamic_array.h>
     24 
     25 struct solparser_object {
     26   struct solparser_material_double_sided_id mtl2;
     27   struct solparser_shape_id shape;
     28   double rotation[3]; /* In degrees */
     29   double translation[3];
     30 };
     31 
     32 struct solparser_object_id { size_t i; };
     33 
     34 #define DARRAY_NAME object_id
     35 #define DARRAY_DATA struct solparser_object_id
     36 #include <rsys/dynamic_array.h>
     37 
     38 struct solparser_geometry {
     39   /* Internal data. Should not be acceded directly. */
     40   struct darray_object_id objects;
     41 };
     42 
     43 struct solparser_geometry_id { size_t i; };
     44 
     45 static INLINE void
     46 solparser_geometry_init
     47   (struct mem_allocator* allocator, struct solparser_geometry* geom)
     48 {
     49   ASSERT(geom);
     50   darray_object_id_init(allocator, &geom->objects);
     51 }
     52 
     53 static INLINE void
     54 solparser_geometry_release(struct solparser_geometry* geom)
     55 {
     56   ASSERT(geom);
     57   darray_object_id_release(&geom->objects);
     58 }
     59 
     60 static INLINE res_T
     61 solparser_geometry_copy
     62   (struct solparser_geometry* dst, const struct solparser_geometry* src)
     63 {
     64   ASSERT(dst && src);
     65   return darray_object_id_copy(&dst->objects, &src->objects);
     66 }
     67 
     68 static INLINE res_T
     69 solparser_geometry_copy_and_release
     70   (struct solparser_geometry* dst, struct solparser_geometry* src)
     71 {
     72   ASSERT(dst && src);
     73   return darray_object_id_copy_and_release(&dst->objects, &src->objects);
     74 }
     75 
     76 static FINLINE size_t
     77 solparser_geometry_get_objects_count(const struct solparser_geometry* geom)
     78 {
     79   ASSERT(geom);
     80   return darray_object_id_size_get(&geom->objects);
     81 }
     82 
     83 static FINLINE struct solparser_object_id
     84 solparser_geometry_get_object
     85   (const struct solparser_geometry* geom, const size_t i)
     86 {
     87   ASSERT(geom && i < solparser_geometry_get_objects_count(geom));
     88   return darray_object_id_cdata_get(&geom->objects)[i];
     89 }
     90 
     91 #endif /* SOLPARSER_GEOMETRY_H */