Esempio n. 1
0
        private static void CalculateMoments(ColorMoment[,,,] moments)
        {
            var areaSquared = new ColorMoment[SideSize, SideSize];
            var area        = new ColorMoment[SideSize];

            for (int alphaIndex = 1; alphaIndex < SideSize; alphaIndex++)
            {
                for (int redIndex = 1; redIndex < SideSize; redIndex++)
                {
                    Array.Clear(area, 0, area.Length);
                    for (int greenIndex = 1; greenIndex < SideSize; greenIndex++)
                    {
                        var line = new ColorMoment();
                        for (int blueIndex = 1; blueIndex < SideSize; blueIndex++)
                        {
                            line.AddFast(ref moments[alphaIndex, redIndex, greenIndex, blueIndex]);
                            area[blueIndex].AddFast(ref line);
                            areaSquared[greenIndex, blueIndex].AddFast(ref area[blueIndex]);

                            ColorMoment moment = moments[alphaIndex - 1, redIndex, greenIndex, blueIndex];
                            moment.AddFast(ref areaSquared[greenIndex, blueIndex]);
                            moments[alphaIndex, redIndex, greenIndex, blueIndex] = moment;
                        }
                    }
                }
            }
        }
        private static void CalculateMoments(ColorMoment[, , ,] moments)
        {
            ColorMoment[,] areaSquared = new ColorMoment[SideSize, SideSize];
            ColorMoment[] area = new ColorMoment[SideSize];
            for (int alphaIndex = 1; alphaIndex < SideSize; alphaIndex++)
            {
                for (int redIndex = 1; redIndex < SideSize; redIndex++)
                {
                    Array.Clear(area, 0, area.Length);
                    for (int greenIndex = 1; greenIndex < SideSize; greenIndex++)
                    {
                        ColorMoment line = new ColorMoment();
                        for (int blueIndex = 1; blueIndex < SideSize; blueIndex++)
                        {
                            line.AddFast(ref moments[alphaIndex, redIndex, greenIndex, blueIndex]);
                            area[blueIndex].AddFast(ref line);
                            areaSquared[greenIndex, blueIndex].AddFast(ref area[blueIndex]);

                            ColorMoment moment = moments[alphaIndex - 1, redIndex, greenIndex, blueIndex];
                            moment.AddFast(ref areaSquared[greenIndex, blueIndex]);
                            moments[alphaIndex, redIndex, greenIndex, blueIndex] = moment;
                        }
                    }
                }
            }
        }
            public static void then_should_add_each_property_value_together()
            {

                // Arrange
                var colorMoment = new ColorMoment { Alpha = 1, Blue = 2, Green = 3, Moment = 4, Red = 5, Weight = 6 };

                // Act
                colorMoment.AddFast(ref colorMoment);

                // Assert
                Assert.That(colorMoment.Alpha, Is.EqualTo(2));
                Assert.That(colorMoment.Red, Is.EqualTo(10));
                Assert.That(colorMoment.Green, Is.EqualTo(6));
                Assert.That(colorMoment.Blue, Is.EqualTo(4));
                Assert.That(colorMoment.Moment, Is.EqualTo(8.0f));
                Assert.That(colorMoment.Weight, Is.EqualTo(12));
            }