From caf2100b5eb2d68885fb055a2e1c7c88dcbf2ff9 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Thu, 4 May 2017 15:18:48 +0200 Subject: [PATCH] YASim: code dedup in class Wing. --- src/FDM/YASim/Wing.cpp | 25 +++++++++++++------------ src/FDM/YASim/Wing.hpp | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/FDM/YASim/Wing.cpp b/src/FDM/YASim/Wing.cpp index 8bb242749..c5595636e 100644 --- a/src/FDM/YASim/Wing.cpp +++ b/src/FDM/YASim/Wing.cpp @@ -251,27 +251,19 @@ void Wing::compile() interp(_base, _tip, frac, pos); float chord = _chord * (1 - (1-_taper)*frac); + float weight = chord * segWid; + float twist = _twist * frac; Surface *s = newSurface(pos, _orient, chord, hasFlap0, hasFlap1, hasSlat, hasSpoiler); - SurfRec *sr = new SurfRec(); - sr->surface = s; - sr->weight = chord * segWid; - s->setTotalDrag(sr->weight); - s->setTwist(_twist * frac); - _surfs.add(sr); + addSurface(s, weight, twist); if(_mirror) { pos[1] = -pos[1]; s = newSurface(pos, _rightOrient, chord, hasFlap0, hasFlap1, hasSlat, hasSpoiler); - sr = new SurfRec(); - sr->surface = s; - sr->weight = chord * segWid; - s->setTotalDrag(sr->weight); - s->setTwist(_twist * frac); - _surfs.add(sr); + addSurface(s, weight, twist); } } } @@ -280,6 +272,15 @@ void Wing::compile() setIncidence(_incidence); } +void Wing::addSurface(Surface* s, float weight, float twist) +{ + SurfRec *sr = new SurfRec(); + sr->surface = s; + sr->weight = weight; + s->setTotalDrag(sr->weight); + s->setTwist(twist); + _surfs.add(sr); +} void Wing::setDragScale(float scale) { diff --git a/src/FDM/YASim/Wing.hpp b/src/FDM/YASim/Wing.hpp index a76ea04a1..e7496c61d 100644 --- a/src/FDM/YASim/Wing.hpp +++ b/src/FDM/YASim/Wing.hpp @@ -96,6 +96,7 @@ private: void calculateTip(); void calculateSpan(); void calculateMAC(); + void addSurface(Surface* s, float weight, float twist); struct SurfRec { Surface * surface; float weight; };