[poincare] Improve logarithm layout

Change-Id: I0bd84672b5e24389308e7d1fd8609056f25cf2d4
This commit is contained in:
Émilie Feral
2017-01-13 16:12:01 +01:00
parent 4007c6ef82
commit 8eed045315
3 changed files with 16 additions and 1 deletions

View File

@@ -21,7 +21,6 @@ public:
protected:
Expression ** m_args;
int m_numberOfArguments;
private:
const char * m_name;
};

View File

@@ -10,6 +10,7 @@ public:
Type type() const override;
Expression * cloneWithDifferentOperands(Expression ** newOperands,
int numberOfOperands, bool cloneOperands = true) const override;
ExpressionLayout * createLayout() const override;
};
#endif

View File

@@ -2,7 +2,12 @@
extern "C" {
#include <assert.h>
#include <math.h>
#include <stdlib.h>
}
#include "layout/horizontal_layout.h"
#include "layout/parenthesis_layout.h"
#include "layout/string_layout.h"
#include "layout/subscript_layout.h"
Logarithm::Logarithm() :
Function("log")
@@ -28,3 +33,13 @@ float Logarithm::approximate(Context& context) const {
}
return log10f(m_args[1]->approximate(context))/log10f(m_args[0]->approximate(context));
}
ExpressionLayout * Logarithm::createLayout() const {
if (m_numberOfArguments == 1) {
return Function::createLayout();
}
ExpressionLayout ** childrenLayouts = (ExpressionLayout **)malloc(2*sizeof(ExpressionLayout *));
childrenLayouts[0] = new SubscriptLayout(new StringLayout(m_name, strlen(m_name)), m_args[0]->createLayout());
childrenLayouts[1] = new ParenthesisLayout(m_args[1]->createLayout());
return new HorizontalLayout(childrenLayouts, 2);
}