Skip to content

Commit

Permalink
Close #268 - Introduce units (deg, rad, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Aug 27, 2020
1 parent 0d3bb84 commit 8808b6f
Show file tree
Hide file tree
Showing 117 changed files with 4,583 additions and 2,261 deletions.
24 changes: 6 additions & 18 deletions xFunc.DotnetTool/Options/SolveOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,19 @@
using CommandLine;
using CommandLine.Text;
using System.Collections.Generic;
using xFunc.Maths.Expressions;

namespace xFunc.DotnetTool.Options
{
[Verb("solve", HelpText = "Calculate result of expression.")]
public class SolveOptions : BaseOptions
{
[Option('a', "angle", Default = AngleMeasurement.Degree, Required = false, HelpText = "Angle Measurement")]
public AngleMeasurement Angle { get; set; }

[Usage(ApplicationAlias = "xfunc")]
public static IEnumerable<Example> Examples
{
get
public static IEnumerable<Example> Examples =>
new List<Example>
{
return new List<Example>
{
new Example(
"Calculate string expression",
new SolveOptions { StringExpression = "1 + 1" }),
new Example(
"Set angle measurement",
new SolveOptions { StringExpression = "1 + 1" , Angle = AngleMeasurement.Radian })
};
}
}
new Example(
"Calculate string expression",
new SolveOptions { StringExpression = "1 + 1" }),
};
}
}
17 changes: 0 additions & 17 deletions xFunc.DotnetTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ private static void Solve(SolveOptions options)
{
Run(options, () =>
{
processor.Parameters.AngleMeasurement = options.Angle;
var result = processor.Solve(options.StringExpression);
Console.WriteLine(result);
});
Expand All @@ -71,21 +69,6 @@ private static void Interactive(InteractiveOptions options)
{
break;
}
else if (stringExpression == "#degree")
{
processor.Parameters.AngleMeasurement = AngleMeasurement.Degree;
continue;
}
else if (stringExpression == "#radian")
{
processor.Parameters.AngleMeasurement = AngleMeasurement.Radian;
continue;
}
else if (stringExpression == "#gradian")
{
processor.Parameters.AngleMeasurement = AngleMeasurement.Gradian;
continue;
}

Run(options, () =>
{
Expand Down
46 changes: 46 additions & 0 deletions xFunc.Maths/Analyzers/Analyzer{TResult,TContext}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using xFunc.Maths.Expressions;
using xFunc.Maths.Expressions.Angles;
using xFunc.Maths.Expressions.ComplexNumbers;
using xFunc.Maths.Expressions.Hyperbolic;
using xFunc.Maths.Expressions.LogicalAndBitwise;
Expand Down Expand Up @@ -208,6 +209,51 @@ public virtual TResult Analyze(Mul exp, TContext context)
public virtual TResult Analyze(Number exp, TContext context)
=> throw new NotSupportedException();

/// <summary>
/// Analyzes the specified expression.
/// </summary>
/// <param name="exp">The expression.</param>
/// <param name="context">The context.</param>
/// <returns>The result of analysis.</returns>
public virtual TResult Analyze(AngleNumber exp, TContext context)
=> throw new NotSupportedException();

/// <summary>
/// Analyzes the specified expression.
/// </summary>
/// <param name="exp">The expression.</param>
/// <param name="context">The context.</param>
/// <returns>The result of analysis.</returns>
public virtual TResult Analyze(ToDegree exp, TContext context)
=> throw new NotSupportedException();

/// <summary>
/// Analyzes the specified expression.
/// </summary>
/// <param name="exp">The expression.</param>
/// <param name="context">The context.</param>
/// <returns>The result of analysis.</returns>
public virtual TResult Analyze(ToRadian exp, TContext context)
=> throw new NotSupportedException();

/// <summary>
/// Analyzes the specified expression.
/// </summary>
/// <param name="exp">The expression.</param>
/// <param name="context">The context.</param>
/// <returns>The result of analysis.</returns>
public virtual TResult Analyze(ToGradian exp, TContext context)
=> throw new NotSupportedException();

/// <summary>
/// Analyzes the specified expression.
/// </summary>
/// <param name="exp">The expression.</param>
/// <param name="context">The context.</param>
/// <returns>The result of analysis.</returns>
public virtual TResult Analyze(ToNumber exp, TContext context)
=> throw new NotSupportedException();

/// <summary>
/// Analyzes the specified expression.
/// </summary>
Expand Down

0 comments on commit 8808b6f

Please sign in to comment.