Exemple #1
0
        public bool AppendNoRedundancy(ComplNum fact1, ComplNum fact2)
        {
            bool       success  = false;
            bool       notfound = false;
            FactorList current  = First;

            try
            {
                notfound = true;
                while (notfound && (current != null))
                {
                    if ((current.val1.Equal(fact1) && current.val2.Equal(fact2)) || (current.val1.Equal(fact2) && current.val2.Equal(fact1)))
                    {
                        notfound = false;
                    }
                    current = current.next;
                }
            }
            catch { MessageBox.Show("NullException in ComplFactors.AppendNoRedundancy during check"); }
            if (notfound)
            {
                try
                {
                    NumFactors++;
                    if (First == null)
                    {
                        First = new FactorList();
                        Last  = First;
                    }
                    else
                    {
                        Last.next = new FactorList();
                        Last      = Last.next;
                    }
                    Last.val1.Assign(fact1);
                    Last.val2.Assign(fact2);
                    success = true;
                }
                catch { MessageBox.Show("NullException in ComplFactors.AppendNoRedundancy during assignment"); }
            }
            return(success);
        }
Exemple #2
0
 public void Append(ComplNum fact1, ComplNum fact2)
 {
     NumFactors++;
     if (First == null)
     {
         First = new FactorList();
         Last  = First;
     }
     else
     {
         Last.next = new FactorList();
         Last      = Last.next;
     }
     try
     {
         Last.val1.Assign(fact1);
         Last.val2.Assign(fact2);
     }
     catch { MessageBox.Show("NullException in ComplFactors.Append"); }
 }
 private void FactIndicator_Click(object sender, MouseButtonEventArgs e)
 {
     if (SelectedProd != null)// react only if previously some number has been selected as product
     {
         // search for clicked ellipse in array to get the corresponding number
         if (FoundFactors != null)
         {
             ComplNum SelectedFactor = FindIndicator((Ellipse)sender, FoundFactors);
             if (SelectedFactor != null)//found?
             {
                 // get all factor pairs
                 if (Factors != null)
                 {
                     ComplFactors CurFactors = Factors.GetFactors(SelectedProd);
                     if (CurFactors != null)
                     {
                         //look if the currently selected number is actually a factor of the previously selected product
                         FactorList CurFactPair = CurFactors.First;
                         //get current necessary thickness of edge to be seen and not be too big.
                         double EdgeThickness = GetCurrentDiameter() * smallmargfract;
                         while (CurFactPair != null) //go through *all* factor pairs to clean up edges from possible previous factor selection
                         {
                             //clean up any previous black edges from non-double factors
                             if (!CurFactPair.val1.Equal(CurFactPair.val2))
                             {
                                 FoundFactors[CurFactPair.val1.Im + size, CurFactPair.val1.Re + size].StrokeThickness = 0;
                                 FoundFactors[CurFactPair.val2.Im + size, CurFactPair.val2.Re + size].StrokeThickness = 0;
                             }
                             // is the lastly selected number part of the current factor pair?
                             if (CurFactPair.val1.Equal(SelectedFactor))
                             {
                                 // only need to do sth if no "double factor"
                                 if (!CurFactPair.val2.Equal(SelectedFactor))
                                 {
                                     // recolor current and corresponding factor's inner edge
                                     SolidColorBrush myBrush = new SolidColorBrush();
                                     myBrush.Color                     = Color.FromRgb(0, 0, 0);
                                     ((Ellipse)sender).Stroke          = myBrush;
                                     ((Ellipse)sender).StrokeThickness = EdgeThickness;
                                     FoundFactors[CurFactPair.val2.Im + size, CurFactPair.val2.Re + size].Stroke          = myBrush;
                                     FoundFactors[CurFactPair.val2.Im + size, CurFactPair.val2.Re + size].StrokeThickness = EdgeThickness;
                                 }
                             }
                             else if (CurFactPair.val2.Equal(SelectedFactor))
                             {
                                 //possibility of "double factor" already excluded
                                 // recolor current and corresponding factor's inner edge
                                 SolidColorBrush myBrush = new SolidColorBrush();
                                 myBrush.Color                     = Color.FromRgb(0, 0, 0);
                                 ((Ellipse)sender).Stroke          = myBrush;
                                 ((Ellipse)sender).StrokeThickness = EdgeThickness;
                                 FoundFactors[CurFactPair.val1.Im + size, CurFactPair.val1.Re + size].Stroke          = myBrush;
                                 FoundFactors[CurFactPair.val1.Im + size, CurFactPair.val1.Re + size].StrokeThickness = EdgeThickness;
                             }
                             else
                             {
                                 //if current selected factor is not part
                             }
                             CurFactPair = CurFactPair.next;
                         }
                     }
                 }
             }
         }
     }
 }
        private void RecolorFactors(ComplNum Prod, ComplFactors Factors)
        {
            if (FoundFactors != null)
            {
                // cleanup before special coloring
                StandardColorFactors();
                StandardOutlineFactors();
                StandardOutlineProducts();
                StandardToolTipFactors();

                //actual re-color action
                double diameter = GetCurrentDiameter();
                // mark the selected product
                if (FoundProducts != null)
                {
                    FoundProducts[Prod.Im + size, Prod.Re + size].StrokeThickness = diameter * smallmargfract;
                }
                //mark factors
                long FactNum = Factors.NumFactors;
                SolidColorBrush[] BrushList = Colors(FactNum);
                long       ColInd           = 0;
                FactorList CurFactPair      = Factors.First;
                while (CurFactPair != null)
                {
                    if (CurFactPair.val1.Equal(CurFactPair.val2))
                    {
                        long i = CurFactPair.val1.Im + size;
                        long j = CurFactPair.val1.Re + size;
                        if (FoundFactors[i, j] != null)
                        {
                            FoundFactors[i, j].StrokeThickness = diameter * smallmargfract;
                            FoundFactors[i, j].Fill            = BrushList[ColInd];
                            FoundFactors[i, j].ToolTip         = "Factor " + CurFactPair.val1.ToString() +
                                                                 " (both factors of " + Prod.ToString() + " identical)";
                        }
                    }
                    else
                    {
                        long i = CurFactPair.val1.Im + size;
                        long j = CurFactPair.val1.Re + size;
                        if (FoundFactors[i, j] != null)
                        {
                            FoundFactors[i, j].Fill = BrushList[ColInd];
                        }
                        FoundFactors[i, j].ToolTip = "Factor " + CurFactPair.val1.ToString() +
                                                     " (corresponding factor of " + Prod.ToString() + ": "
                                                     + CurFactPair.val2.ToString() + ").\n Click to show corresponding factor.";
                        i = CurFactPair.val2.Im + size;
                        j = CurFactPair.val2.Re + size;
                        if (FoundFactors[i, j] != null)
                        {
                            FoundFactors[i, j].Fill = BrushList[ColInd];
                        }
                        FoundFactors[i, j].ToolTip = "Factor " + CurFactPair.val2.ToString() +
                                                     " (corresponding factor of " + Prod.ToString() + ": "
                                                     + CurFactPair.val1.ToString() + ").\n Click to show corresponding factor.";
                    }
                    ColInd++;
                    CurFactPair = CurFactPair.next;
                }
            }
        }
