Exemple #1
0
        private void DrawGeometry(StreamGeometryContext context)
        {
            Radius      = Math.Abs(Radius);
            InnerRadius = Math.Abs(InnerRadius);

            Point innerArcStartPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle, InnerRadius);

            innerArcStartPoint.Offset(CenterX, CenterY);

            Point innerArcEndPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius);

            innerArcEndPoint.Offset(CenterX, CenterY);

            Point outerArcStartPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle, Radius);

            outerArcStartPoint.Offset(CenterX, CenterY);

            Point outerArcEndPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius);

            outerArcEndPoint.Offset(CenterX, CenterY);

            if (PushOut > 0 && WedgeAngle < 360.0)
            {
                Point offset = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, PushOut);
                innerArcStartPoint.Offset(offset.X, offset.Y);
                innerArcEndPoint.Offset(offset.X, offset.Y);
                outerArcStartPoint.Offset(offset.X, offset.Y);
                outerArcEndPoint.Offset(offset.X, offset.Y);
            }

            bool largeArc = WedgeAngle > 180.0;

            Size outerArcSize = new Size(Radius, Radius);
            Size innerArcSize = new Size(InnerRadius, InnerRadius);

            if (WedgeAngle >= 360.0)
            {
                Point internalOuterPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, Radius);
                internalOuterPoint.Offset(CenterX, CenterY);
                Point internalInnerPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, InnerRadius);
                internalInnerPoint.Offset(CenterX, CenterY);

                context.BeginFigure(innerArcStartPoint, true, true);
                context.LineTo(outerArcStartPoint, true, true);
                context.ArcTo(internalOuterPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true);
                context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true);
                context.LineTo(innerArcEndPoint, true, true);
                context.ArcTo(internalInnerPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true);
                context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true);
            }
            else
            {
                context.BeginFigure(innerArcStartPoint, true, true);
                context.LineTo(outerArcStartPoint, true, true);
                context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true);
                context.LineTo(innerArcEndPoint, true, true);
                context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true);
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns true if shape contains point(x,y),
        /// Returns false if not
        /// </summary>
        /// <param name="x">X region of point</param>
        /// <param name="y">Y region of point</param>
        /// <returns></returns>
        public virtual bool Contains(int x, int y)
        {
            if (this.IsLine)
            {
                int dist1 = CalculationUtils.CalculateDistance(x, y, region.X0, region.Y0)
                            + CalculationUtils.CalculateDistance(x, y, region.X1, region.Y1);

                int dist2 = CalculationUtils.CalculateDistance(region.X1, region.Y1,
                                                               region.X0, region.Y0) + 7;

                return(dist1 < dist2);
            }
            return(new Rectangle(region.X0, region.Y0, region.X1 -
                                 region.X0, region.Y1 - region.Y0).Contains(x, y));
        }
        static void Main(string[] args)
        {
            ProtocolUtils.AddToProtocol("Herzlich Willkommen bei dem Zahlensysteme-Rechner!", ProtocolMessageType.Info);
            ProtocolUtils.AddToProtocol("Um ihre Berechnung zu starten geben sie bitte einen Term ein.", ProtocolMessageType.Info);
            ProtocolUtils.AddToProtocol("Die Grundrechenarten + - * / und Klammersetzung werden unterstüzt.", ProtocolMessageType.Info);
            ProtocolUtils.AddToProtocol("Bei Eingabe einer Zahl wird diese in alle unterstützten Zahlensysteme umgewandelt.", ProtocolMessageType.Info);
            ProtocolUtils.AddToProtocol("Der Taschenrechner unterstützt folgende Zahlensysteme, um diese zu verwenden verwenden sie folgende Präfixe:", ProtocolMessageType.Info);
            ProtocolUtils.AddToProtocol("binär: b_(zahl),", ProtocolMessageType.Info);
            ProtocolUtils.AddToProtocol("oktal: o_(zahl),", ProtocolMessageType.Info);
            ProtocolUtils.AddToProtocol("dezimal: d_(zahl),", ProtocolMessageType.Info);
            ProtocolUtils.AddToProtocol("hexadezimal: h_(zahl)", ProtocolMessageType.Info);
            do
            {
                ConsoleUtils.BeginWindow();
                ProtocolUtils.RefreshWindowFromProtocol();
                ConsoleUtils.BeginLine();
                ConsoleUtils.WriteLineContent("> ");
                //save coordinates
                int cursorX = Console.CursorLeft;
                int cursorY = Console.CursorTop;
                ConsoleUtils.EndLine();
                ConsoleUtils.EndWindow();
                Console.SetCursorPosition(cursorX, cursorY);


                //lese benutzereingabe ein
                string input = Console.ReadLine();

                string displayInput = "> " + input;
                ProtocolUtils.AddToProtocol(displayInput, ProtocolMessageType.Info);
                try
                {
                    // Zerlege die Benutzereingabe in Tokens
                    InputToken[] tokens = InputUtils.CreateTokensFromInput(input);

                    //an sonsten sollte dies ein term sein(länge 0 ist kein problem)
                    //versuche den Term zu evaluieren
                    Operand result = CalculationUtils.CalculateTerm(tokens);
                    //gib das Ergebnis aus
                    ConversionUtils.ConvertNumber(result);
                }
                //fange ungültige Operationen auf, diese entstehen wenn Leere stacks gepoppt werden
                //passiert wenn die eingabe syntax fehler enthielt
                catch (InvalidOperationException)
                {
                    ProtocolUtils.AddToProtocol("Syntax Fehler", ProtocolMessageType.Error);
                }// Durch null teilen
                catch (DivideByZeroException)
                {
                    ProtocolUtils.AddToProtocol("Durch 0 teilen nicht möglich.", ProtocolMessageType.Error);
                }
                //fange sonstige Exceptions auf und gib die nachricht auf der konsole aus
                catch (Exception e)
                {
                    ProtocolUtils.AddToProtocol(e.Message, ProtocolMessageType.Error);
                }



                ProtocolUtils.AddToProtocol("Möchten Sie noch eine Berechnung durchführen? (j/n)", ProtocolMessageType.Info);

                ConsoleUtils.BeginWindow();
                ProtocolUtils.RefreshWindowFromProtocol();
                ConsoleUtils.EndWindow();
                //wiederhole solange der benutzer kein kleines n eintippt
            } while (Console.ReadKey().KeyChar != 'n');

            Console.Clear();

            string filename = "rechenprotokoll.txt";

            ProtocolUtils.WriteProtocolToFile(filename);
            Console.WriteLine("Protokoll gespeichert. Dateiname: " + filename);
        }