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)
         );
 }
Example #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;
        }
 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;
 }
 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;
 }
Example #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;
        }
Example #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);
            }
        }
Example #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;
        }
Example #8
0
 public bool continuingStroke(StrokeDirection stroke, Position start, Position end)
 {
     return determineDirection(start, end) == stroke;
 }
Example #9
0
 public Boolean continuingStroke(StrokeDirection stroke, Position start, Position end)
 {
     StrokeDirection newStroke = determineDirection (start, end);
     return newStroke == stroke;
 }
Example #10
0
 public Stroke(StrokeDirection direction, Position start, Position end)
 {
     this.direction = direction;
     this.start = start;
     this.end = end;
 }
Example #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);
 }