mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare] Add Vector Norm Layout
Change-Id: Iae5bbeabaa0ca627ae6651f187d1a42b970df37d
This commit is contained in:
committed by
Émilie Feral
parent
8d2af7e77f
commit
3aa5e8bcd6
@@ -29,7 +29,7 @@ public:
|
||||
|
||||
private:
|
||||
KDCoordinate widthMargin() const override { return 2; }
|
||||
virtual KDCoordinate verticalExternMargin() const override { return 1; }
|
||||
KDCoordinate verticalExternMargin() const override { return 1; }
|
||||
bool renderTopBar() const override { return false; }
|
||||
bool renderBottomBar() const override { return false; }
|
||||
};
|
||||
|
||||
@@ -49,6 +49,7 @@ private:
|
||||
virtual KDCoordinate verticalExternMargin() const { return k_verticalExternMargin; }
|
||||
virtual bool renderTopBar() const { return true; }
|
||||
virtual bool renderBottomBar() const { return true; }
|
||||
virtual bool renderDoubleBar() const { return false; }
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart = nullptr, Layout * selectionEnd = nullptr, KDColor selectionColor = KDColorRed) override;
|
||||
};
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
RightParenthesisLayout,
|
||||
RightSquareBracketLayout,
|
||||
SumLayout,
|
||||
VectorNormLayout,
|
||||
VerticalOffsetLayout
|
||||
};
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ private:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
// Simplification
|
||||
Expression shallowReduce(ReductionContext reductionContext) override;
|
||||
LayoutShape leftLayoutShape() const override { return LayoutShape::MoreLetters; };
|
||||
LayoutShape rightLayoutShape() const override { return LayoutShape::BoundaryPunctuation; }
|
||||
LayoutShape leftLayoutShape() const override { return LayoutShape::BoundaryPunctuation; }
|
||||
// Evaluation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, complexFormat, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, complexFormat, angleUnit); }
|
||||
|
||||
46
poincare/include/poincare/vector_norm_layout.h
Normal file
46
poincare/include/poincare/vector_norm_layout.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef POINCARE_VECTOR_NORM_LAYOUT_NODE_H
|
||||
#define POINCARE_VECTOR_NORM_LAYOUT_NODE_H
|
||||
|
||||
#include <poincare/vector_norm.h>
|
||||
#include <poincare/bracket_pair_layout.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class VectorNormLayoutNode final : public BracketPairLayoutNode {
|
||||
public:
|
||||
using BracketPairLayoutNode::BracketPairLayoutNode;
|
||||
|
||||
// Layout
|
||||
Type type() const override { return Type::VectorNormLayout; }
|
||||
|
||||
// SerializationHelperInterface
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override {
|
||||
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, VectorNorm::s_functionHelper.name(), true);
|
||||
}
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(VectorNormLayoutNode); }
|
||||
#if POINCARE_TREE_LOG
|
||||
void logNodeName(std::ostream & stream) const override {
|
||||
stream << "VectorNormLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
KDCoordinate widthMargin() const override { return 2; }
|
||||
KDCoordinate verticalExternMargin() const override { return 1; }
|
||||
bool renderTopBar() const override { return false; }
|
||||
bool renderBottomBar() const override { return false; }
|
||||
bool renderDoubleBar() const override { return true; }
|
||||
};
|
||||
|
||||
class VectorNormLayout final : public Layout {
|
||||
public:
|
||||
static VectorNormLayout Builder(Layout child) { return TreeHandle::FixedArityBuilder<VectorNormLayout, VectorNormLayoutNode>({child}); }
|
||||
VectorNormLayout() = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <poincare/right_square_bracket_layout.h>
|
||||
#include <poincare/square_bracket_layout.h>
|
||||
#include <poincare/sum_layout.h>
|
||||
#include <poincare/vector_norm_layout.h>
|
||||
#include <poincare/vertical_offset_layout.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -114,22 +114,41 @@ int BracketPairLayoutNode::serialize(char * buffer, int bufferSize, Preferences:
|
||||
void BracketPairLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor, Layout * selectionStart, Layout * selectionEnd, KDColor selectionColor) {
|
||||
KDSize childSize = childLayout()->layoutSize();
|
||||
KDCoordinate verticalBarHeight = childSize.height() + 2*k_verticalMargin;
|
||||
ctx->fillRect(KDRect(p.x()+externWidthMargin(), p.y()+verticalExternMargin(), k_lineThickness, verticalBarHeight), expressionColor);
|
||||
ctx->fillRect(KDRect(p.x()+externWidthMargin()+childSize.width()+2*widthMargin()+k_lineThickness, p.y()+verticalExternMargin(), k_lineThickness, verticalBarHeight), expressionColor);
|
||||
KDCoordinate horizontalPosition = p.x() + externWidthMargin();
|
||||
KDCoordinate verticalPosition = p.y() + verticalExternMargin();
|
||||
if (renderDoubleBar()) {
|
||||
ctx->fillRect(KDRect(horizontalPosition, verticalPosition, k_lineThickness, verticalBarHeight), expressionColor);
|
||||
horizontalPosition += k_lineThickness + widthMargin();
|
||||
}
|
||||
ctx->fillRect(KDRect(horizontalPosition, verticalPosition, k_lineThickness, verticalBarHeight), expressionColor);
|
||||
if (renderTopBar()) {
|
||||
ctx->fillRect(KDRect(p.x()+externWidthMargin(), p.y()+verticalExternMargin(), k_bracketWidth, k_lineThickness), expressionColor);
|
||||
ctx->fillRect(KDRect(p.x()+externWidthMargin()+2*k_lineThickness+childSize.width()+2*widthMargin()-k_bracketWidth, p.y() + verticalExternMargin(), k_bracketWidth, k_lineThickness), expressionColor);
|
||||
ctx->fillRect(KDRect(horizontalPosition, verticalPosition, k_bracketWidth, k_lineThickness), expressionColor);
|
||||
}
|
||||
if (renderBottomBar()) {
|
||||
ctx->fillRect(KDRect(p.x()+externWidthMargin(), p.y()+verticalExternMargin()+verticalBarHeight-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor);
|
||||
ctx->fillRect(KDRect(p.x()+externWidthMargin()+2*k_lineThickness+childSize.width()+2*widthMargin()-k_bracketWidth, p.y()+verticalExternMargin()+verticalBarHeight-k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor);
|
||||
ctx->fillRect(KDRect(horizontalPosition, verticalPosition + verticalBarHeight - k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor);
|
||||
}
|
||||
horizontalPosition += k_lineThickness + widthMargin() + childSize.width() + widthMargin();
|
||||
ctx->fillRect(KDRect(horizontalPosition, verticalPosition, k_lineThickness, verticalBarHeight), expressionColor);
|
||||
horizontalPosition += k_lineThickness;
|
||||
if (renderTopBar()) {
|
||||
ctx->fillRect(KDRect(horizontalPosition - k_bracketWidth, verticalPosition, k_bracketWidth, k_lineThickness), expressionColor);
|
||||
}
|
||||
if (renderBottomBar()) {
|
||||
ctx->fillRect(KDRect(horizontalPosition - k_bracketWidth, verticalPosition + verticalBarHeight - k_lineThickness, k_bracketWidth, k_lineThickness), expressionColor);
|
||||
}
|
||||
if (renderDoubleBar()) {
|
||||
horizontalPosition += widthMargin();
|
||||
ctx->fillRect(KDRect(horizontalPosition, verticalPosition, k_lineThickness, verticalBarHeight), expressionColor);
|
||||
}
|
||||
}
|
||||
|
||||
KDSize BracketPairLayoutNode::computeSize() {
|
||||
KDSize childSize = childLayout()->layoutSize();
|
||||
KDSize result = KDSize(childSize.width() + 2*externWidthMargin() + 2*widthMargin() + 2*k_lineThickness, childSize.height() + 2 * k_verticalMargin + 2*verticalExternMargin());
|
||||
return result;
|
||||
KDCoordinate horizontalCoordinates = childSize.width() + 2*externWidthMargin() + 2*widthMargin() + 2*k_lineThickness;
|
||||
if (renderDoubleBar()) {
|
||||
horizontalCoordinates += 2*k_lineThickness + 2*widthMargin();
|
||||
}
|
||||
return KDSize(horizontalCoordinates, childSize.height() + 2 * k_verticalMargin + 2*verticalExternMargin());
|
||||
}
|
||||
|
||||
KDCoordinate BracketPairLayoutNode::computeBaseline() {
|
||||
@@ -138,7 +157,11 @@ KDCoordinate BracketPairLayoutNode::computeBaseline() {
|
||||
|
||||
KDPoint BracketPairLayoutNode::positionOfChild(LayoutNode * child) {
|
||||
assert(child == childLayout());
|
||||
return KDPoint(widthMargin() + externWidthMargin() + k_lineThickness, k_verticalMargin + verticalExternMargin());
|
||||
KDCoordinate horizontalCoordinates = widthMargin() + externWidthMargin() + k_lineThickness;
|
||||
if (renderDoubleBar()) {
|
||||
horizontalCoordinates += k_lineThickness + widthMargin();
|
||||
}
|
||||
return KDPoint(horizontalCoordinates, k_verticalMargin + verticalExternMargin());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -217,7 +217,8 @@ int HorizontalLayoutNode::serializeChildrenBetweenIndexes(char * buffer, int buf
|
||||
|| (nextChildType == LayoutNode::Type::NthRootLayout
|
||||
&& !static_cast<NthRootLayoutNode *>(nextChild)->isSquareRoot())
|
||||
|| nextChildType == LayoutNode::Type::ProductLayout
|
||||
|| nextChildType == LayoutNode::Type::SumLayout)
|
||||
|| nextChildType == LayoutNode::Type::SumLayout
|
||||
|| nextChildType == LayoutNode::Type::VectorNormLayout)
|
||||
&& currentChild->canBeOmittedMultiplicationLeftFactor())
|
||||
{
|
||||
assert(nextChildType != LayoutNode::Type::HorizontalLayout);
|
||||
|
||||
@@ -372,6 +372,7 @@ template Unreal TreeHandle::FixedArityBuilder<Unreal, UnrealNode>(const Tuple &)
|
||||
template VectorCross TreeHandle::FixedArityBuilder<VectorCross, VectorCrossNode>(const Tuple &);
|
||||
template VectorDot TreeHandle::FixedArityBuilder<VectorDot, VectorDotNode>(const Tuple &);
|
||||
template VectorNorm TreeHandle::FixedArityBuilder<VectorNorm, VectorNormNode>(const Tuple &);
|
||||
template VectorNormLayout TreeHandle::FixedArityBuilder<VectorNormLayout, VectorNormLayoutNode>(const Tuple &);
|
||||
template MatrixLayout TreeHandle::NAryBuilder<MatrixLayout, MatrixLayoutNode>(const Tuple &);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include <poincare/vector_norm.h>
|
||||
#include <poincare/addition.h>
|
||||
#include <poincare/layout_helper.h>
|
||||
#include <poincare/matrix.h>
|
||||
#include <poincare/serialization_helper.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/vector_norm.h>
|
||||
#include <poincare/vector_norm_layout.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -16,7 +17,7 @@ Expression VectorNormNode::shallowReduce(ReductionContext reductionContext) {
|
||||
}
|
||||
|
||||
Layout VectorNormNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
return LayoutHelper::Prefix(VectorNorm(this), floatDisplayMode, numberOfSignificantDigits, VectorNorm::s_functionHelper.name());
|
||||
return VectorNormLayout::Builder(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits));
|
||||
}
|
||||
|
||||
int VectorNormNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
|
||||
Reference in New Issue
Block a user