testIsInside.cpp 5.36 KB
Newer Older
Weichen's avatar
Weichen committed
1 2 3
/**
 * \file        testIsInside.cpp
 * \date        Jul 4, 2014
4 5
 * \version     v0.7
 * \copyright   <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
Weichen's avatar
Weichen committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * \section License
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * JuPedSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
 * \section Description
 *
 *
 **/
 
 
Mohcine Chraibi's avatar
Mohcine Chraibi committed
29 30 31 32 33 34
#include <cstdlib>
#include <stdio.h>
#include "../pedestrian/Ellipse.h"

//#include "Config.h"

35
#if defined(_WIN64) || defined(_WIN32)
Mohcine Chraibi's avatar
Mohcine Chraibi committed
36
#include <direct.h>
37
#define GetCurrentDir _getcwd
Mohcine Chraibi's avatar
Mohcine Chraibi committed
38 39
#else
#include <unistd.h>
40 41
#define GetCurrentDir getcwd
#endif
Mohcine Chraibi's avatar
Mohcine Chraibi committed
42 43 44 45 46 47 48 49

OutputHandler* Log;


//int testPointOnEllipse(int argc, char* argv[])
int testIsInside()
{

50 51 52 53 54 55 56 57 58 59 60 61 62
     char cCurrentPath[FILENAME_MAX];
     if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath))) {
          return EXIT_FAILURE;
     }
     cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */

     FILE * f;
     char fname[FILENAME_MAX] = "log_testIsInside.txt";
     // strcpy(fname, cCurrentPath);
     // strcat(fname, "logs/log_testPointOnEllipse.txt");
     f = fopen(fname, "w");
     fprintf (f, "The current working directory is %s\n\n", cCurrentPath);
     int ntests=0, res=0;
63
     float a=2.0, b=10.0;
64 65 66 67 68 69 70
     JEllipse E;
     Point P;
     //double px, py;
     E.SetCenter( Point(0,0) );
     E.SetV0(1);
     E.SetV( Point(0,0) );
     E.SetAmin(a);
71
     E.SetBmax(b);
72
     // P == E.center
73 74
     P._x = (0);
     P._y = (0);
75 76
     res += ( E.IsInside(P) == true)?1:0;
     ntests++;
77
     fprintf (f, "%3d. E(%-4.2f, %-4.2f), a=%-4.2f, b=%-4.2f, P(%4.2f, %4.2f)    res=%-3d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
78 79
     // P ~ E.center

80 81
     P._x = (0.);
     P._y = (-0.3);
82 83
     res += ( E.IsInside(P) == true)?1:0;
     ntests++;
84
     fprintf (f, "%3d. E(%-4.2f, %-4.2f), a=%-4.2f, b=%-4.2f, P(%4.2f, %4.2f)    res=%-3d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
85 86

     // P ~ E.center
87 88
     P._x = (-0.73);
     P._y = (-0.3);
89 90
     res += ( E.IsInside(P) == true)?1:0;
     ntests++;
91
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
92 93

     // P  semi-axis
94 95
     P._x = (a);
     P._y = (0);
96 97
     res += ( E.IsInside(P) == false)?1:0;
     ntests++;
98
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
99
     // P  semi-axis
100 101
     P._x = (-a);
     P._y = (0);
102 103
     res += ( E.IsInside(P) == false)?1:0;
     ntests++;
104
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
105 106

     // P ~ semi-axis
107 108
     P._x = (0);
     P._y = (b);
109 110
     res += ( E.IsInside(P) ==  false)?1:0;
     ntests++;
111
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
112 113

     // P ~ semi-axis
114 115
     P._x = (0);
     P._y = (-b);
116 117
     res += ( E.IsInside(P) == false)?1:0;
     ntests++;
118
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
119 120

     // P outside
121 122
     P._x = (a);
     P._y = (-b);
123 124
     res += ( E.IsInside(P) == false)?1:0;
     ntests++;
125
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
126 127

// P outside
128 129
     P._x = (2*a);
     P._y = (3.1*b);
130 131
     res += ( E.IsInside(P) == false)?1:0;
     ntests++;
132
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
133 134 135


// P outside
136 137
     P._x = (3*a);
     P._y = (-3.5*b);
138 139
     res += ( E.IsInside(P) == false)?1:0;
     ntests++;
140
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
141 142 143


// P outside
144 145
     P._x = (-5*a);
     P._y = (-2*b);
146 147
     res += ( E.IsInside(P) == false)?1:0;
     ntests++;
148
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
149 150 151


// P outside
152 153
     P._x = (-1.1*a);
     P._y = (-1.1*b);
154 155
     res += ( E.IsInside(P) == false)?1:0;
     ntests++;
156
     fprintf (f, "%3d. E(%3.2f, %3.2f), a=%3.2f, b=%3.2f, P(%3.2f, %3.2f)    res=%d\n",ntests, E.GetCenter()._x, E.GetCenter()._y, a, b, P._x, P._y, res);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
157 158 159

//-----------------------------------------------------------------

160 161 162

     fclose(f);
     return (res==ntests)?EXIT_SUCCESS:EXIT_FAILURE;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
163 164
}

165
int main()
Mohcine Chraibi's avatar
Mohcine Chraibi committed
166
{
167 168
     //   fprintf(stdout, "%s Version %d.%d\n", argv[0], JPSCORE_MINOR_VERSION, JPSCORE_MAJOR_VERSION);
     return testIsInside();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
169
}