Пример #1
0
    private static bool ProportionalLines(float[][] matrix, float[] vector, int i, int j)
    {
        float firstQuotient  = matrix[i][0] / matrix[j][0];
        float secondQuotient = matrix[i][1] / matrix[j][1];
        float thirdQuotient  = vector[i] / vector[j];

        if (firstQuotient.ApproximatelyEquals(secondQuotient, _approximation) &&
            firstQuotient.ApproximatelyEquals(thirdQuotient, _approximation))
        {
            return(true);
        }

        if (float.IsNaN(firstQuotient) && secondQuotient.ApproximatelyEquals(thirdQuotient, _approximation))
        {
            return(true);
        }

        if (float.IsNaN(secondQuotient) && firstQuotient.ApproximatelyEquals(thirdQuotient, _approximation))
        {
            return(true);
        }

        if (float.IsNaN(thirdQuotient) && firstQuotient.ApproximatelyEquals(secondQuotient, _approximation))
        {
            return(true);
        }

        return(false);
    }
        private void AdjustHeightIfNeeded()
        {
            if (!_preventExpandingHeight)
            {
                return;
            }

            if (_contentHeight.ApproximatelyEquals(position.height))
            {
                return;
            }

            Rect positionToAdjust = position;

            positionToAdjust.height = Math.Min(_contentHeight, DropdownStyle.MaxWindowHeight);
            minSize = new Vector2(minSize.x, positionToAdjust.height);
            maxSize = new Vector2(maxSize.x, positionToAdjust.height);
            float screenHeight = Screen.currentResolution.height - 40f;

            if (positionToAdjust.yMax >= screenHeight)
            {
                positionToAdjust.y -= positionToAdjust.yMax - screenHeight;
            }

            position = positionToAdjust;
        }
Пример #3
0
 public bool Equals(Vector other)
 {
     return(X.ApproximatelyEquals(other.X) &&
            Y.ApproximatelyEquals(other.Y) &&
            Z.ApproximatelyEquals(other.Z) &&
            W.ApproximatelyEquals(other.W));
 }
Пример #4
0
 public void ToggleGlow(bool enable)
 {
     if (enable == originalGlowRadius.ApproximatelyEquals(Props.glowRadius))
     {
         return;
     }
     Props.glowRadius = enable ? originalGlowRadius : 0f;
     // reset cache in parent class
     RemoteTechController.Instance.CompGlowerGlowOnField.SetValue(this, !(bool)RemoteTechController.Instance.CompGlowerShouldBeLitProperty.GetValue(this, null));
     UpdateLit(parent.Map);
 }
Пример #5
0
        public void Intersect(Point origin, Vector direction, float t0, float t1)
        {
            var cone = new Cone();

            direction = Vector.Normalize(direction);
            var ray = new Ray(origin, direction);

            var intersections = cone.Intersect(ray);

            Assert.Equal(2, intersections.Count);
            Assert.True(t0.ApproximatelyEquals(intersections[0].Time));
            Assert.True(t1.ApproximatelyEquals(intersections[1].Time));
        }
Пример #6
0
        public void ApproximatelyEquals_ShouldReturnExpectedResult(
            float lhs,
            float rhs,
            bool expected
            )
        {
            // arrange
            // act
            var actual = lhs.ApproximatelyEquals(rhs);

            // assert
            actual.Should().Be(expected, $"{lhs} should {(expected ? "" : "not ")} equal {rhs}");
        }
Пример #7
0
        public Color RefractedColor(IntersectionInfo info, int remaining)
        {
            if (remaining < 1)
            {
                return(Color.Black);
            }

            float materialTransparency = info.Intersection.Shape.Material.Transparency;

            if (materialTransparency.ApproximatelyEquals(0))
            {
                return(Color.Black);
            }

            // Find the ratio of the first index of refraction to the second
            float ratio = info.RefractiveIndex1 / info.RefractiveIndex2;

            // Theta_i is the angle of the incoming ray
            // Cos(Theta_i) is the same as the dot product of the two vectors
            float cosineI = Vector.Dot(info.EyeVector, info.Normal);

            // Theta_t is the angle of the refracted ray
            // Find Sin(Theta_t)^2
            float sin2T = (ratio * ratio) * (1 - (cosineI * cosineI));

            if (sin2T > 1)
            {
                // Total internal reflection
                return(Color.Black);
            }

            float cosineT = MathF.Sqrt(1 - sin2T);

            // Compute direction of the refracted ray
            var direction = info.Normal * (ratio * cosineI - cosineT) - info.EyeVector * ratio;

            var refractedRay = new Ray(info.UnderPoint, direction);

            return(ColorAt(refractedRay, remaining - 1) * materialTransparency);
        }
Пример #8
0
 public bool Equals(Distance other)
 {
     return(AsMeters
            .ApproximatelyEquals(other.AsMeters));
 }
Пример #9
0
 public static bool ApproximatelyGreaterThan(this float thisFloat, float otherFloat, float differenceCap)
 {
     return((thisFloat > otherFloat) || thisFloat.ApproximatelyEquals(otherFloat, differenceCap));
 }
Пример #10
0
 public bool Equals(Speed other)
 {
     return(AsMetersPerSecond
            .ApproximatelyEquals(other.AsKilometersPerHour));
 }
Пример #11
0
 /// <summary>Determines if the number are not equal with a certain tolerance.</summary>
 /// <param name="firstNum">First number.</param>
 /// <param name="secondNum">Second number.</param>
 /// <param name="tolerance">Tolerance by which to determine if the numbers are equal. Default is 0.01f.</param>
 /// <returns>Whether the numbers are not equal with tolerance.</returns>
 /// <example><code>
 /// if (_optimalWidth.DoesNotEqualApproximately(position.width))
 ///     this.Resize(_optimalWidth);
 /// </code></example>
 [PublicAPI] public static bool DoesNotEqualApproximately(this float firstNum, float secondNum, float tolerance = 0.01f) =>
 !firstNum.ApproximatelyEquals(secondNum, tolerance);
Пример #12
0
 public bool Equals(Color other)
 {
     return(R.ApproximatelyEquals(other.R) &&
            G.ApproximatelyEquals(other.G) &&
            B.ApproximatelyEquals(other.B));
 }