Skip to content

Commit d1b8cef

Browse files
authored
Merge pull request #254 from RedGl0w/additional_result_trigo
Changes to the trigonometry additional result
2 parents 81ced86 + 7dff052 commit d1b8cef

File tree

10 files changed

+70
-22
lines changed

10 files changed

+70
-22
lines changed

apps/calculation/additional_outputs/trigonometry_graph_cell.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace Calculation {
88

99
TrigonometryGraphView::TrigonometryGraphView(TrigonometryModel * model) :
1010
CurveView(model),
11-
m_model(model)
11+
m_model(model),
12+
m_shouldDisplayTan(false)
1213
{
1314
}
1415

@@ -22,17 +23,33 @@ void TrigonometryGraphView::drawRect(KDContext * ctx, KDRect rect) const {
2223
drawCurve(ctx, rect, 0.0f, 2.0f*M_PI, M_PI/180.0f, [](float t, void * model, void * context) {
2324
return Poincare::Coordinate2D<float>(std::cos(t), std::sin(t));
2425
}, nullptr, nullptr, true, Palette::SecondaryText, false);
25-
// Draw dashed segment to indicate sine and cosine
26-
drawHorizontalOrVerticalSegment(ctx, rect, Axis::Vertical, c, 0.0f, s, Palette::CalculationTrigoAndComplexForeground, 1, 3);
27-
drawHorizontalOrVerticalSegment(ctx, rect, Axis::Horizontal, s, 0.0f, c, Palette::CalculationTrigoAndComplexForeground, 1, 3);
26+
27+
if (!m_shouldDisplayTan) {
28+
// Draw dashed segment to indicate sine and cosine
29+
drawHorizontalOrVerticalSegment(ctx, rect, Axis::Vertical, c, 0.0f, s, Palette::CalculationTrigoAndComplexForeground, 1, 3);
30+
drawHorizontalOrVerticalSegment(ctx, rect, Axis::Horizontal, s, 0.0f, c, Palette::CalculationTrigoAndComplexForeground, 1, 3);
31+
}
32+
33+
if (m_shouldDisplayTan) {
34+
float t = std::tan(m_model->angle());
35+
drawHorizontalOrVerticalSegment(ctx, rect, Axis::Vertical, 1.0f, m_model->yMin(), m_model->yMax(), Palette::SecondaryText, 2);
36+
drawSegment(ctx, rect, 0.0f, 0.0f, 1.0f, t, Palette::SecondaryText, false);
37+
drawDot(ctx, rect, 1.0f, t, Palette::CalculationTrigoAndComplexForeground, Size::Large);
38+
drawLabel(ctx, rect, 0.0f, t, "tan(θ)", Palette::CalculationTrigoAndComplexForeground, CurveView::RelativePosition::Before, CurveView::RelativePosition::None);
39+
drawHorizontalOrVerticalSegment(ctx, rect, Axis::Horizontal, t, 0.0f, 1.0f, Palette::CalculationTrigoAndComplexForeground, 1, 3);
40+
}
41+
2842
// Draw angle position on the circle
29-
drawDot(ctx, rect, c, s, Palette::CalculationTrigoAndComplexForeground, Size::Large);
43+
drawDot(ctx, rect, c, s, m_shouldDisplayTan ? Palette::SecondaryText : Palette::CalculationTrigoAndComplexForeground, m_shouldDisplayTan ? Size::Tiny : Size::Large);
3044
// Draw graduations
3145
drawLabelsAndGraduations(ctx, rect, Axis::Vertical, false, true);
3246
drawLabelsAndGraduations(ctx, rect, Axis::Horizontal, false, true);
33-
// Draw labels
34-
drawLabel(ctx, rect, 0.0f, s, "sin(θ)", Palette::CalculationTrigoAndComplexForeground, c >= 0.0f ? CurveView::RelativePosition::Before : CurveView::RelativePosition::After, CurveView::RelativePosition::None);
35-
drawLabel(ctx, rect, c, 0.0f, "cos(θ)", Palette::CalculationTrigoAndComplexForeground, CurveView::RelativePosition::None, s >= 0.0f ? CurveView::RelativePosition::Before : CurveView::RelativePosition::After);
47+
48+
if (!m_shouldDisplayTan) {
49+
// Draw labels
50+
drawLabel(ctx, rect, 0.0f, s, "sin(θ)", Palette::CalculationTrigoAndComplexForeground, c >= 0.0f ? CurveView::RelativePosition::Before : CurveView::RelativePosition::After, CurveView::RelativePosition::None);
51+
drawLabel(ctx, rect, c, 0.0f, "cos(θ)", Palette::CalculationTrigoAndComplexForeground, CurveView::RelativePosition::None, s >= 0.0f ? CurveView::RelativePosition::Before : CurveView::RelativePosition::After);
52+
}
3653
}
3754

3855
}

