예제 #1
0
        protected override Vector2 CalculateMinimumSize()
        {
            var separation = ActualSeparation;

            var minWidth  = 0f;
            var minHeight = 0f;
            var first     = true;

            foreach (var child in Children)
            {
                if (!child.Visible)
                {
                    continue;
                }

                var(childWidth, childHeight) = child.CombinedMinimumSize;
                if (Vertical)
                {
                    minHeight += childHeight;
                    if (!first)
                    {
                        minHeight += separation;
                    }

                    first = false;

                    minWidth = MathF.Max(minWidth, childWidth);
                }
                else
                {
                    minWidth += childWidth;
                    if (!first)
                    {
                        minWidth += separation;
                    }

                    first = false;

                    minHeight = MathF.Max(minHeight, childHeight);
                }
            }

            return(new Vector2(minWidth, minHeight));
        }
예제 #2
0
 public static float Median(float a, float b, float c)
 {
     return(MathF.Max(MathF.Min(a, b), MathF.Min(MathF.Max(a, b), c)));
 }
예제 #3
0
 public static float Max(float a, float b, float c, float d)
 {
     return(MathF.Max(a, MathF.Max(b, MathF.Max(c, d))));
 }
예제 #4
0
파일: Ray.cs 프로젝트: exp111/RobustToolbox
        public bool Intersects(Box2 box, out float distance, out Vector2 hitPos)
        {
            hitPos   = Vector2.Zero;
            distance = 0;

            var         tmin    = 0.0f;           // set to -FLT_MAX to get first hit on line
            var         tmax    = float.MaxValue; // set to max distance ray can travel (for segment)
            const float epsilon = 1.0E-07f;

            // X axis slab
            {
                if (MathF.Abs(_direction.X) < epsilon)
                {
                    // ray is parallel to this slab, it will never hit unless ray is inside box
                    if (_position.X < MathF.Min(box.Left, box.Right) || _position.X > MathF.Max(box.Left, box.Right))
                    {
                        return(false);
                    }
                }

                // calculate intersection t value of ray with near and far plane of slab
                var ood = 1.0f / _direction.X;
                var t1  = (MathF.Min(box.Left, box.Right) - _position.X) * ood;
                var t2  = (MathF.Max(box.Left, box.Right) - _position.X) * ood;

                // Make t1 be the intersection with near plane, t2 with far plane
                if (t1 > t2)
                {
                    MathHelper.Swap(ref t1, ref t2);
                }

                // Compute the intersection of slab intersection intervals
                tmin = MathF.Max(t1, tmin);
                tmax = MathF.Min(t2, tmax); // Is this Min (SE) or Max(Textbook)

                // Exit with no collision as soon as slab intersection becomes empty
                if (tmin > tmax)
                {
                    return(false);
                }
            }

            // Y axis slab
            {
                if (MathF.Abs(_direction.Y) < epsilon)
                {
                    // ray is parallel to this slab, it will never hit unless ray is inside box
                    if (_position.Y < MathF.Min(box.Top, box.Bottom) || _position.Y > MathF.Max(box.Top, box.Bottom))
                    {
                        return(false);
                    }
                }

                // calculate intersection t value of ray with near and far plane of slab
                var ood = 1.0f / _direction.Y;
                var t1  = (MathF.Min(box.Top, box.Bottom) - _position.Y) * ood;
                var t2  = (MathF.Max(box.Top, box.Bottom) - _position.Y) * ood;

                // Make t1 be the intersection with near plane, t2 with far plane
                if (t1 > t2)
                {
                    MathHelper.Swap(ref t1, ref t2);
                }

                // Compute the intersection of slab intersection intervals
                tmin = MathF.Max(t1, tmin);
                tmax = MathF.Min(t2, tmax); // Is this Min (SE) or Max(Textbook)

                // Exit with no collision as soon as slab intersection becomes empty
                if (tmin > tmax)
                {
                    return(false);
                }
            }

            // Ray intersects all slabs. Return point and intersection t value
            hitPos   = _position + _direction * tmin;
            distance = tmin;
            return(true);
        }