mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 11:39:58 +02:00
[poincare] Rational::createLyt gives single CodePointLyt if possible
This reduces the size of created layouts, thus allowing more layouts to be created, as there is a limit on the number of layout in a lyout field
This commit is contained in:
@@ -96,8 +96,8 @@ public:
|
||||
// Serialization
|
||||
int serialize(char * buffer, int bufferSize) const;
|
||||
|
||||
//Layout
|
||||
HorizontalLayout createLayout() const;
|
||||
// Layout
|
||||
Layout createLayout() const;
|
||||
|
||||
// Approximation
|
||||
template<typename T> T approximate() const;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <poincare/integer.h>
|
||||
#include <poincare/code_point_layout.h>
|
||||
#include <poincare/ieee754.h>
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
@@ -202,9 +204,14 @@ int Integer::serialize(char * buffer, int bufferSize) const {
|
||||
|
||||
// Layout
|
||||
|
||||
HorizontalLayout Integer::createLayout() const {
|
||||
Layout Integer::createLayout() const {
|
||||
char buffer[k_maxNumberOfDigitsBase10];
|
||||
int numberOfChars = serialize(buffer, k_maxNumberOfDigitsBase10);
|
||||
assert(numberOfChars >= 1);
|
||||
if ((int)UTF8Decoder::CharSizeOfCodePoint(buffer[0]) == numberOfChars) {
|
||||
UTF8Decoder decoder = UTF8Decoder(buffer);
|
||||
return CodePointLayout::Builder(decoder.nextCodePoint());
|
||||
}
|
||||
return LayoutHelper::String(buffer, numberOfChars);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,11 +96,11 @@ Expression RationalNode::setSign(Sign s, Context * context, Preferences::Complex
|
||||
// Layout
|
||||
|
||||
Layout RationalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
HorizontalLayout numeratorLayout = signedNumerator().createLayout();
|
||||
Layout numeratorLayout = signedNumerator().createLayout();
|
||||
if (denominator().isOne()) {
|
||||
return numeratorLayout;
|
||||
}
|
||||
HorizontalLayout denominatorLayout = denominator().createLayout();
|
||||
Layout denominatorLayout = denominator().createLayout();
|
||||
return FractionLayout::Builder(numeratorLayout, denominatorLayout);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user