From 4f608d7d70548b3ecbd10f45045189467f748607 Mon Sep 17 00:00:00 2001 From: firleju Date: Wed, 12 Oct 2016 18:55:28 +0200 Subject: [PATCH] =?UTF-8?q?Przet=C5=82umaczone=20mctools.=20Pliki=20wyniko?= =?UTF-8?q?we.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- McZapkie/mctools.cpp | 367 +++++++++++++++++++++++++++++++++++++++++++ McZapkie/mctools.h | 106 +++++++++++++ 2 files changed, 473 insertions(+) create mode 100644 McZapkie/mctools.cpp create mode 100644 McZapkie/mctools.h diff --git a/McZapkie/mctools.cpp b/McZapkie/mctools.cpp new file mode 100644 index 00000000..65cd10cd --- /dev/null +++ b/McZapkie/mctools.cpp @@ -0,0 +1,367 @@ +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ +/* +MaSzyna EU07 - SPKS +Brakes. +Copyright (C) 2007-2014 Maciej Cierniak +*/ +#include "mctools.h" +#include +#include + +/*================================================*/ + +std::string Ups(std::string s) +{ + int jatka; + std::string swy; + + swy = ""; + { + long jatka_end = s.length() + 1; + for (jatka = 0; jatka < jatka_end; jatka++) + swy = swy + UpCase(s[jatka]); + } + return swy; +} /*=Ups=*/ + +int Max0(int x1, int x2) +{ + if (x1 > x2) + return x1; + else + return x2; +} + +int Min0(int x1, int x2) +{ + if (x1 < x2) + return x1; + else + return x2; +} + +double Max0R(double x1, double x2) +{ + double result; + if (x1 > x2) + Max0R = x1; + else + Max0R = x2; + return result; +} + +double Min0R(double x1, double x2) +{ + double result; + if (x1 < x2) + Min0R = x1; + else + Min0R = x2; + return result; +} + +int Sign(double x) +{ + if (x > 0) + return 1; + else if (x < 0) + return -1; + return 0; +} + +bool TestFlag(int Flag, int Value) +{ + if ((Flag & Value) == Value) + return true; + else + return false; +} + +bool SetFlag(int &Flag, int Value) +{ + return iSetFlag(Flag, Value); +} + +bool iSetFlag(int &Flag, int Value) +{ + if (Value > 0) + if ((Flag & Value) == 0) + { + Flag |= Value; + return true; // true, gdy było wcześniej 0 i zostało ustawione + } + if (Value < 0) + if ((Flag & abs(Value)) == abs(Value)) + { + Flag |= Value; // Value jest ujemne, czyli zerowanie flagi + return true; // true, gdy było wcześniej 1 i zostało wyzerowane + } + return false; +} + +bool FuzzyLogic(double Test, double Threshold, double Probability) +{ + if ((Test > Threshold) && (!DebugModeFlag)) + return + (Random < Probability * Threshold * 1.0 / Test) /*im wiekszy Test tym wieksza szansa*/; + else + return false; +} + +bool FuzzyLogicAI(double Test, double Threshold, double Probability) +{ + if ((Test > Threshold)) + return + (Random < Probability * Threshold * 1.0 / Test) /*im wiekszy Test tym wieksza szansa*/; + else + return false; +} + +std::string ReadWord(std::ifstream &infile) +{ + std::string result; + std::string s; + char c; + bool nextword; + + s = ""; + nextword = false; + while ((!eof(infile)) && (!nextword)) + { + read(infile, c); + if (c in _Spacesigns) + if (s != "") + nextword = true; + if (!(c in _Spacesigns)) + s = s + c; + } + ReadWord = s; + return result; +} + +std::string Cut_Space(std::string s, int Just) +{ + std::string result; + unsigned char ii; + + switch (Just) + { + case CutLeft: + { + ii = 0; + while ((ii < length(s)) && (s[ii + 1] == _SPACE)) + ++ii; + s = Copy(s, ii + 1, length(s) - ii); + } + case CutRight: + { + ii = length(s); + while ((ii > 0) && (s[ii] == _SPACE)) + --ii; + s = Copy(s, 1, ii); + } + case CutBoth: + { + s = Cut_Space(s, CutLeft); + s = Cut_Space(s, CutRight); + } + } + Cut_Space = s; + return result; +} +/*Cut_Space*/ + +std::string ExtractKeyWord(std::string InS, std::string KeyWord) +{ + std::string result; + std::string s; + unsigned char kwp; + + InS = InS + " "; + kwp = Pos(KeyWord, InS); + if (kwp > 0) + { + s = Copy(InS, kwp, length(InS)); + s = Copy(s, 1, Pos(" ", s) - 1); + } + else + s = ""; + ExtractKeyWord = s; + return result; +} + +std::string DUE(std::string s) /*Delete Until Equal sign*/ +{ + std::string result; + DUE = Copy(s, Pos("=", s) + 1, length(s)); + return result; +} + +std::string DWE(std::string s) /*Delete While Equal sign*/ +{ + std::string result; + unsigned char ep; + + ep = Pos("=", s); + if (ep > 0) + DWE = Copy(s, 1, ep - 1); + else + DWE = s; + return result; +} + +std::string Ld2Sp(std::string s) /*Low dash to Space sign*/ +{ + std::string result; + unsigned char b; + std::string s2; + + s2 = ""; + { + long b_end = length(s) + 1; + for (b = 1; b < b_end; ++b) + if (s[b] == "_") + s2 = s2 + " "; + else + s2 = s2 + s[b]; + } + Ld2Sp = s2; + return result; +} + +std::string Tab2Sp(std::string s) /*Tab to Space sign*/ +{ + std::string result; + unsigned char b; + std::string s2; + + s2 = ""; + { + long b_end = length(s) + 1; + for (b = 1; b < b_end; ++b) + if (s[b] == (char)9) + s2 = s2 + " "; + else + s2 = s2 + s[b]; + } + Tab2Sp = s2; + return result; +} + +void ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double L, double dL, + double &phi, double &Xout, double &Yout) +/*wylicza polozenie Xout Yout i orientacje phi punktu na elemencie dL luku*/ +{ + double dX; + double dY; + double Xc; + double Yc; + double gamma; + double alfa; + double AbsR; + + if ((R != 0) && (L != 0)) + { + AbsR = abs(R); + dX = Xn - X0; + dY = Yn - Y0; + if (dX != 0) + gamma = atan(dY * 1.0 / dX); + else if (dY > 0) + gamma = Pi * 1.0 / 2; + else + gamma = 3 * Pi * 1.0 / 2; + alfa = L * 1.0 / R; + phi = gamma - (alfa + Pi * Round(R * 1.0 / AbsR)) * 1.0 / 2; + Xc = X0 - AbsR * cos(phi); + Yc = Y0 - AbsR * sin(phi); + phi = phi + alfa * dL * 1.0 / L; + Xout = AbsR * cos(phi) + Xc; + Yout = AbsR * sin(phi) + Yc; + } +} + +void ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double R, double &Xout, + double &Yout) +{ + double dX; + double dY; + double gamma; + double alfa; + /* pX,pY : real;*/ + + alfa = 0; // ABu: bo nie bylo zainicjowane + dX = Xn - X0; + dY = Yn - Y0; + if (dX != 0) + gamma = atan(dY * 1.0 / dX); + else if (dY > 0) + gamma = Pi * 1.0 / 2; + else + gamma = 3 * Pi * 1.0 / 2; + if (R != 0) + alfa = L * 1.0 / R; + Xout = X0 + L * cos(alfa * 1.0 / 2 - gamma); + Yout = Y0 + L * sin(alfa * 1.0 / 2 - gamma); +} + +/*graficzne:*/ + +double Xhor(double h) +{ + double result; + Xhor = h * Hstep + Xmin; + return result; +} + +double Yver(double v) +{ + double result; + Yver = (Vsize - v) * Vstep + Ymin; + return result; +} + +long Horiz(double x) +{ + long result; + x = (x - Xmin) * 1.0 / Hstep; + if (x > -MaxInt) + if (x < MaxInt) + Horiz = Round(x); + else + Horiz = MaxInt; + else + Horiz = -MaxInt; + return result; +} + +long Vert(double Y) +{ + long result; + Y = (Y - Ymin) * 1.0 / Vstep; + if (Y > -MaxInt) + if (Y < MaxInt) + Vert = Vsize - Round(Y); + else + Vert = MaxInt; + else + Vert = -MaxInt; + return result; +} + +void ClearPendingExceptions() +// resetuje błędy FPU, wymagane dla Trunc() +{ + ; /*?*/ /* ASM + FNCLEX + ASM END */ +} + +// END diff --git a/McZapkie/mctools.h b/McZapkie/mctools.h new file mode 100644 index 00000000..b33b48ed --- /dev/null +++ b/McZapkie/mctools.h @@ -0,0 +1,106 @@ +#pragma once +#ifndef INCLUDED_MCTOOLS_H +#define INCLUDED_MCTOOLS_H + + +/* +This Source Code Form is subject to the +terms of the Mozilla Public License, v. +2.0. If a copy of the MPL was not +distributed with this file, You can +obtain one at +http://mozilla.org/MPL/2.0/. +*/ + +/*rozne takie duperele do operacji na stringach w paszczalu, pewnie w delfi sa lepsze*/ +/*konwersja zmiennych na stringi, funkcje matematyczne, logiczne, lancuchowe, I/O etc*/ + +#include +#include + + +/*Ra: te stałe nie są używane... + _FileName = ['a'..'z','A'..'Z',':','\','.','*','?','0'..'9','_','-']; + _RealNum = ['0'..'9','-','+','.','E','e']; + _Integer = ['0'..'9','-']; //Ra: to się gryzie z STLport w Builder 6 + _Plus_Int = ['0'..'9']; + _All = [' '..'ţ']; + _Delimiter= [',',';']+_EOL; + _Delimiter_Space=_Delimiter+[' ']; +*/ +static char _EOL[2] = { (char)13, (char)10 }; + //static char const _SPACE = " "; // to jest w +static char _Spacesigns[5] = { " ",_SPACE,(char)9, (char)13, (char)10}; + static int const CutLeft = -1; + static int const CutRight = 1; + static int const CutBoth = 0; /*Cut_Space*/ + + + int ConversionError = 0; + int LineCount = 0; + bool DebugModeFlag = false; + bool FreeFlyModeFlag = false; + + + typedef unsigned long/*?*//*set of: char */ TableChar; /*MCTUTIL*/ + +/*konwersje*/ + +/*funkcje matematyczne*/ +int Max0(int x1, int x2); +int Min0(int x1, int x2); + +double Max0R(double x1, double x2); +double Min0R(double x1, double x2); + +int Sign(double x); + +/*funkcje logiczne*/ +bool TestFlag(int Flag, int Value); +bool SetFlag( int & Flag, int Value); +bool iSetFlag( int & Flag, int Value); + +bool FuzzyLogic(double Test, double Threshold, double Probability); +/*jesli Test>Threshold to losowanie*/ +bool FuzzyLogicAI(double Test, double Threshold, double Probability); +/*to samo ale zawsze niezaleznie od DebugFlag*/ + +/*operacje na stringach*/ +std::string ReadWord( std::ifstream & infile); /*czyta slowo z wiersza pliku tekstowego*/ +std::string Ups(std::string s); +std::string Cut_Space(std::string s, int Just); +std::string ExtractKeyWord(std::string InS, std::string KeyWord); /*wyciaga slowo kluczowe i lancuch do pierwszej spacji*/ +std::string DUE(std::string s); /*Delete Until Equal sign*/ +std::string DWE(std::string s); /*Delete While Equal sign*/ +std::string Ld2Sp(std::string s); /*Low dash to Space sign*/ +std::string Tab2Sp(std::string s); /*Tab to Space sign*/ + +/*procedury, zmienne i funkcje graficzne*/ +void ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double L, double dL, double & phi, double & Xout, double & Yout); +/*wylicza polozenie Xout Yout i orientacje phi punktu na elemencie dL luku*/ +void ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double R, double & Xout, double & Yout); + + + + double Xmin; double Ymin; double Xmax; double Ymax; + double Xaspect; double Yaspect; + double Hstep; double Vstep; + int Vsize; int Hsize; + +double Xhor( double h); + /* Converts horizontal screen coordinate into real X-coordinate. */ + +double Yver( double v); + /* Converts vertical screen coordinate into real Y-coordinate. */ + +long Horiz(double x); + +long Vert(double Y); + +void ClearPendingExceptions(); + +/*------------------------------------------------*/ + + +#endif//INCLUDED_MCTOOLS_H +//END