예제 #1
0
 public bool EqualsAtom(MathAtom otherAtom) =>
 Nucleus == otherAtom.Nucleus &&
 GetType() == otherAtom.GetType() &&
 //IndexRange == otherAtom.IndexRange &&
 //FontStyle == otherAtom.FontStyle &&
 Superscript.NullCheckingStructuralEquality(otherAtom.Superscript) &&
 Subscript.NullCheckingStructuralEquality(otherAtom.Subscript);
예제 #2
0
        public override List <Run> DisplayText()
        {
            List <Run> display = new List <Run>();

            display.Add(new Run()
            {
                Text = "("
            });
            foreach (Element e in Elements)
            {
                display.AddRange(e.DisplayText());
            }
            display.Add(new Run()
            {
                Text = ")"
            });
            if (Subscript > 1)
            {
                Run r = new Run()
                {
                    Text = Subscript.ToString()
                };
                Typography.SetVariants(r, Windows.UI.Xaml.FontVariants.Subscript);
                display.Add(r);
            }

            return(display);
        }
예제 #3
0
 public void Fuse(MathAtom otherAtom)
 {
     if (Subscript.IsNonEmpty())
     {
         throw new InvalidOperationException("Cannot fuse into an atom with a subscript");
     }
     if (Superscript.IsNonEmpty())
     {
         throw new InvalidOperationException("Cannot fuse into an atom with a superscript");
     }
     if (otherAtom.GetType() != GetType())
     {
         throw new InvalidOperationException("Cannot fuse atoms with different types");
     }
     FusedAtoms ??= new List <MathAtom> {
         Clone(false)
     };
     if (otherAtom.FusedAtoms != null)
     {
         FusedAtoms.AddRange(otherAtom.FusedAtoms);
     }
     else
     {
         FusedAtoms.Add(otherAtom);
     }
     Nucleus   += otherAtom.Nucleus;
     IndexRange = new Range(IndexRange.Location,
                            IndexRange.Length + otherAtom.IndexRange.Length);
     Subscript   = otherAtom.Subscript;
     Superscript = otherAtom.Superscript;
 }
예제 #4
0
        protected override void LLWrite(ICodeWriter writer, object o)
        {
            writer.BeginNewLine(true);
            if (Name != null)
            {
                Name.WriteAll(writer);
            }
            else
            {
                Subscript.WriteAll(writer);
            }

            if (TypeAnnotation != null)
            {
                writer.Write(": ", true);
                TypeAnnotation.WriteAll(writer);
            }

            if (Value != null)
            {
                writer.Write(" = ", true);
                Value.WriteAll(writer);
            }
            writer.EndLine();
        }
        public void GetSubscript(string latex, IList <Element> container, Marker marker)
        {
            if (marker.Position >= latex.Length)
            {
                return;
            }

            if (latex.Substring(marker.Position, 1) == "_")
            {
                marker.Position += 1;

                var subsection = GetSubsection(latex, container, marker);

                if (subsection != null)
                {
                    var subscript = new Subscript();
                    var line      = new MathematicsLine();

                    subscript.Element1 = container.Last();

                    if (subsection.Item2.Count() == 1)
                    {
                        subscript.Element2 = subsection.Item2.First();
                    }
                    else
                    {
                        line.Elements      = subsection.Item2;
                        subscript.Element2 = line;
                    }

                    container.Remove(container.Last());
                    container.Add(subscript);

                    marker.Position += subsection.Item1;
                }
                else
                {
                    var elements = new List <Element>();

                    GetGreekLetter(latex, elements, marker);
                    GetIdentifier(latex, elements, marker);
                    GetNumber(latex, elements, marker);
                    GetOperator(latex, elements, marker);
                    GetMathRoman(latex, elements, marker);
                    GetPunctuationMark(latex, elements, marker);

                    if (elements.Any())
                    {
                        var subscript = new Subscript();

                        subscript.Element1 = container.Last();
                        subscript.Element2 = elements.First();

                        container.Remove(container.Last());
                        container.Add(subscript);
                    }
                }
            }
        }
예제 #6
0
        protected override void OnMeasure(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style)
        {
            bracketSize = HasBracket ? 5 : 0;

            Body.Measure(widthSpec, heightSpec, g, font, style);
            Subscript.Measure(widthSpec, heightSpec, g, font, style);

            SetDesiredSize(Body.DesiredWidth + Subscript.DesiredWidth + bracketSize * 2 + 1 - ShiftOffset + 5, Body.DesiredHeight + Subscript.DesiredHeight - 10);
        }
