Beispiel #1
0
        /// <inheritdoc/>
        public override bool ValidateOldTheorem(ContextualPicture contextualPicture, Theorem oldTheorem)
        {
            // If we don't care whether the intersection point is outside or inside of the picture,
            // then there is no reason to say a theorem is invalid
            if (!ExpectAnyExternalIntersection)
            {
                return(true);
            }

            // Otherwise it might have happened that the new point is the one where the old theorem
            // stated an intersection theorem. We need to check this. Let's take the new point
            var newPoint = contextualPicture.NewPoints.FirstOrDefault();

            // If the last object hasn't been a point, then nothing as explained could have happened
            if (newPoint == null)
            {
                return(true);
            }

            // Otherwise we need to check whether the old theorem doesn't state that some objects
            // have an intersection point equal to the new point
            return(oldTheorem.InvolvedObjects
                   // We know the objects are with points
                   .Cast <TheoremObjectWithPoints>()
                   // For each we will find the corresponding geometric object definable by points
                   .Select(objectWithPoints =>
            {
                // If the object is defined explicitly, then we simply ask the picture to do the job
                if (objectWithPoints.DefinedByExplicitObject)
                {
                    return (DefinableByPoints)contextualPicture.GetGeometricObject(objectWithPoints.ConfigurationObject);
                }

                // Otherwise we need to find the inner points
                var innerPoints = objectWithPoints.Points
                                  // As geometric objects
                                  .Select(contextualPicture.GetGeometricObject)
                                  // They are points
                                  .Cast <PointObject>()
                                  // Enumerate
                                  .ToArray();

                // Base on the type of object we will take all lines / circles passing through the first point
                return (objectWithPoints switch
                {
                    // If we have a line, take lines
                    LineTheoremObject _ => innerPoints[0].Lines.Cast <DefinableByPoints>(),

                    // If we have a circle, take circles
                    CircleTheoremObject _ => innerPoints[0].Circles,

                    // Unhandled cases
                    _ => throw new TheoremFinderException($"Unhandled type of {nameof(TheoremObjectWithPoints)}: {objectWithPoints.GetType()}")
                })
                // Take the first line or circle that contains all the points
                .First(lineOrCircle => lineOrCircle.ContainsAll(innerPoints));
            })
        /// <inheritdoc/>
        public override IEnumerable <Theorem> FindNewTheorems(ContextualPicture contextualPicture)
        {
            // Get the last object of the configuration
            var lastConfigurationObject = contextualPicture.Pictures.Configuration.LastConstructedObject;

            // Distinguish cases bases on its type
            switch (lastConfigurationObject.ObjectType)
            {
            // If we have a point
            case Point:

                // We find its geometric version
                var geometricPoint = (PointObject)contextualPicture.GetGeometricObject(lastConfigurationObject);

                // Take all circles and lines
                return(geometricPoint.Lines.Cast <DefinableByPoints>().Concat(geometricPoint.Circles)
                       // That are defined explicitly
                       .Where(lineCircle => lineCircle.ConfigurationObject != null)
                       // Each makes a valid incidence
                       .Select(lineCircle => new Theorem(Type, lineCircle.ConfigurationObject, lastConfigurationObject)));

            // If we have a line or circle
            case Line:
            case Circle:

                // We find its geometric version
                var geometricLineCircle = (DefinableByPoints)contextualPicture.GetGeometricObject(lastConfigurationObject);

                // Take its points
                return(geometricLineCircle.Points
                       // Each makes a valid incidence theorem
                       .Select(point => new Theorem(Type, point.ConfigurationObject, lastConfigurationObject)));

            // Unhandled cases
            default:
                throw new TheoremFinderException($"Unhandled value of {nameof(ConfigurationObjectType)}: {lastConfigurationObject.ObjectType}");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Finds all options for changing the definition of a given old theorem object based on the new (last)
        /// configuration object, which might have geometric properties related to this old object (for example,
        /// if the new object is a point and the old one is a line/circle, then it might lie on it). This includes
        /// even an option of not changing the definition at all, i.e. returning the original old object.
        /// </summary>
        /// <param name="oldTheoremObject">The old theorem object for which we're looking for definition change options.</param>
        /// <param name="contextualPicture">The contextual picture that represents the configuration.</param>
        /// <returns>The enumeration of all possible definition changes, including no change.</returns>
        private static IEnumerable <TheoremObject> FindDefinitionChangeOptions(TheoremObject oldTheoremObject, ContextualPicture contextualPicture)
        {
            // Find the new object of the configuration
            var newConfigurationObject = contextualPicture.Pictures.Configuration.LastConstructedObject;

            // Find its geometric version
            var newGeometricObject = contextualPicture.GetGeometricObject(newConfigurationObject);

            // Switch based on the type of old object
            switch (oldTheoremObject)
            {
            // If we have a point or line segment (internally consisting of points...)
            case PointTheoremObject _:
            case LineSegmentTheoremObject _:

                // Then there is no way to find a new definition of the object,
                // i.e. we return the 'no change of definition' option
                return(new[] { oldTheoremObject });

            // If we have an object with points...
            case TheoremObjectWithPoints objectWithPoints:

                #region Find its geometric version

                // We're going to find the corresponding geometric version
                DefinableByPoints geometricObjectWithPoints = default;

                // If our object is defined explicitly
                if (objectWithPoints.DefinedByExplicitObject)
                {
                    // Use the internal configuration object to get the definition directly
                    geometricObjectWithPoints = (DefinableByPoints)contextualPicture.GetGeometricObject(objectWithPoints.ConfigurationObject);
                }

                // Otherwise it's defined by points
                else
                {
                    // Get the points corresponding to its points
                    var geometricPoints = objectWithPoints.Points
                                          // For each find the geometric point
                                          .Select(contextualPicture.GetGeometricObject)
                                          // We know they're points
                                          .Cast <PointObject>()
                                          // Enumerate
                                          .ToArray();

                    // Find the right object based on the type of the theorem object with points
                    geometricObjectWithPoints = (objectWithPoints switch
                    {
                        // Looking for the line that contains our points
                        // It certainly passes through the first point
                        LineTheoremObject _ => geometricPoints[0].Lines.First(line => line.ContainsAll(geometricPoints)) as DefinableByPoints,

                        // Looking for the circle that contains our points
                        // It certainly passes through the first point
                        CircleTheoremObject _ => geometricPoints[0].Circles.First(circle => circle.ContainsAll(geometricPoints)),

                        // Unhandled cases
                        _ => throw new TheoremFinderException($"Unhandled type of {nameof(TheoremObjectWithPoints)}: {objectWithPoints.GetType()}")
                    });
                }