示例#1
0
 public static double Distance(Position start, Position end)
 {
     return Math.Sqrt(
         Math.Pow(end.point.X - start.point.X, 2) +
         Math.Pow(end.point.Y - start.point.Y, 2)
         );
 }
示例#2
0
        public Spell handleAdd(Position pos)
        {
            if (spell == null)
            {
                addPosition(pos);

                if (positions.Count > 10)
                {
                    if (wandIsPaused(positions))
                    {
                        Spell chosen = brain.chooseSpell(positions);
                        if (chosen != null)
                        {
                            for (int i = 0; i < spellNames.Count; i++)
                            {
                                if (spellNames[i].Equals(chosen.GetType().Name))
                                {
                                    spell = chosen;
                                    /*
                                    ((CloudBitSpell)spell).setConfigurations(device, authorization, spellVoltages[i], spellDurations[i], iftttUserKey, spellIftttEvents[i]);
                                    spell.castSpell();
                                    */
                                    startSpell = DateTime.Now;
                                }
                            }
                        }

                        /*
                        strokes = decomposer.determineStrokes(positions);

                        // TODO: move to class for choosing which spell was cast
                        foreach (SpellTrigger trigger in spells)
                        {
                            if (trigger.triggered(strokes))
                            {
                                spell = trigger;
                                trigger.castSpell();
                                startSpell = DateTime.Now;
                            }
                        }
                         */
                    }
                }
            }
            else if (!spell.casting())
            {
                spell = null;
                positions.Clear();
                if (strokes != null)
                {
                    strokes.Clear();
                }
            }

            return spell;
        }
示例#3
0
 public double FractionOfTotal(Position start, Position end)
 {
     double size = Distance(start, end);
     double totalSize = Diagonal();
     if (totalSize == 0.0)
     {
         return double.PositiveInfinity;
     }
     return size / totalSize;
 }
示例#4
0
 public static double Slope(Position start, Position end)
 {
     double slope = 0.0;
     if (end.point.X - start.point.X == 0)
     {
         slope = double.PositiveInfinity;
     }
     else
     {
         slope = ((double)end.point.Y - start.point.Y) / (end.point.X - start.point.X);
     }
     return slope;
 }
示例#5
0
        // TODO: Not handling curved lines
        public static StrokeDirection determineDirection(Position start, Position end)
        {
            double angleFactor = 2.0;
            double ratioXToY = ((double)PositionStatistics.MAX_X) / PositionStatistics.MAX_Y;
            angleFactor = angleFactor * ratioXToY;

            StrokeDirection stroke = StrokeDirection.Bumbled;

            int deltaX = start.point.X - end.point.X; // 0 is far right for some reason
            int deltaY = end.point.Y - start.point.Y;

            // Avoid divide by zero
            if (deltaX == 0) {
                if (deltaY > 0) {
                    stroke = StrokeDirection.Up;
                } else {
                    stroke = StrokeDirection.Down;
                }
                return stroke;
            }

            double slope = ((double) deltaY) / deltaX;

            if (slope < -angleFactor || slope >= angleFactor) {
                if (deltaY > 0) {
                    stroke = StrokeDirection.Up;
                } else {
                    stroke = StrokeDirection.Down;
                }
            } else if (slope >= -angleFactor && slope < -(1/angleFactor)) {
                if (deltaX > 0) {
                    stroke = StrokeDirection.DownToTheRight;
                } else {
                    stroke = StrokeDirection.UpToTheLeft;
                }
            } else if (slope >= -(1/angleFactor) && slope < (1/angleFactor)) {
                if (deltaX > 0) {
                    stroke = StrokeDirection.Right;
                } else {
                    stroke = StrokeDirection.Left;
                }
            } else if (slope >= (1/angleFactor) && slope < angleFactor) {
                if (deltaX > 0) {
                    stroke = StrokeDirection.UpToTheRight;
                } else {
                    stroke = StrokeDirection.DownToTheLeft;
                }
            }

            return stroke;
        }
示例#6
0
        private void addPosition(Position position)
        {
            positions.Add(position);

            // Remove all but last 2 seconds
            var timeOfLatest = position.time;

            int idx = positions.Count - 1;
            while (idx >= 0
                && timeOfLatest.Subtract(positions.ElementAt(idx).time).TotalSeconds < 2)
            {
                idx--;
            }

            if (idx > 0) {
                positions.RemoveRange (0, idx);
            }
        }
示例#7
0
        public bool strokeIsValid(StrokeDirection stroke, Position start, Position end)
        {
            int deltaX = start.point.X - end.point.X;
            int deltaY = start.point.Y - end.point.Y;

            double length = Math.Sqrt (Math.Pow(deltaX,2) + Math.Pow(deltaY,2));
            double percent = length / Math.Max (maxX, maxY);
            if (length > 0)
            {
                percent *= 100;
            }

            return percent >= minPctForStroke;
        }
示例#8
0
 public bool continuingStroke(StrokeDirection stroke, Position start, Position end)
 {
     return determineDirection(start, end) == stroke;
 }
示例#9
0
 public Boolean continuingStroke(StrokeDirection stroke, Position start, Position end)
 {
     StrokeDirection newStroke = determineDirection (start, end);
     return newStroke == stroke;
 }
示例#10
0
 public Stroke(StrokeDirection direction, Position start, Position end)
 {
     this.direction = direction;
     this.start = start;
     this.end = end;
 }
示例#11
0
 public static double Slope(Position start, Position end)
 {
     var calculate = end.point.X - start.point.X;
     return calculate == 0 ? double.PositiveInfinity : ((double)end.point.Y - start.point.Y) / (end.point.X - start.point.X);
 }