apps/calculation/additional_outputs/trigonometry_graph_cell.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ class TrigonometryGraphView : public Shared::CurveView {
1111
public:
1212
TrigonometryGraphView(TrigonometryModel * model);
1313
void drawRect(KDContext * ctx, KDRect rect) const override;
14+
void setShouldDisplayTan(bool shouldDisplayTan) { m_shouldDisplayTan = shouldDisplayTan; };
1415
private:
1516
TrigonometryModel * m_model;
17+
bool m_shouldDisplayTan;
1618
};
1719

1820
class TrigonometryGraphCell : public IllustrationCell {
1921
public:
2022
TrigonometryGraphCell(TrigonometryModel * model) : m_view(model) {}
23+
void setShouldDisplayTan(bool shouldDisplayTan) { m_view.setShouldDisplayTan(shouldDisplayTan); };
2124
private:
2225
View * view() override { return &m_view; }
2326
TrigonometryGraphView m_view;

apps/calculation/additional_outputs/trigonometry_list_controller.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ Poincare::Constant toConstant(Expression e) {
1818
}
1919

2020
void TrigonometryListController::setExpression(Expression e) {
21-
assert(e.type() == ExpressionNode::Type::Cosine || e.type() == ExpressionNode::Type::Sine);
21+
assert(e.type() == ExpressionNode::Type::Cosine || e.type() == ExpressionNode::Type::Sine || e.type() == ExpressionNode::Type::Tangent);
22+
bool shouldDisplayTan = e.type() == ExpressionNode::Type::Tangent;
23+
m_graphCell.setShouldDisplayTan(shouldDisplayTan);
24+
m_model.setShouldDisplayTan(shouldDisplayTan);
2225

2326
Poincare::Context * context = App::app()->localContext();
2427
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
@@ -58,6 +61,7 @@ void TrigonometryListController::setExpression(Expression e) {
5861
IllustratedListController::setExpression(angleExpression);
5962

6063
// Fill calculation store
64+
m_calculationStore.push("tan(θ)", context, CalculationHeight);
6165
m_calculationStore.push("sin(θ)", context, CalculationHeight);
6266
m_calculationStore.push("cos(θ)", context, CalculationHeight);
6367
m_calculationStore.push("θ", context, CalculationHeight);

apps/calculation/additional_outputs/trigonometry_model.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,22 @@ TrigonometryModel::TrigonometryModel() :
88
{
99
}
1010

11+
float TrigonometryModel::yMin() const {
12+
if (m_shouldDisplayTan) {
13+
return -1.1f;
14+
}
15+
return yCenter() - yHalfRange();
16+
}
17+
18+
float TrigonometryModel::yMax() const {
19+
if (m_shouldDisplayTan) {
20+
float t = std::tan(angle());
21+
if (t <= 1.2f) {
22+
return 1.2f;
23+
}
24+
return 1.2f * std::tan(angle());
25+
}
26+
return yCenter() + yHalfRange();
27+
}
28+
1129
}

apps/calculation/additional_outputs/trigonometry_model.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ class TrigonometryModel : public Shared::CurveViewRange {
1414
// CurveViewRange
1515
float xMin() const override { return -k_xHalfRange; }
1616
float xMax() const override { return k_xHalfRange; }
17-
float yMin() const override { return yCenter() - yHalfRange(); }
18-
float yMax() const override { return yCenter() + yHalfRange(); }
17+
float yMin() const override;
18+
float yMax() const override;
1919

2020
void setAngle(float f) { m_angle = f; }
2121
float angle() const { return m_angle*(float)M_PI/(float)Poincare::Trigonometry::PiInAngleUnit(Poincare::Preferences::sharedPreferences()->angleUnit()); }
22+
void setShouldDisplayTan(bool shouldDisplayTan) { m_shouldDisplayTan = shouldDisplayTan; }
2223
private:
2324
constexpr static float k_xHalfRange = 2.1f;
2425
// We center the yRange around the semi-circle where the angle is
@@ -33,6 +34,7 @@ class TrigonometryModel : public Shared::CurveViewRange {
3334
float yHalfRange() const { return IllustratedListController::k_illustrationHeight*k_xHalfRange/(Ion::Display::Width - Metric::PopUpRightMargin - Metric::PopUpLeftMargin); }
3435

3536
float m_angle;
37+
bool m_shouldDisplayTan;
3638
};
3739

3840
}

apps/calculation/calculation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,11 @@ Calculation::AdditionalInformationType Calculation::additionalInformationType(Co
251251
* - > input: 2cos(2) - cos(2)
252252
* > output: cos(2)
253253
*/
254-
if (input().isDefinedCosineOrSine(context, complexFormat, preferences->angleUnit()) || o.isDefinedCosineOrSine(context, complexFormat, preferences->angleUnit())) {
255-
return AdditionalInformationType::Trigonometry;
254+
if (i.isDefinedCosineOrSineOrTangent(context, complexFormat, preferences->angleUnit())) {
255+
return AdditionalInformationType::TrigonometryInput;
256+
}
257+
if (o.isDefinedCosineOrSineOrTangent(context, complexFormat, preferences->angleUnit())) {
258+
return AdditionalInformationType::TrigonometryOutput;
256259
}
257260
if (o.hasUnit()) {
258261
Expression unit;

apps/calculation/calculation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ friend CalculationStore;
4040
Integer,
4141
Rational,
4242
SecondDegree,
43-
Trigonometry,
43+
TrigonometryInput,
44+
TrigonometryOutput,
4445
Unit,
4546
Matrix,
4647
Complex

apps/calculation/history_controller.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
103103
vc = &m_complexController;
104104
} else if (additionalInfoType == Calculation::AdditionalInformationType::SecondDegree) {
105105
vc = &m_secondDegreeController;
106-
} else if (additionalInfoType == Calculation::AdditionalInformationType::Trigonometry) {
106+
} else if (additionalInfoType == Calculation::AdditionalInformationType::TrigonometryInput) {
107107
vc = &m_trigonometryController;
108-
// Find which of the input or output is the cosine/sine
109-
ExpressionNode::Type t = e.type();
110-
e = t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine ? e : calculationAtIndex(focusRow)->input();
111-
} else if (additionalInfoType == Calculation::AdditionalInformationType::Integer) {
108+
e = calculationAtIndex(focusRow)->input();
109+
} else if (additionalInfoType == Calculation::AdditionalInformationType::TrigonometryOutput) {
110+
vc = &m_trigonometryController;
111+
} else if (additionalInfoType == Calculation::AdditionalInformationType::Integer) {
112112
vc = &m_integerController;
113113
} else if (additionalInfoType == Calculation::AdditionalInformationType::Rational) {
114114
vc = &m_rationalController;

poincare/include/poincare/expression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Expression : public TreeHandle {
183183
bool isRationalOne() const;
184184
bool isRandom() const { return node()->isRandom(); }
185185
bool isParameteredExpression() const { return node()->isParameteredExpression(); }
186-
bool isDefinedCosineOrSine(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
186+
bool isDefinedCosineOrSineOrTangent(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;
187187
bool isBasedIntegerCappedBy(const char * integerString) const;
188188
bool isDivisionOfIntegers() const;
189189
bool hasDefinedComplexApproximation(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const;

poincare/src/expression.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex
292292
return !isMultivariablePolynomial;
293293
}
294294

295-
bool Expression::isDefinedCosineOrSine(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
295+
bool Expression::isDefinedCosineOrSineOrTangent(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const {
296296
ExpressionNode::Type t = type();
297-
if (t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine) {
297+
if (t == ExpressionNode::Type::Cosine || t == ExpressionNode::Type::Sine || t == ExpressionNode::Type::Tangent) {
298298
float r = childAtIndex(0).approximateToScalar<float>(context, complexFormat, angleUnit);
299299
if (!std::isnan(r)) {
300300
return true;

0 commit comments

Comments
 (0)