예제 #7
0
        protected override void OnDraw(Graphics g, Font font, Style style)
        {
            Body.Draw(g, font, style);
            Subscript.Draw(g, style.Font, style);

            if (HasBracket)
            {
                VectorGraphics.DrawRoundBracket(new RectangleF(Left, Top, Width - Subscript.DesiredWidth, Height), g, Brushes.Black);
            }
        }
예제 #8
0
        public static Subscript Index(string bas, string index)
        {
            var  subscript   = new Subscript();
            Base b           = new Base(new Run(new Text(bas)));
            var  subArgument = new SubArgument(new Run(new Text(index)));

            subscript.AppendChild(b);
            subscript.AppendChild(subArgument);
            return(subscript);
        }
예제 #9
0
    public float CalculateDensity(float altitude)
    {
        Subscript subscript = GetSubscript(altitude);

        if (subscript.TemperatureLapseRate == 0)
        {
            return(subscript.MassDensity * Mathf.Exp(
                       (-GRAVITATIONAL_ACCELERATION * MOLAR_MASS_AIR * (altitude - subscript.ReferenceLevel)) / (GAS_CONSTANT * subscript.ReferenceTemperature)));
        }
        else
        {
            return(subscript.MassDensity * Mathf.Pow(
                       subscript.ReferenceTemperature / (subscript.ReferenceTemperature + subscript.TemperatureLapseRate * (altitude - subscript.ReferenceLevel)),
                       1 + (GRAVITATIONAL_ACCELERATION * MOLAR_MASS_AIR) / (GAS_CONSTANT * subscript.TemperatureLapseRate)));
        }
    }
예제 #10
0
        private SubscriptToken processSubScript(Subscript s)
        {
            TokenList subBase  = new TokenList();
            TokenList argument = new TokenList();

            foreach (var child in s.Base)
            {
                subBase.Append(processElement(child));
            }

            foreach (var child in s.SubArgument)
            {
                argument.Append(processElement(child));
            }

            return(new SubscriptToken(subBase, argument));
        }
예제 #11
0
 protected TAtom ApplyCommonPropertiesOn <TAtom>(bool finalize, TAtom newAtom)
     where TAtom : MathAtom
 {
     if (string.IsNullOrEmpty(newAtom.Nucleus))
     {
         // newAtom.Nucleus may have already been initialized by newAtom's constructor
         newAtom.Nucleus = Nucleus;
     }
     if (FusedAtoms != null)
     {
         newAtom.FusedAtoms = new List <MathAtom>(FusedAtoms);
     }
     newAtom.Superscript = Superscript.Clone(finalize);
     newAtom.Subscript   = Subscript.Clone(finalize);
     newAtom.IndexRange  = IndexRange;
     newAtom.FontStyle   = FontStyle;
     return(newAtom);
 }
예제 #12
0
        public override List <Run> DisplayText()
        {
            List <Run> display = new List <Run>();

            display.Add(new Run()
            {
                Text = Symbol
            });
            if (Subscript > 1)
            {
                Run r = new Run()
                {
                    Text = Subscript.ToString()
                };
                Typography.SetVariants(r, Windows.UI.Xaml.FontVariants.Subscript);
                display.Add(r);
            }
            if (Charge != 0)
            {
                if (Charge < 0)
                {
                    //This won't convert a - to a ⁻ for some reason?
                    Run r1 = new Run()
                    {
                        Text = "⁻"
                    };
                    display.Add(r1);
                }

                Run r = new Run()
                {
                    Text = Math.Abs(Charge).ToString()
                };
                Typography.SetVariants(r, Windows.UI.Xaml.FontVariants.Superscript);
                display.Add(r);
            }

            return(display);
        }
        public bool IsOutOfBoundaries(int _subscript, Subscript _subscriptType)
        {
            switch (_subscriptType)
            {
            case Subscript.i:
                if (_subscript < 0 || _subscript >= NumberBlocksX)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case Subscript.j:
                if (_subscript < 0 || _subscript >= NumberBlocksY)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case Subscript.k:
                if (_subscript < 0 || _subscript >= NumberBlocksZ)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                return(false);
            }
        }
예제 #14
0
    private static Subscript GetSubscript(float altitude)
    {
        if (altitude < 0)
        {
            throw new ArgumentException("No subscript defined for altitude < 0");
        }

        Subscript retVal = null;

        foreach (Subscript subscript in subscripts)
        {
            if (subscript.ReferenceLevel <= altitude)
            {
                retVal = subscript;
            }
            else
            {
                return(retVal ?? throw new Exception("Illegal state in subscript getter"));
            }
        }

        return(retVal ?? throw new Exception("Illegal state in subscript getter"));
    }
