public void AddFast(ref ColorMoment c2)
 {
     Alpha += c2.Alpha;
     Red += c2.Red;
     Green += c2.Green;
     Blue += c2.Blue;
     Weight += c2.Weight;
     Moment += c2.Moment;
 }
            public static void then_should_add_each_property_value_together()
            {
                // Arrange
                var colorMoment1 = new ColorMoment {
                    Alpha = 1, Blue = 2, Green = 3, Moment = 4, Red = 5, Weight = 6
                };
                var colorMoment2 = new ColorMoment {
                    Alpha = 6, Blue = 5, Green = 4, Moment = 3, Red = 2, Weight = 1
                };

                // Act
                var addedColor = colorMoment1 + colorMoment2;

                // Assert
                Assert.That(addedColor.Alpha, Is.EqualTo(7));
                Assert.That(addedColor.Blue, Is.EqualTo(7));
                Assert.That(addedColor.Green, Is.EqualTo(7));
                Assert.That(addedColor.Moment, Is.EqualTo(7));
                Assert.That(addedColor.Red, Is.EqualTo(7));
                Assert.That(addedColor.Weight, Is.EqualTo(7));
            }
Exemple #3
0
        private (byte?, float) MaxCutInDirection(Box box, int direction, byte first, byte last, ColorMoment boxWholeMoment)
        {
            ColorMoment bottomMoment = Bottom(box, direction);
            float       maxScore     = 0.0f;
            byte?       cutPoint     = null;

            for (byte position = first; position < last; ++position)
            {
                var lowerHalfMoment = Top(box, direction, position) - bottomMoment;
                if (lowerHalfMoment.Count == 0)
                {
                    continue;
                }
                var upperHalfMoment = boxWholeMoment - lowerHalfMoment;
                if (upperHalfMoment.Count == 0)
                {
                    continue;
                }
                var score = lowerHalfMoment.SquaredSumsOverCount + upperHalfMoment.SquaredSumsOverCount;
                // score is boxWholeMoment.Moment - (lowerHalfMoment.Variance + upperHalfMoment.Variance)
                // to minimise variance, we want to maximise this
                if (score > maxScore)
                {
                    maxScore = score;
                    cutPoint = position;
                }
            }
            return(cutPoint, maxScore);
        }
        private static CubeCut Maximize(ColorMoment[,,,] moments, Box cube, int direction, byte first, byte last, ColorMoment whole)
        {
            var  bottom   = Bottom(cube, direction, moments);
            var  result   = 0.0f;
            byte?cutPoint = null;

            for (var position = first; position < last; ++position)
            {
                var half = bottom + Top(cube, direction, position, moments);
                if (half.Weight == 0)
                {
                    continue;
                }

                var temp = half.WeightedDistance();

                half = whole - half;
                if (half.Weight != 0)
                {
                    temp += half.WeightedDistance();

                    if (temp > result)
                    {
                        result   = temp;
                        cutPoint = position;
                    }
                }
            }

            return(new CubeCut(cutPoint, result));
        }
        private static float CalculateVariance(ColorMoment[,,,] moments, Box cube)
        {
            ColorMoment volume = Volume(cube, moments);

            return(volume.Variance());
        }