Esempio n. 1
0
        public static HsvColor FromRgb(RgbColor color)
        {
            double value  = Comparables.Maximum(color.Red, color.Green, color.Blue);
            double chroma = value - Comparables.Minimum(color.Red, color.Green, color.Blue);

            if (chroma == 0)
            {
                return(new HsvColor(0, 0, value));
            }

            double hue = 0;

            if (value == color.Red)
            {
                hue = (color.Green - color.Blue) / chroma + 0;
            }
            if (value == color.Green)
            {
                hue = (color.Blue - color.Red) / chroma + 2;
            }
            if (value == color.Blue)
            {
                hue = (color.Red - color.Green) / chroma + 4;
            }

            return(new HsvColor(hue.Modulo(6), chroma / value, value));
        }
Esempio n. 2
0
        void InsertLength(double length)
        {
            if (PositionedControlComponents.Any(positionedControlComponent => positionedControlComponent.IsSelected))
            {
                return;
            }

            double newCurveLength = Comparables.Maximum(1, nextSpecification.CurveLength + length);

            ChangeCurveLength(newCurveLength);

            curveOptimizer.Submit(nextSpecification);
        }
Esempio n. 3
0
        void InsertLength(double position, double length)
        {
            double newCurveLength = Comparables.Maximum(1, nextSpecification.CurveLength + length);
            double lengthRatio    = nextSpecification.CurveLength / newCurveLength;

            ChangeCurveLength(newCurveLength);

            foreach (SpecificationComponent specificationComponent in SpecificationComponents)
            {
                specificationComponent.CurrentPosition = ShiftPosition(specificationComponent.CurrentPosition, position, lengthRatio);
            }

            RebuildCurveSpecification();

            curveOptimizer.Submit(nextSpecification);
        }
        public void RepositionRowForComparable(int comparableId)
        {
            var comparable = (from c in Comparables
                              where c.Id == comparableId
                              select c).FirstOrDefault();

            if (comparable == null)
            {
                return;
            }

            // refresh the comparable object
            var index = Comparables.IndexOf(comparable);
            var refreshedComparable = DataService.GetComparable(comparableId);

            Comparables[index] = refreshedComparable;

            // reorder the list again
            Comparables = Comparables.OrderBy(c => c.GetPricePerBaseUnit(Comparison.UnitId)).ToList();

            // get the new index of the comparable
            var newIndex = Comparables.IndexOf(refreshedComparable);

            if (newIndex == index)
            {
                var indexPaths = new NSIndexPath[] { NSIndexPath.FromRowSection(index, 0) };
                ReloadRows(indexPaths, UITableViewRowAnimation.None);
                SelectRow(indexPaths[0], false, UITableViewScrollPosition.None);
            }
            else
            {
                BeginUpdates();
                InsertRows(new NSIndexPath[] { NSIndexPath.FromRowSection(newIndex, 0) }, UITableViewRowAnimation.Fade);
                DeleteRows(new NSIndexPath[] { NSIndexPath.FromRowSection(index, 0) }, UITableViewRowAnimation.Fade);
                EndUpdates();
                if (newIndex == 0)
                {
                    UpdateCheapestComparable(refreshedComparable);
                }
            }
        }
 public void AddComparable(ComparableModel comparable)
 {
     if (Comparables.Count == 0)
     {
         Comparables.Add(comparable);
         UpdateCheapestComparable(comparable);
         ReloadRows(new NSIndexPath[] { NSIndexPath.FromRowSection(0, 0) }, UITableViewRowAnimation.Fade);
     }
     else
     {
         Comparables.Add(comparable);
         Comparables = Comparables.OrderBy(c => c.GetPricePerBaseUnit(Comparison.UnitId)).ToList();
         var addedAt = Comparables.IndexOf(comparable);
         if (addedAt == 0)
         {
             UpdateCheapestComparable(comparable);
         }
         BeginUpdates();
         InsertRows(new NSIndexPath[] { NSIndexPath.FromRowSection(addedAt, 0) }, UITableViewRowAnimation.Fade);
         EndUpdates();
     }
     SetScrollAndSelection();
 }