예제 #15
0
            private void HandleEscSeq1(PegNode node, StyleContext context, StructuralGlyph parent)
            {
                int posBeg    = node.match_.posBeg_;
                var childNode = node.child_;

                if (childNode == null)
                {
                    throw new ArgumentNullException("childNode");
                }

                string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

                switch (escHeader.ToLowerInvariant())
                {
                case @"\id(":
                {
                    const string DefPropertyHead = "$Property[\"";
                    const string DefPropertyTail = "\"]";

                    string s = GetText(childNode).Trim();
                    if (s == "$DI")
                    {
                        parent.Add(new DocumentIdentifier(context));
                    }
                    else if (s.StartsWith(DefPropertyHead) && s.EndsWith(DefPropertyTail))
                    {
                        string propertyName = s.Substring(DefPropertyHead.Length, s.Length - DefPropertyHead.Length - DefPropertyTail.Length);
                        if (!string.IsNullOrEmpty(propertyName))
                        {
                            parent.Add(new ValueOfProperty(context, propertyName));
                        }
                    }
                }
                break;

                case @"\g(":
                {
                    var newContext = context.Clone();
                    newContext.SetFont(context.FontId.WithFamily("Symbol"));
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\i(":
                {
                    var newContext = context.Clone();
                    newContext.MergeFontStyle(FontXStyle.Italic);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\b(":
                {
                    var newContext = context.Clone();
                    newContext.MergeFontStyle(FontXStyle.Bold);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\u(":
                {
                    var newContext = context.Clone();
                    newContext.MergeFontStyle(FontXStyle.Underline);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\s(":
                {
                    var newContext = context.Clone();
                    newContext.MergeFontStyle(FontXStyle.Strikeout);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\n(":
                {
                    var newContext = context.Clone();
                    newContext.SetFontStyle(FontXStyle.Regular);
                    VisitNode(childNode, newContext, parent);
                }
                break;

                case @"\+(":
                {
                    var newParent = new Superscript
                    {
                        Style = context
                    };
                    parent.Add(newParent);

                    var newContext = context.Clone();
                    newContext.ScaleFont(0.65);
                    VisitNode(childNode, newContext, newParent);
                }
                break;

                case @"\-(":
                {
                    var newParent = new Subscript
                    {
                        Style = context
                    };
                    parent.Add(newParent);

                    var newContext = context.Clone();
                    newContext.ScaleFont(0.65);
                    VisitNode(childNode, newContext, newParent);
                }
                break;

                case @"\l(":
                {
                    string s = GetText(childNode);
                    if (int.TryParse(s, out var plotNumber))
                    {
                        parent.Add(new PlotSymbol(context, plotNumber));
                    }
                }
                break;

                case @"\%(":
                {
                    string s = GetText(childNode);
                    if (int.TryParse(s, out var plotNumber))
                    {
                        parent.Add(new PlotName(context, plotNumber));
                    }
                }
                break;

                case @"\ad(":
                {
                    var newParent = new DotOverGlyph
                    {
                        Style = context
                    };
                    parent.Add(newParent);
                    VisitNode(childNode, context, newParent);
                }
                break;

                case @"\ab(":
                {
                    var newParent = new BarOverGlyph
                    {
                        Style = context
                    };
                    parent.Add(newParent);
                    VisitNode(childNode, context, newParent);
                }
                break;
                }
            }
예제 #16
0
 public override Subscript VisitSubscript(Subscript subscript)
 {
     subscript = subscriptDelegate?.Invoke(subscript) ?? subscript;
     return(base.VisitSubscript(subscript));
 }
예제 #17
0
    public float CalculateTemperature(float altitude)
    {
        Subscript subscript = GetSubscript(altitude);

        return(subscript.ReferenceTemperature + subscript.TemperatureLapseRate * (altitude - subscript.ReferenceLevel));
    }
예제 #18
0
 protected override void OnLayout(float left, float top, float width, float height, Graphics g, Font font, Style style)
 {
     Body.Layout(this, bracketSize, 0, Body.DesiredWidth, Body.DesiredHeight, g, font, style);
     Subscript.Layout(this, Body.DesiredWidth + bracketSize * 2 + 1 - ShiftOffset, DesiredHeight - Subscript.DesiredHeight, Body.DesiredWidth, Body.DesiredHeight, g, font, style);
 }
예제 #19
0
 /// <summary>
 /// Determines whether the specified <see cref="Subscript" />, is equal to this instance.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns>true if equal; otherwise, false</returns>
 protected bool Equals(Subscript other) => string.Equals(Text, other.Text) && Equals(Attributes, other.Attributes);
예제 #20
0
            internal static expr Convert(Compiler.Ast.Expression expr, expr_context ctx) {
                expr ast;

                if (expr is ConstantExpression)
                    ast = Convert((ConstantExpression)expr);
                else if (expr is NameExpression)
                    ast = new Name((NameExpression)expr, ctx);
                else if (expr is UnaryExpression)
                    ast = new UnaryOp((UnaryExpression)expr);
                else if (expr is BinaryExpression)
                    ast = Convert((BinaryExpression)expr);
                else if (expr is AndExpression)
                    ast = new BoolOp((AndExpression)expr);
                else if (expr is OrExpression)
                    ast = new BoolOp((OrExpression)expr);
                else if (expr is CallExpression)
                    ast = new Call((CallExpression)expr);
                else if (expr is ParenthesisExpression)
                    return Convert(((ParenthesisExpression)expr).Expression);
                else if (expr is LambdaExpression)
                    ast = new Lambda((LambdaExpression)expr);
                else if (expr is ListExpression)
                    ast = new List((ListExpression)expr, ctx);
                else if (expr is TupleExpression)
                    ast = new Tuple((TupleExpression)expr, ctx);
                else if (expr is DictionaryExpression)
                    ast = new Dict((DictionaryExpression)expr);
                else if (expr is ListComprehension)
                    ast = new ListComp((ListComprehension)expr);
                else if (expr is GeneratorExpression)
                    ast = new GeneratorExp((GeneratorExpression)expr);
                else if (expr is MemberExpression)
                    ast = new Attribute((MemberExpression)expr, ctx);
                else if (expr is YieldExpression)
                    ast = new Yield((YieldExpression)expr);
                else if (expr is ConditionalExpression)
                    ast = new IfExp((ConditionalExpression)expr);
                else if (expr is IndexExpression)
                    ast = new Subscript((IndexExpression)expr, ctx);
                else if (expr is SliceExpression)
                    ast = new Slice((SliceExpression)expr);
                else if (expr is BackQuoteExpression)
                    ast = new Repr((BackQuoteExpression)expr);
                else
                    throw new ArgumentTypeException("Unexpected expression type: " + expr.GetType());

                ast.GetSourceLocation(expr);
                return ast;
            }
예제 #21
0
			private void HandleEscSeq1(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\id(":
						{
							const string DefPropertyHead = "$Property[\"";
							const string DefPropertyTail = "\"]";

							string s = GetText(childNode).Trim();
							if (s == "$DI")
							{
								parent.Add(new DocumentIdentifier(context));
							}
							else if (s.StartsWith(DefPropertyHead) && s.EndsWith(DefPropertyTail))
							{
								string propertyName = s.Substring(DefPropertyHead.Length, s.Length - DefPropertyHead.Length - DefPropertyTail.Length);
								if (!string.IsNullOrEmpty(propertyName))
									parent.Add(new ValueOfProperty(context, propertyName));
							}
						}
						break;

					case @"\g(":
						{
							var newContext = context.Clone();
							newContext.SetFont(context.FontId.WithFamily("Symbol"));
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\i(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Italic);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\b(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Bold);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\u(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Underline);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\s(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Strikeout);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\n(":
						{
							var newContext = context.Clone();
							newContext.SetFontStyle(FontXStyle.Regular);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\+(":
						{
							var newParent = new Superscript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\-(":
						{
							var newParent = new Subscript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\l(":
						{
							string s = GetText(childNode);
							int plotNumber;
							if (int.TryParse(s, out plotNumber))
							{
								parent.Add(new PlotSymbol(context, plotNumber));
							}
						}
						break;

					case @"\%(":
						{
							string s = GetText(childNode);
							int plotNumber;
							if (int.TryParse(s, out plotNumber))
							{
								parent.Add(new PlotName(context, plotNumber));
							}
						}
						break;

					case @"\ad(":
						{
							var newParent = new DotOverGlyph();
							newParent.Style = context;
							parent.Add(newParent);
							VisitNode(childNode, context, newParent);
						}
						break;

					case @"\ab(":
						{
							var newParent = new BarOverGlyph();
							newParent.Style = context;
							parent.Add(newParent);
							VisitNode(childNode, context, newParent);
						}
						break;
				}
			}
예제 #22
0
 protected bool Equals(Subscript other)
 {
     return(string.Equals(Text, other.Text) && Equals(Attributes, other.Attributes));
 }