Changeset 1130 for cpp/frams/genetics


Ignore:
Timestamp:
04/16/21 15:55:34 (3 years ago)
Author:
Maciej Komosinski
Message:

Used std::min(), std::max() explicitly to avoid compiler confusion. Used std::size() explicitly instead of the equivalent macro

Location:
cpp/frams/genetics
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f1/f1_conv.cpp

    r1039 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#include "f1_conv.h"
    6 #include <common/nonstd_stl.h>
    76#include <common/log.h>
    87#include <frams/util/multirange.h>
     
    1110#include <ctype.h>
    1211#include <assert.h>
     12#include <algorithm>
    1313
    1414//#define v1f1COMPATIBLE //as in ancient Framsticks 1.x
     
    273273int Builder::growJoint(int part1, int part2, Pt3D &angle, GeneProps &c, const char *g)
    274274{
    275         double len = min(2.0, c.length);
     275        double len = std::min(2.0, c.length);
    276276        sprintf(tmp, "p1=%d,p2=%d,dx=%lg,rx=%lg,ry=%lg,rz=%lg,stam=%lg,vr=%g,vg=%g,vb=%g",
    277277                part1, part2, len, angle.x, angle.y, angle.z, c.stamina, c.cred, c.cgreen, c.cblue);
  • cpp/frams/genetics/f9/f9_conv.cpp

    r1108 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66#include <frams/model/model.h>
    77#include <string.h>
    8 #include <common/nonstd_stl.h> //ARRAY_LENGTH
    98
    109#define APPLY_DETERMINISTIC_BODY_NOISE //this genetic representation easily produces perfectly vertical sticks that would stay upright forever in simulation. In most cases such infinite perfection is not desired, so we make the construct less perfect by perturbing its coordinates.
     
    129128        static int g[] = { 0, 1, 1, 1, 0, 0 };
    130129        static int b[] = { 0, 0, 0, 1, 1, 1 };
    131         int maxind = ARRAY_LENGTH(r) - 1;
     130        int maxind = int(std::size(r)) - 1;
    132131
    133132        int joints_count = m.getJointCount();
  • cpp/frams/genetics/fB/fB_conv.cpp

    r973 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    77#include <frams/param/paramobj.h>
    88#include <vector>
     9#include <algorithm>
    910#include <frams/util/multimap.h>
    1011#include "fB_general.h"
     
    250251                                double mn, mx, def;
    251252                                par.getMinMaxDouble(propindex, mn, mx, def);
    252                                 par.setDouble(propindex, min(mx, max(mn, (mx - mn) * val + mn)));
     253                                par.setDouble(propindex, std::min(mx, std::max(mn, (mx - mn) * val + mn)));
    253254                        }
    254255                        propindex++;
  • cpp/frams/genetics/fB/fB_oper.cpp

    r999 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#include <frams/util/sstring.h>
    66#include <vector>
     7#include <algorithm>
    78#include <frams/param/param.h>
    89#include "fB_conv.h"
     
    461462        {
    462463                // get maximal count of genes from both parents
    463                 int maxgenecount = max(fB_GenoHelpers::geneCountNoNested(parent1),
     464                int maxgenecount = std::max(fB_GenoHelpers::geneCountNoNested(parent1),
    464465                        fB_GenoHelpers::geneCountNoNested(parent2));
    465466
  • cpp/frams/genetics/fF/fF_conv.cpp

    r994 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#include "fF_conv.h"
    66#include "fF_genotype.h"
    7 #include <common/nonstd_stl.h>
    87#include <common/Convert.h>
    98
  • cpp/frams/genetics/fF/fF_oper.cpp

    r974 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    4949        par.load(gene);
    5050        static const int propsToMutate[] = fF_PROPS_TO_MUTATE;
    51         int which = rndUint(ARRAY_LENGTH(propsToMutate));
     51        int which = rndUint(std::size(propsToMutate));
    5252        bool mutated_ok = GenoOperators::mutatePropertyNaive(par.param, propsToMutate[which]);
    5353        if (mutated_ok)
  • cpp/frams/genetics/fS/fS_general.cpp

    r1108 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 2019-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 2019-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1313#include "common/nonstd_math.h"
    1414#include <frams/model/geometry/part_distance_estimator.h>
     15#include <algorithm>
    1516
    1617int fS_Genotype::precision = 4;
  • cpp/frams/genetics/fS/fS_oper.cpp

    r1056 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 2019-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 2019-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    77#include "fS_oper.h"
    88#include "frams/util/rndutil.h"
     9#include <algorithm>
    910
    1011#define FIELDSTRUCT GenoOper_fS
     
    362363                        {
    363364                                // Remove the selected child
    364                                 swap(randomNode->children[selectedIndex], randomNode->children[childCount - 1]);
     365                                std::swap(randomNode->children[selectedIndex], randomNode->children[childCount - 1]);
    365366                                randomNode->children.pop_back();
    366367                                randomNode->children.shrink_to_fit();
     
    586587                        fS_Neuron *it = randomNode->neurons[rndUint(size)];
    587588                        geno.rearrangeNeuronConnections(it, SHIFT::LEFT);        // Important to rearrange the neurons before deleting
    588                         swap(it, randomNode->neurons.back());
     589                        std::swap(it, randomNode->neurons.back());
    589590                        randomNode->neurons.pop_back();
    590591                        randomNode->neurons.shrink_to_fit();
  • cpp/frams/genetics/fn/fn_conv.h

    r779 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    77
    88#include <frams/genetics/genoconv.h>
     9#include <common/nonstd_stl.h>
    910
    1011// The fn->f0 converter
  • cpp/frams/genetics/geneprops.cpp

    r1039 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#include "geneprops.h"
     6#include <algorithm>
    67
    78GeneProps GeneProps::standard_values;
     
    5455#ifdef v1f1COMPATIBLE
    5556        case 'L': length += (3.0 - length)*0.3;
    56                 length = min(length, Model::getMaxJoint().d.x); break;
     57                length = std::min(length, Model::getMaxJoint().d.x); break;
    5758#else
    5859        case 'L': length += (2.0 - length)*0.3; //2.0 is currently Model::getMaxJoint().d.x so min() does not limit the range
    59                 length = min(length, Model::getMaxJoint().d.x); break;
     60                length = std::min(length, Model::getMaxJoint().d.x); break;
    6061#endif
    6162        case 'l': length += (0.33 - length)*0.3;
    62                 length = max(length, Model::getMinJoint().d.x); break;
     63                length = std::max(length, Model::getMinJoint().d.x); break;
    6364
    6465        case 'W': weight += (2.0 - weight)*0.3;  break;
Note: See TracChangeset for help on using the changeset viewer.