Example #1
0
        public override bool Equals(object obj)
        {
            if (obj == null) // check if its null
            {
                return(false);
            }

            if (this.GetType() != obj.GetType()) // check if the type is the same
            {
                return(false);
            }

            MouseGeneralization generalization = (MouseGeneralization)obj;

            if (generalization == null) // check if it can be casted
            {
                return(false);
            }

            if (generalization.AverageX == this.AverageX &&
                generalization.AverageY == this.AverageY)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public static Generalization[] Merge(Generalization[] prev_gens, Generalization[] new_gens)
        {
            List <Generalization> gens = new List <Generalization>();

            if (prev_gens.Length > 0 && prev_gens.Length == new_gens.Length && prev_gens[0].Type == new_gens[0].Type)
            {
                for (int i = 0; i < prev_gens.Length; i++)
                {
                    MouseGeneralization prev_gen = (MouseGeneralization)prev_gens[i];
                    MouseGeneralization new_gen = (MouseGeneralization)new_gens[i];
                    int x1 = prev_gen.AverageX, x2 = new_gen.AverageX, y1 = prev_gen.AverageY, y2 = new_gen.AverageY;
                    int incx1 = prev_gen.AverageIncX, incy1 = prev_gen.AverageIncY, incx2 = new_gen.AverageIncX, incy2 = new_gen.AverageIncY;
#if CORRECTION
                    int dx = x2 - x1;
                    int dy = y2 - y1;
#else
                    int dx = (int)(((double)x2 / (double)(prev_gen.Occurrences + 1)) - ((double)x1 * ((double)prev_gen.Occurrences / (double)(prev_gen.Occurrences + 1))));
                    int dy = (int)(((double)y2 / (double)(prev_gen.Occurrences + 1)) - ((double)y1 * ((double)prev_gen.Occurrences / (double)(prev_gen.Occurrences + 1))));
#endif

                    if (prev_gen.IsSequential == new_gen.IsSequential)
                    {
                        if (prev_gen.IsSequential == true)
                        {
#if CORRECTION
                            int dincx = incx2 - incx1;
                            int dincy = incy2 - incy1;
#else
                            int dincx = (int)(((double)incx2 / (double)(prev_gen.Occurrences + 1)) - ((double)incx1 * ((double)prev_gen.Occurrences / (double)(prev_gen.Occurrences + 1))));
                            int dincy = (int)(((double)incy2 / (double)(prev_gen.Occurrences + 1)) - ((double)incy1 * ((double)prev_gen.Occurrences / (double)(prev_gen.Occurrences + 1))));
#endif
                            bool is_dincx_valid = (Math.Abs(dincx) <= MouseAction.MAX_X_OFFSET ? true : false);
                            bool is_dincy_valid = (Math.Abs(dincy) <= MouseAction.MAX_Y_OFFSET ? true : false);

                            if (is_dincx_valid && is_dincy_valid)
                            {
#if CORRECTION
                                int avg_incx = GetIntAverage(incx1, incx2);
                                int avg_incy = GetIntAverage(incy1, incy2);
#else
                                int avg_incx = GetIntAverage(incx1, incx2, prev_gen.Occurrences);
                                int avg_incy = GetIntAverage(incy1, incy2, prev_gen.Occurrences);
#endif
                                bool is_dx_valid = (Math.Abs(dx - avg_incx) <= MouseAction.MAX_X_OFFSET ? true : false);
                                bool is_dy_valid = (Math.Abs(dy - avg_incy) <= MouseAction.MAX_Y_OFFSET ? true : false);

                                if (is_dx_valid && is_dy_valid)
                                {
#if CORRECTION
                                    int avg_x = GetIntAverage(x1, x2);
                                    int avg_y = GetIntAverage(y1, y2);
#else
                                    int avg_x = GetIntAverage(x1, x2, prev_gen.Occurrences);
                                    int avg_y = GetIntAverage(y1, y2, prev_gen.Occurrences);
#endif
                                    gens.Add(new MouseGeneralization(x2, y2, avg_incx, avg_incy, true, new_gen.Time, prev_gen.Occurrences + 1));
                                }
                            }
                        }
                        else
                        {
                            int incx = (Math.Abs(dx) <= MouseAction.MAX_X_OFFSET ? 0 : dx);
                            int incy = (Math.Abs(dy) <= MouseAction.MAX_Y_OFFSET ? 0 : dy);
#if CORRECTION
                            int avg_x = GetIntAverage(x1, x2);
                            int avg_y = GetIntAverage(y1, y2);
#else
                            int avg_x = GetIntAverage(x1, x2, prev_gen.Occurrences);
                            int avg_y = GetIntAverage(y1, y2, prev_gen.Occurrences);
#endif
                            bool seq = (incx != 0 || incy != 0 ? true : false);
                            if (!seq)
                            {
                                gens.Add(new MouseGeneralization(avg_x, avg_y, incx, incy, seq, new_gen.Time, prev_gen.Occurrences + 1));
                            }
                        }
                    }
                }
            }

            return(gens.ToArray());
        }