Skip to content

Conversation

@SuhasDissa
Copy link
Member

Added new functions:

  • Trigonometric functions
  • Degrees <-> Radian conversion
  • Clamp function

Added a cheat sheet to quickly look up available function syntax
Allow hiding functions
Visibility improvements (thicker lines for functions and axis) and a Legend showing currently visible functions

Screenshot_20251119_163021


// Function template chips
Text(
text = "Quick Templates:",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not translatable, i.e. stringResource(R.string.quick_templates)

Comment on lines +175 to +186
val templates = listOf(
"sin(x)" to "sin(x)",
"x^2" to "x^2",
"sin(cos(x))" to "sin(cos(x))",
"sqrt(x^2+1)" to "sqrt(x^2+1)",
"e^(-x^2)" to "exp(-x^2)",
"ln(abs(x))" to "ln(abs(x))",
"tan(x/2)" to "tan(x/2)",
"cbrt(x)" to "cbrt(x)",
"cot(x)" to "cot(x)",
"1/x" to "1/x"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val templates = listOf(
"sin(x)" to "sin(x)",
"x^2" to "x^2",
"sin(cos(x))" to "sin(cos(x))",
"sqrt(x^2+1)" to "sqrt(x^2+1)",
"e^(-x^2)" to "exp(-x^2)",
"ln(abs(x))" to "ln(abs(x))",
"tan(x/2)" to "tan(x/2)",
"cbrt(x)" to "cbrt(x)",
"cot(x)" to "cot(x)",
"1/x" to "1/x"
)
val templates = remember {
listOf(
"sin(x)" to "sin(x)",
"x^2" to "x^2",
"sin(cos(x))" to "sin(cos(x))",
"sqrt(x^2+1)" to "sqrt(x^2+1)",
"e^(-x^2)" to "exp(-x^2)",
"ln(abs(x))" to "ln(abs(x))",
"tan(x/2)" to "tan(x/2)",
"cbrt(x)" to "cbrt(x)",
"cot(x)" to "cot(x)",
"1/x" to "1/x"
)
}

we should either make them remember or put them outside of the compose code, i.e. above the method declaration

"1/x" to "1/x"
)

templates.forEach { (label, template) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could use a LazyRow here instead of a Row with Modifier.scrollabe?

IconButton(onClick = { showCheatSheet = true }) {
Icon(
imageVector = Icons.Rounded.Help,
contentDescription = "Syntax help",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not translatable

),
supportingText = {
Text(
text = "Supports nested functions like sin(cos(x))",
Copy link
Member

@Bnyro Bnyro Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that hint is really necessary, perhaps it'd be better to put this into the SyntaxCheatSheetDialog?

(and also make it translatable)

Comment on lines +255 to +260
"+" to "Addition",
"-" to "Subtraction",
"*" to "Multiplication",
"/" to "Division",
"^" to "Exponentiation (x^2)",
"%" to "Modulo (remainder)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not translatable

Comment on lines +255 to +260
"+" to "Addition",
"-" to "Subtraction",
"*" to "Multiplication",
"/" to "Division",
"^" to "Exponentiation (x^2)",
"%" to "Modulo (remainder)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually use % as percentage (e.g. 10% is the same as 0.1) and not as modulo in CalcYou, might be worth adding a mod function that can be used instead.

onClick = onDismiss,
modifier = Modifier.align(Alignment.End)
) {
Text(text = "Close")
Copy link
Member

@Bnyro Bnyro Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Text(text = "Close")
Text(text = stringResource(android.R.string.ok))

fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.secondary
)
items.forEach { (syntax, description) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a LazyColumn could be used instead here as well for lazy rendering. Won't make much of a difference here, but for larger data amounts it definitely improves performance

Comment on lines +252 to +265
private fun gcd(a: Long, b: Long): Long {
var x = abs(a)
var y = abs(b)
while (y != 0L) {
val temp = y
y = x % y
x = temp
}
return x
}

private fun lcm(a: Long, b: Long): Long {
return if (a == 0L || b == 0L) 0L else abs(a * b) / gcd(a, b)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this into MathUtil.kt

Copy link
Member

@Bnyro Bnyro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, this really looks like a bunch of great improvements! <3

I hope you're doing well, as I haven't heard from you in a while. I'd definitely love to see you back in our development team :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants