Ejemplo n.º 1
0
        public void EqualWhenSameInstance()
        {
            GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);
            var testSubject            = position1;

            Assert.IsTrue(testSubject == position1);
        }
Ejemplo n.º 2
0
        public void EqualWhenEverythingMatches()
        {
            GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);
            object           position2 = new GeometryPosition(10, 20, 30, 40);

            Assert.IsTrue(position1.Equals(position2));
        }
Ejemplo n.º 3
0
        public void NotEqualPositions()
        {
            GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);
            GeometryPosition position2 = new GeometryPosition(40, 30, 20, 10);

            Assert.IsTrue(position1 != position2);
        }
Ejemplo n.º 4
0
        public void NotEqualObjects()
        {
            GeographyPosition position1 = new GeographyPosition(10, 20, 30, 40);
            GeometryPosition  position2 = new GeometryPosition(10, 20, 30, 40);

            Assert.False(position1.Equals(position2));
        }
Ejemplo n.º 5
0
 public void Points()
 {
     GeometryPosition position = new GeometryPosition(2.0, 3.0);
     Assert.AreEqual("geo.distance(geography'POINT(2 3)', Foo) < 3", SearchFilter.Create($"geo.distance({position}, Foo) < 3"));
     Assert.AreEqual("geo.distance(geography'POINT(2 3)', Foo) < 3", SearchFilter.Create($"geo.distance({new GeometryPosition(2.0, 3.0, 5.0)}, Foo) < 3"));
     Assert.AreEqual("geo.distance(geography'POINT(2 3)', Foo) < 3", SearchFilter.Create($"geo.distance({new PointGeometry(position)}, Foo) < 3"));
 }
Ejemplo n.º 6
0
        public void GetHashCodeImplementation()
        {
            GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);
            Assert.Equal(2139226112, position1.GetHashCode());

            GeometryPosition position2 = new GeometryPosition(10, 20, null, null);
            Assert.Equal(48234496, position2.GetHashCode());
        }
Ejemplo n.º 7
0
        public void GetHashCodeImplementation()
        {
            GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);

            Assert.AreEqual(2139226112, position1.GetHashCode());

            GeometryPosition position2 = new GeometryPosition(10, 20, null, null);

            Assert.AreEqual(48234496, position2.GetHashCode());
        }
