Example #1
0
        /// <summary>
        /// Transitions from color to another.
        /// </summary>
        /// <param name="colorB">The color to transition from.</param>
        /// <param name="colorA">The color to transition to.</param>
        /// <param name="percentage">The percentage of the transition progress (values between 0 and 1).</param>
        /// <param name="evenColors">Color the generated color should differ from.</param>
        /// <returns>The new generated random color.</returns>
        public static RgbColor Transition(RgbColor colorA, RgbColor colorB, float percentage, bool evenColors = true)
        {
            ContractCheck.ValidPercentage(percentage, nameof(percentage));
            ContractCheck.ArgumentNotNull(colorA, nameof(colorA));
            ContractCheck.ArgumentNotNull(colorB, nameof(colorB));

            byte rd;
            byte gd;
            byte bd;

            if (evenColors)
            {
                rd = (byte)(colorA.R - (colorA.R - colorB.R) * percentage);
                gd = (byte)(colorA.G - (colorA.G - colorB.G) * percentage);
                bd = (byte)(colorA.B - (byte)((colorA.B - colorB.B) * percentage));
            }
            else
            {
                percentage = 1 - percentage;
                rd         = CalcColors(colorA.R, colorB.R, percentage);
                gd         = CalcColors(colorA.G, colorB.G, percentage);
                bd         = CalcColors(colorA.B, colorB.B, percentage);
            }

            return(new RgbColor(rd, gd, bd));
        }
Example #2
0
        private static SyntaxNode ProcessContract(SyntaxNode node, Scope scope, SyntacticalExtension <SyntaxNode> extension)
        {
            if (extension.Kind == ExtensionKind.Code)
            {
                var block = extension.Body as BlockSyntax;
                Debug.Assert(block != null);

                List <StatementSyntax> checks = new List <StatementSyntax>();
                foreach (var st in block.Statements)
                {
                    var stExpression = st as ExpressionStatementSyntax;
                    if (stExpression == null)
                    {
                        scope.AddError("contract01", "contracts only support boolean expressions", st);
                        continue;
                    }

                    var contractCheck = ContractCheck
                                        .ReplaceNodes(ContractCheck
                                                      .DescendantNodes()
                                                      .OfType <ExpressionSyntax>()
                                                      .Where(expr => expr.ToString() == "__condition"),

                                                      (oldNode, newNode) =>
                                                      stExpression.Expression);

                    checks.Add(contractCheck);
                }

                return(CSharp.Block(checks));
            }

            scope.AddError("contract02", "contract cannot return a value", node);
            return(node);
        }
        public ContractCheckDataStore()
        {
            client             = new HttpClient();
            client.BaseAddress = new Uri($"{App.BackendUrl}/");

            viewModels = new ContractCheck();

            items = new List <Contract>();
        }
Example #4
0
        /// <summary>
        /// Creates a new color based on a hex string.
        /// </summary>
        /// <param name="hex">Hex string representation of a RGB Color in the format '#000000'.</param>
        public RgbColor(string hex)
        {
            ContractCheck.ArgumentMatchesRegex(hex, nameof(hex), @"^#[0-9a-fA-F]{6}$");
            hex = hex.Replace("#", "", StringComparison.InvariantCultureIgnoreCase);
            var bigint = int.Parse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

            R = (byte)(bigint >> 16 & 255);
            G = (byte)(bigint >> 8 & 255);
            B = (byte)(bigint & 255);
        }
Example #5
0
 public ContractCheckTests()
 {
     this.dateNow = DateTime.UtcNow;
     this.doctrineShipsServices   = new DoctrineShipsServices(this.doctrineShipsRepository, this.eveDataSource, this.doctrineShipsValidation, null, this.logger);
     this.controller              = new SearchController(this.doctrineShipsServices);
     this.unitOfWork              = new UnitOfWork(new DoctrineShipsContext());
     this.eveDataSource           = new EveDataSourceCached(this.logger);
     this.doctrineShipsRepository = new DoctrineShipsRepository(this.unitOfWork);
     this.contractCheck           = new ContractCheck(this.doctrineShipsRepository);
     this.doctrineShipsValidation = new DoctrineShipsValidation(this.doctrineShipsRepository);
     this.loggerStore             = new DoctrineShipsRepository(this.unitOfWork);
     this.logger = new SystemLogger(this.loggerStore);
 }
        public async Task <IEnumerable <Contract> > GetItemsAsync(bool forceRefresh = false)
        {
            if (forceRefresh && IsConnected)
            {
                var json = await client.GetStringAsync($"api/CheckContract");

                viewModels = await Task.Run(() => JsonConvert.DeserializeObject <ContractCheck>(json));

                items = viewModels.ContractViewModels;
            }

            return(items);
        }
Example #7
0
        /// <summary>
        /// Checks whether two colors are similar to each other.
        /// </summary>
        /// <param name="colorA">First color for comparison.</param>
        /// <param name="colorB">Gets compared to colorA.</param>
        /// <param name="percentage">How similar the colors have to be between 0 and 1.</param>
        public static bool AreSimilar(RgbColor colorA, RgbColor colorB, float percentage)
        {
            ContractCheck.ValidPercentage(percentage, nameof(percentage));
            ContractCheck.ArgumentNotNull(colorA, nameof(colorA));
            ContractCheck.ArgumentNotNull(colorB, nameof(colorB));

            RgbColor c1 = new RgbColor(0, 0, 0);
            RgbColor c2 = new RgbColor(0, 0, 0);

            c1.R = Math.Min(colorA.R, colorB.R);
            c1.G = Math.Min(colorA.G, colorB.G);
            c1.B = Math.Min(colorA.B, colorB.B);

            c2.R = Math.Max(colorA.R, colorB.R);
            c2.G = Math.Max(colorA.G, colorB.G);
            c2.B = Math.Max(colorA.B, colorB.B);

            return(!(c1.R * 1.0 / c2.R < percentage ||
                     c1.G * 1.0 / c2.G < percentage ||
                     c1.B * 1.0 / c2.B < percentage));
        }
 public IValidationResult Contract(Contract contract)
 {
     return(ContractCheck.Contract(contract));
 }