LCOV - code coverage report
Current view: top level - pencil/include/geometry - geometry_point.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.57.0_covts Lines: 12 35 34.3 %
Date: 2024-04-07 11:14:42 Functions: 4 6 66.7 %

          Line data    Source code
       1             : /* File: geometry_point.inl; Copyright and License: see below */
       2             : 
       3             : #include "u8/u8_trace.h"
       4             : #include "u8/u8_log.h"
       5             : #include <assert.h>
       6             : #include <math.h>
       7             : 
       8           8 : static inline void geometry_point_init ( geometry_point_t *this_, double x, double y )
       9             : {
      10           8 :     (*this_).x = x;
      11           8 :     (*this_).y = y;
      12           8 : }
      13             : 
      14             : static inline void geometry_point_reinit ( geometry_point_t *this_, double x, double y )
      15             : {
      16             :     (*this_).x = x;
      17             :     (*this_).y = y;
      18             : }
      19             : 
      20             : static inline void geometry_point_copy ( geometry_point_t *this_, const geometry_point_t *original )
      21             : {
      22             :     assert( NULL != original );
      23             :     (*this_) = (*original);
      24             : }
      25             : 
      26             : static inline void geometry_point_replace ( geometry_point_t *this_, const geometry_point_t *original )
      27             : {
      28             :     assert( NULL != original );
      29             :     (*this_) = (*original);
      30             : }
      31             : 
      32             : static inline void geometry_point_destroy ( geometry_point_t *this_ )
      33             : {
      34             : }
      35             : 
      36           8 : static inline double geometry_point_get_x ( const geometry_point_t *this_ )
      37             : {
      38           8 :     return (*this_).x;
      39             : }
      40             : 
      41           8 : static inline double geometry_point_get_y ( const geometry_point_t *this_ )
      42             : {
      43           8 :     return (*this_).y;
      44             : }
      45             : 
      46           0 : static inline double geometry_point_calc_chess_distance ( const geometry_point_t *this_, const geometry_point_t *that )
      47             : {
      48           0 :     assert( NULL != that );
      49           0 :     return ( fabs( (*this_).x - (*that).x ) + fabs( (*this_).y - (*that).y ) );
      50             : }
      51             : 
      52             : static inline bool geometry_point_equals ( const geometry_point_t *this_, const geometry_point_t *that )
      53             : {
      54             :     assert( NULL != that );
      55             :     return ( ( fabs( (*this_).x - (*that).x ) + fabs( (*this_).y - (*that).y ) ) < 0.000000001 );
      56             : }
      57             : 
      58           0 : static inline geometry_direction_t geometry_point_get_direction ( const geometry_point_t *this_, const geometry_point_t *that )
      59             : {
      60           0 :     assert( NULL != that );
      61             :     geometry_direction_t result;
      62           0 :     if ( (*this_).x + 0.000000001 < (*that).x )
      63             :     {
      64             :         /* that is right of this_ */
      65           0 :         if ( (*this_).y + 0.000000001 < (*that).y )
      66             :         {
      67           0 :             result = GEOMETRY_DIRECTION_DOWN_RIGHT;
      68             :         }
      69           0 :         else if ( (*this_).y - 0.000000001 > (*that).y )
      70             :         {
      71           0 :             result = GEOMETRY_DIRECTION_UP_RIGHT;
      72             :         }
      73             :         else
      74             :         {
      75           0 :             result = GEOMETRY_DIRECTION_RIGHT;
      76             :         }
      77             :     }
      78           0 :     else if ( (*this_).x - 0.000000001 > (*that).x )
      79             :     {
      80             :         /* that is left of this_ */
      81           0 :         if ( (*this_).y + 0.000000001 < (*that).y )
      82             :         {
      83           0 :             result = GEOMETRY_DIRECTION_DOWN_LEFT;
      84             :         }
      85           0 :         else if ( (*this_).y - 0.000000001 > (*that).y )
      86             :         {
      87           0 :             result = GEOMETRY_DIRECTION_UP_LEFT;
      88             :         }
      89             :         else
      90             :         {
      91           0 :             result = GEOMETRY_DIRECTION_LEFT;
      92             :         }
      93             :     }
      94             :     else
      95             :     {
      96             :         /* that is x-equal to this_ */
      97           0 :         if ( (*this_).y + 0.000000001 < (*that).y )
      98             :         {
      99           0 :             result = GEOMETRY_DIRECTION_DOWN;
     100             :         }
     101           0 :         else if ( (*this_).y - 0.000000001 > (*that).y )
     102             :         {
     103           0 :             result = GEOMETRY_DIRECTION_UP;
     104             :         }
     105             :         else
     106             :         {
     107           0 :             result = GEOMETRY_DIRECTION_CENTER;
     108             :         }
     109             :     }
     110           0 :     return result;
     111             : }
     112             : 
     113           5 : static inline void geometry_point_shift ( geometry_point_t *this_, double delta_x, double delta_y )
     114             : {
     115           5 :     (*this_).x += delta_x;
     116           5 :     (*this_).y += delta_y;
     117           5 : }
     118             : 
     119             : static inline void geometry_point_trace ( const geometry_point_t *this_ )
     120             : {
     121             :     U8_TRACE_INFO( "geometry_point_t" );
     122             :     U8_TRACE_INFO_INT( "- x:", (*this_).x );
     123             :     U8_TRACE_INFO_INT( "- y:", (*this_).y );
     124             : }
     125             : 
     126             : 
     127             : /*
     128             : Copyright 2019-2024 Andreas Warnke
     129             : 
     130             : Licensed under the Apache License, Version 2.0 (the "License");
     131             : you may not use this file except in compliance with the License.
     132             : You may obtain a copy of the License at
     133             : 
     134             :     http://www.apache.org/licenses/LICENSE-2.0
     135             : 
     136             : Unless required by applicable law or agreed to in writing, software
     137             : distributed under the License is distributed on an "AS IS" BASIS,
     138             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     139             : See the License for the specific language governing permissions and
     140             : limitations under the License.
     141             : */

Generated by: LCOV version 1.16