Ejemplo n.º 8
0
 protected override GeometryPosition OnLineTo(GeometryPosition position)
 {
     if (!this.processingGeography)
     {
         ValidateGeometryPosition(position.X, position.Y, position.Z, position.M);
     }
     this.AddControlPoint(position.X, position.Y);
     if (this.processingGeography)
     {
         throw new FormatException(Strings.Validator_UnexpectedGeography);
     }
     return(position);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Convert a <see cref="GeometryPosition"/> to an OData value.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <returns>The OData representation of the position.</returns>
        private static string EncodeGeometry(GeometryPosition position)
        {
            const int maxLength =
                19 +       // "geography'POINT( )'".Length
                2 *        // Lat and Long each have:
                (15 +      //     Maximum precision for a double (without G17)
                 1 +       //     Optional decimal point
                 1);       //     Optional negative sign
            StringBuilder odata = new StringBuilder(maxLength);

            odata.Append("geography'POINT(");
            odata.Append(JsonSerialization.Double(position.Longitude, CultureInfo.InvariantCulture));
            odata.Append(" ");
            odata.Append(JsonSerialization.Double(position.Latitude, CultureInfo.InvariantCulture));
            odata.Append(")'");
            return(odata.ToString());
        }
Ejemplo n.º 10
0
 internal static void SendFigure(this GeometryLineString GeometryLineString, GeometryPipeline pipeline)
 {
     Util.CheckArgumentNull(GeometryLineString, "GeometryLineString");
     for (int i = 0; i < GeometryLineString.Points.Count; i++)
     {
         GeometryPoint point = GeometryLineString.Points[i];
         GeometryPosition position = new GeometryPosition(point.X, point.Y, point.Z, point.M);
         if (i == 0)
         {
             pipeline.BeginFigure(position);
         }
         else
         {
             pipeline.LineTo(position);
         }
     }
     if (GeometryLineString.Points.Count > 0)
     {
         pipeline.EndFigure();
     }
 }
Ejemplo n.º 11
0
 internal static void SendFigure(this GeometryLineString GeometryLineString, GeometryPipeline pipeline)
 {
     Util.CheckArgumentNull(GeometryLineString, "GeometryLineString");
     for (int i = 0; i < GeometryLineString.Points.Count; i++)
     {
         GeometryPoint    point    = GeometryLineString.Points[i];
         GeometryPosition position = new GeometryPosition(point.X, point.Y, point.Z, point.M);
         if (i == 0)
         {
             pipeline.BeginFigure(position);
         }
         else
         {
             pipeline.LineTo(position);
         }
     }
     if (GeometryLineString.Points.Count > 0)
     {
         pipeline.EndFigure();
     }
 }
Ejemplo n.º 12
0
 public override void BeginFigure(GeometryPosition position)
 {
 }
Ejemplo n.º 13
0
 public override void BeginFigure(GeometryPosition position)
 {
     logger.AddCoordinates(PipelineMethod.GeometryBeginFigure, position.X, position.Y, position.Z, position.M);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Draw a point in the specified coordinate
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>The position to be passed down the pipeline</returns>
 protected virtual GeometryPosition OnLineTo(GeometryPosition position)
 {
     return position;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Draw a point in the specified coordinate
 /// </summary>
 /// <param name="position">Next position</param>
 public override void LineTo(GeometryPosition position)
 {
     both.OnLineTo(position);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Draw a point in the specified coordinate
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>
 /// The position to be passed down the pipeline
 /// </returns>
 protected override GeometryPosition OnLineTo(GeometryPosition position)
 {
     this.WriteControlPoint(position.X, position.Y, position.Z, position.M);
     return position;
 }
 /// <summary>
 /// Begins a figure.
 /// </summary>
 /// <param name="position">The position of the control point.</param>
 public override void BeginFigure(GeometryPosition position)
 {
     this.Destination.BeginFigure(this.ConvertPosition(position));
 }
Ejemplo n.º 18
0
 protected virtual GeometryPosition OnBeginFigure(GeometryPosition position)
 {
     return(position);
 }
Ejemplo n.º 19
0
 protected override GeometryPosition OnBeginFigure(GeometryPosition position)
 {
     this.BeginFigure(new Action<double, double, double?, double?>(SpatialValidatorImplementation.NestedValidator.ValidateGeometryPosition), position.X, position.Y, position.Z, position.M);
     return position;
 }
 /// <summary>
 /// Implemented by a subclass to handle the start of a figure
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>The position to be passed down the pipeline</returns>
 protected override GeometryPosition OnBeginFigure(GeometryPosition position)
 {
     BeginFigure(ValidateGeometryPosition, position.X, position.Y, position.Z, position.M);
     return position;
 }
Ejemplo n.º 21
0
 public void NotEqualPositions()
 {
     GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);
     GeometryPosition position2 = new GeometryPosition(40, 30, 20, 10);
     Assert.True(position1 != position2);
 }
Ejemplo n.º 22
0
 public void EqualWhenSameInstance()
 {
     GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);
     var testSubject = position1;
     Assert.True(testSubject == position1);
 }
Ejemplo n.º 23
0
 public void EqualWhenEverythingMatches()
 {
     GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);
     object position2 = new GeometryPosition(10, 20, 30, 40);
     Assert.True(position1.Equals(position2));
 }
Ejemplo n.º 24
0
 public void NotEqualToNull()
 {
     GeometryPosition position1 = new GeometryPosition(10, 20, 30, 40);
     Assert.False(position1.Equals(null));
 }
Ejemplo n.º 25
0
 public override void LineTo(GeometryPosition position)
 {
     sum += this.sign * (position.X + position.Y);
 }
Ejemplo n.º 26
0
 protected virtual GeometryPosition OnLineTo(GeometryPosition position)
 {
     return(position);
 }
Ejemplo n.º 27
0
 public override void BeginFigure(GeometryPosition position)
 {
     sum += this.sign * (position.X + position.Y);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Begin drawing a figure
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>The position to be passed down the pipeline</returns>
 protected override GeometryPosition OnBeginFigure(GeometryPosition position)
 {
     WriteFigureScope(position.X, position.Y, position.Z, position.M);
     return(position);
 }
Ejemplo n.º 29
0
 public void NotEqualObjects()
 {
     GeographyPosition position1 = new GeographyPosition(10, 20, 30, 40);
     GeometryPosition position2 = new GeometryPosition(10, 20, 30, 40);
     Assert.False(position1.Equals(position2));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Draw a point in the specified coordinate
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>
 /// The position to be passed down the pipeline
 /// </returns>
 protected override GeometryPosition OnLineTo(GeometryPosition position)
 {
     this.WriteControlPoint(position.X, position.Y, position.Z, position.M);
     return(position);
 }
Ejemplo n.º 31
0
 public override void BeginFigure(GeometryPosition position)
 {
     logger.AddCoordinates(PipelineMethod.GeometryBeginFigure, position.X, position.Y, position.Z, position.M);
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Begin drawing a figure
 /// </summary>
 /// <param name="position">Next position</param>
 public override void BeginFigure(GeometryPosition position)
 {
     both.OnBeginFigure(position);
 }
Ejemplo n.º 33
0
 public override void BeginFigure(GeometryPosition position)
 {
     Debug.Assert(position != null, "ForwardingSegment should have validated nullness");
     this.builder.BeginFigure(position.X, position.Y, position.Z, position.M);
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Begin drawing a figure
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>The position to be passed down the pipeline</returns>
 protected virtual GeometryPosition OnBeginFigure(GeometryPosition position)
 {
     return position;
 }
Ejemplo n.º 35
0
 public override void LineTo(GeometryPosition position)
 {
     this.builder.LineTo(position.X, position.Y, position.Z, position.M);
 }
Ejemplo n.º 36
0
 public override void LineTo(GeometryPosition position)
 {
     logger.AddCoordinates(PipelineMethod.GeometryAddLineTo, position.X, position.Y, position.Z, position.M);
 }
Ejemplo n.º 37
0
 public override void LineTo(GeometryPosition position)
 {
     this.tracingPipe.Trace("Geometry.LineTo", position);
 }
Ejemplo n.º 38
0
 public override void LineTo(GeometryPosition position)
 {
 }
Ejemplo n.º 39
0
 public override void BeginFigure(GeometryPosition position)
 {
     this.parent.coordinates.Add(new PositionData(position.X, position.Y, position.Z, position.M));
 }
Ejemplo n.º 40
0
        /// <summary>
        /// Create an OData filter expression from an interpolated string.  The
        /// interpolated values will be quoted and escaped as necessary.
        /// </summary>
        /// <param name="filter">An interpolated filter string.</param>
        /// <param name="formatProvider">
        /// Format provider used to convert values to strings.
        /// <see cref="CultureInfo.InvariantCulture"/> is used as a default.
        /// </param>
        /// <returns>A valid OData filter expression.</returns>
        public static string Create(FormattableString filter, IFormatProvider formatProvider)
        {
            if (filter == null)
            {
                return(null);
            }
            formatProvider ??= CultureInfo.InvariantCulture;

            string[] args = new string[filter.ArgumentCount];
            for (int i = 0; i < filter.ArgumentCount; i++)
            {
                args[i] = filter.GetArgument(i) switch
                {
                    // Null
                    null => "null",

                    // Boolean
                    bool x => x.ToString(formatProvider).ToLowerInvariant(),

                    // Numeric
                    sbyte x => x.ToString(formatProvider),
                    byte x => x.ToString(formatProvider),
                    short x => x.ToString(formatProvider),
                    ushort x => x.ToString(formatProvider),
                    int x => x.ToString(formatProvider),
                    uint x => x.ToString(formatProvider),
                    long x => x.ToString(formatProvider),
                    ulong x => x.ToString(formatProvider),
                    decimal x => x.ToString(formatProvider),

                    // Floating point
                    float x => JsonSerialization.Float(x, formatProvider),
                    double x => JsonSerialization.Double(x, formatProvider),

                    // Dates as 8601 with a time zone
                    DateTimeOffset x => JsonSerialization.Date(x, formatProvider),
                    DateTime x => JsonSerialization.Date(x, formatProvider),

#if EXPERIMENTAL_SPATIAL
                    // Points
                    GeometryPosition x => EncodeGeometry(x),
                    PointGeometry x => EncodeGeometry(x),

                    // Polygons
                    LineGeometry x => EncodeGeometry(x),
                    PolygonGeometry x => EncodeGeometry(x),
#endif

                    // Text
                    string x => Quote(x),
                    char x => Quote(x.ToString(formatProvider)),
                    StringBuilder x => Quote(x.ToString()),

                    // Everything else
                    object x => throw new ArgumentException(
                              $"Unable to convert argument {i} from type {x.GetType()} to an OData literal.")
                };
            }
            string text = string.Format(formatProvider, filter.Format, args);
            return(text);
        }
            /// <summary>
            /// Implemented by a subclass to handle the addition of a waypoint to a Geometry figure
            /// </summary>
            /// <param name="position">Next position</param>
            /// <returns>the GeometryPosition to be passed down the pipeline</returns>
            protected override GeometryPosition OnLineTo(GeometryPosition position)
            {
                if (!this.processingGeography)
                {
                    ValidateGeometryPosition(position.X, position.Y, position.Z, position.M);
                }

                AddControlPoint(position.X, position.Y);

                if (this.processingGeography)
                {
                    throw new FormatException(Strings.Validator_UnexpectedGeography);
                }

                return position;
            }
Ejemplo n.º 42
0
 public override void LineTo(GeometryPosition position)
 {
     logger.AddCoordinates(PipelineMethod.GeometryAddLineTo, position.X, position.Y, position.Z, position.M);
 }
Ejemplo n.º 43
0
 public abstract void BeginFigure(GeometryPosition position);
Ejemplo n.º 44
0
 public override void BeginFigure(GeometryPosition position)
 {
     this.builder.BeginFigure(position.X, position.Y, position.Z, position.M);
 }
Ejemplo n.º 45
0
 public abstract void LineTo(GeometryPosition position);
Ejemplo n.º 46
0
 public override void BeginFigure(GeometryPosition position)
 {
     this.tracingPipe.Trace("Geometry.BeginFigure", position);
 }
 /// <summary>
 /// Adds a geometric control point.
 /// </summary>
 /// <param name="position">The position of the control point.</param>
 public override void LineTo(GeometryPosition position)
 {
     this.Destination.LineTo(this.ConvertPosition(position));
 }
 /// <summary>
 /// Begins a figure.
 /// </summary>
 /// <param name="position">The position of the control point.</param>
 public override void BeginFigure(GeometryPosition position)
 {
     this.Destination.BeginFigure(this.ConvertPosition(position));
 }
 /// <summary>
 /// Converts the position with the Y coordinate as latitude.
 /// </summary>
 /// <param name="position">The position to convert.</param>
 /// <returns>The converted position</returns>
 internal static GeographyPosition ConvertWithYCoordinateAsLatitude(GeometryPosition position)
 {
     return new GeographyPosition(position.Y, position.X, position.Z, position.M);
 }
Ejemplo n.º 50
0
 public override void BeginFigure(GeometryPosition position)
 {
     this.both.OnBeginFigure(position);
 }
Ejemplo n.º 51
0
 /// <summary>Draws a point in the specified coordinate.</summary>
 /// <param name="position">The position of the line.</param>
 public abstract void LineTo(GeometryPosition position);
Ejemplo n.º 52
0
 public override void LineTo(GeometryPosition position)
 {
     this.both.OnLineTo(position);
 }
Ejemplo n.º 53
0
 protected override GeometryPosition OnLineTo(GeometryPosition position)
 {
     this.AddLineTo(position.X, position.Y, position.Z, position.M);
     return position;
 }
 /// <summary>
 /// Adds a geometric control point.
 /// </summary>
 /// <param name="position">The position of the control point.</param>
 public override void LineTo(GeometryPosition position)
 {
     this.Destination.LineTo(this.ConvertPosition(position));
 }
Ejemplo n.º 55
0
 protected override GeometryPosition OnBeginFigure(GeometryPosition position)
 {
     this.WriteFigureScope(position.X, position.Y, position.Z, position.M);
     return position;
 }
 /// <summary>
 /// Converts the position with the Y coordinate as latitude.
 /// </summary>
 /// <param name="position">The position to convert.</param>
 /// <returns>The converted position</returns>
 internal static GeographyPosition ConvertWithYCoordinateAsLatitude(GeometryPosition position)
 {
     return(new GeographyPosition(position.Y, position.X, position.Z, position.M));
 }
Ejemplo n.º 57
0
 /// <summary>
 /// Begin drawing a figure
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>The position to be passed down the pipeline</returns>
 protected override GeometryPosition OnBeginFigure(GeometryPosition position)
 {
     BeginFigure();
     this.WriteControlPoint(position.X, position.Y, position.Z, position.M);
     return(position);
 }
Ejemplo n.º 58
0
 /// <summary>
 /// Draw a point in the specified coordinate
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>
 /// The position to be passed down the pipeline
 /// </returns>
 protected override GeometryPosition OnLineTo(GeometryPosition position)
 {
     this.AddLineTo(position.X, position.Y, position.Z, position.M);
     return(position);
 }
Ejemplo n.º 59
0
 /// <summary>
 /// Begin drawing a figure
 /// </summary>
 /// <param name="position">Next position</param>
 /// <returns>The position to be passed down the pipeline</returns>
 protected override GeometryPosition OnBeginFigure(GeometryPosition position)
 {
     BeginFigure();
     this.WriteControlPoint(position.X, position.Y, position.Z, position.M);
     return position;
 }