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_pivot.h (3916B)


      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_PIVOT_H
     18 #define SOLPARSER_PIVOT_H
     19 
     20 #include <rsys/double3.h>
     21 
     22 /*******************************************************************************
     23  * Anchor
     24  ******************************************************************************/
     25 struct solparser_anchor_id { size_t i; };
     26 
     27 struct solparser_anchor {
     28   struct str name;
     29   double position[3];
     30 };
     31 
     32 static INLINE void
     33 solparser_anchor_init
     34   (struct mem_allocator* allocator, struct solparser_anchor* anchor)
     35 {
     36   ASSERT(anchor);
     37   str_init(allocator, &anchor->name);
     38 }
     39 
     40 static INLINE void
     41 solparser_anchor_release(struct solparser_anchor* anchor)
     42 {
     43   ASSERT(anchor);
     44   str_release(&anchor->name);
     45 }
     46 
     47 static INLINE res_T
     48 solparser_anchor_copy
     49   (struct solparser_anchor* dst, const struct solparser_anchor* src)
     50 {
     51   ASSERT(dst && src);
     52   d3_set(dst->position, src->position);
     53   return str_copy(&dst->name, &src->name);
     54 }
     55 
     56 static INLINE res_T
     57 solparser_anchor_copy_and_release
     58   (struct solparser_anchor* dst, struct solparser_anchor* src)
     59 {
     60   ASSERT(dst && src);
     61   d3_set(dst->position, src->position);
     62   return str_copy_and_release(&dst->name, &src->name);
     63 }
     64 
     65 /*******************************************************************************
     66  * Target
     67  ******************************************************************************/
     68 enum solparser_target_type {
     69   SOLPARSER_TARGET_ANCHOR,
     70   SOLPARSER_TARGET_DIRECTION,
     71   SOLPARSER_TARGET_POSITION,
     72   SOLPARSER_TARGET_SUN,
     73 
     74   SOLPARSER_TARGET_TYPES_COUNT__
     75 };
     76 
     77 struct solparser_target {
     78   enum solparser_target_type type;
     79   union {
     80     double position[3]; /* World space position */
     81     double direction[3]; /* World space direction */
     82     struct solparser_anchor_id anchor;
     83   } data;
     84 };
     85 #define SOLPARSER_TARGET_NULL__ { 0 }
     86 static const struct solparser_target SOLPARSER_TARGET_NULL =
     87   SOLPARSER_TARGET_NULL__;
     88 
     89 
     90 /*******************************************************************************
     91  * X pivot
     92  ******************************************************************************/
     93 struct solparser_pivot_id { size_t i; };
     94 
     95 struct solparser_x_pivot {
     96   double ref_point[3];
     97   struct solparser_target target;
     98 };
     99 
    100 #define SOLPARSER_X_PIVOT_NULL__ { {0,0,0}, SOLPARSER_TARGET_NULL__ }
    101 static const struct solparser_x_pivot SOLPARSER_X_PIVOT_NULL =
    102   SOLPARSER_X_PIVOT_NULL__;
    103 
    104 static INLINE void
    105 solparser_x_pivot_init
    106   (struct mem_allocator* allocator, struct solparser_x_pivot* x_pivot)
    107 {
    108   (void)allocator;
    109   ASSERT(x_pivot);
    110   *x_pivot = SOLPARSER_X_PIVOT_NULL;
    111 }
    112 
    113 /*******************************************************************************
    114  * ZX pivot
    115  ******************************************************************************/
    116 struct solparser_zx_pivot {
    117   double spacing;
    118   double ref_point[3];
    119   struct solparser_target target;
    120 };
    121 
    122 #define SOLPARSER_ZX_PIVOT_NULL__ { 0, {0,0,0}, SOLPARSER_TARGET_NULL__ }
    123 static const struct solparser_zx_pivot SOLPARSER_ZX_PIVOT_NULL =
    124   SOLPARSER_ZX_PIVOT_NULL__;
    125 
    126 static INLINE void
    127 solparser_zx_pivot_init
    128   (struct mem_allocator* allocator, struct solparser_zx_pivot* zx_pivot)
    129 {
    130   (void)allocator;
    131   ASSERT(zx_pivot);
    132   *zx_pivot = SOLPARSER_ZX_PIVOT_NULL;
    133 }
    134 
    135 #endif /* SOLPARSER_PIVOT_H */
    136