Exemple #5
0
        public ComplFactors(ComplNum InputProd)
        {
            double   AbsVal;
            uint     OuterPhase;
            long     Size1, Size2, Size3, OuterSize;
            long     SearchReAbs1, SearchImAbs1, SearchReAbs2, SearchImAbs2;
            ComplNum Fact1, Fact2, Prod;

            AbsVal = 0;
            Size1  = 0;
            Size2  = 0;
            Size3  = 0;
            Fact1  = null;
            Fact2  = null;
            Prod   = new ComplNum();

            try
            {
                AbsVal = InputProd.Absolute();
                Size3  = (long)Math.Ceiling(AbsVal);
                Size2  = (long)Math.Floor(Math.Sqrt(AbsVal) * Math.Sqrt(0.5));
                Prod.Assign(InputProd);
            }
            catch { MessageBox.Show("NullException in ComplFactors constructor"); }
            First      = null;
            Last       = null;
            NumFactors = 0;

            for (OuterSize = Size2; OuterSize <= Size3; OuterSize++)
            {
                OuterPhase   = 0;
                SearchReAbs1 = -OuterSize;
                SearchImAbs1 = -OuterSize;
                Size1        = (long)Math.Ceiling(AbsVal / ((double)OuterSize));
                while (OuterPhase < 4)
                {
                    for (SearchReAbs2 = 0; SearchReAbs2 <= Size1; SearchReAbs2++)
                    {
                        for (SearchImAbs2 = 0; SearchImAbs2 <= Size1; SearchImAbs2++)
                        {
                            //Test with all sign combinations
                            Fact1 = new ComplNum(SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                            Fact1 = new ComplNum(-SearchReAbs1, -SearchImAbs1);
                            Fact2 = new ComplNum(-SearchReAbs2, -SearchImAbs2);
                            if (Prod.Equal(ComplNumCalc.Mul(Fact1, Fact2)))
                            {
                                this.AppendNoRedundancy(Fact1, Fact2);
                            }
                        }
                    }
                    if (OuterPhase == 0)
                    {
                        if (SearchImAbs1 < OuterSize)
                        {
                            SearchImAbs1++;
                        }
                        else
                        {
                            OuterPhase++;
                        }
                    }
                    else if (OuterPhase == 1)
                    {
                        if (SearchReAbs1 < OuterSize)
                        {
                            SearchReAbs1++;
                        }
                        else
                        {
                            OuterPhase++;
                        }
                    }
                    else if (OuterPhase == 2)
                    {
                        if (SearchImAbs1 > -OuterSize)
                        {
                            SearchImAbs1--;
                        }
                        else
                        {
                            OuterPhase++;
                        }
                    }
                    else if (OuterPhase == 3)
                    {
                        if (SearchReAbs1 > -OuterSize)
                        {
                            SearchReAbs1--;
                        }
                        else
                        {
                            OuterPhase++;
                        }
                    }
                }
            }
        }
Exemple #6
0
 public ComplFactors()
 {
     First      = null;
     Last       = null;
     NumFactors = 0;
 }
Exemple #7
0
 public FactorList()
 {
     val1 = new ComplNum();
     val2 = new ComplNum();
     next = null;
 }