static void Main(string[] args) { Point p1 = new Point(2, 3); Point p2 = p1; Console.WriteLine("p1: {0}", p1.ToString()); Console.WriteLine("Before: p1.Prop.SomeProperty = {0}", p1.Prop.SomeProperty); Console.WriteLine("p2: {0}", p2.ToString()); Console.WriteLine("Before: p2.Prop.SomeProperty = {0}\n", p2.Prop.SomeProperty); p2.Prop.SomeProperty = 69; p1.X = 200; p1.Y = 300; Console.WriteLine("p1: {0}", p1.ToString()); Console.WriteLine("After: p1.Prop.SomeProperty = {0}", p1.Prop.SomeProperty); Console.WriteLine("p2: {0}", p2.ToString()); Console.WriteLine("After: p2.Prop.SomeProperty = {0}", p2.Prop.SomeProperty); p1.SomeFunctionToImplement(); Console.ReadLine(); }
static void Main() { var point = new Point(2.3, 1, 0); var secPoint = new Point(1, 2, 5); var thirdPoint = new Point(3, 2, 2); Console.WriteLine(point.ToString()); Console.WriteLine(Point.O); Console.WriteLine(DistanceBnTwoPoints.CalcDistTwoPoints(point, Point.O)); var path = new Path(); path.AddPointsPath(point); path.AddPointsPath(Point.O); path.AddPointsPath(secPoint); path.AddPointsPath(thirdPoint); PathStorage.SavePath(path); var pathLoad = PathStorage.LoadPath(); foreach (var p in pathLoad.Points) { Console.WriteLine(p); } Console.WriteLine(new string('-', 59)); }
public void TestMercator_1SP_Projection() { CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); //System.Collections.ObjectModel.Collection<ProjectionParameter> parameters = new System.Collections.ObjectModel.Collection<ProjectionParameter>(5); System.Collections.ObjectModel.Collection<ProjectionParameter> parameters = new System.Collections.ObjectModel.Collection<ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", 110)); parameters.Add(new ProjectionParameter("scale_factor", 0.997)); parameters.Add(new ProjectionParameter("false_easting", 3900000)); parameters.Add(new ProjectionParameter("false_northing", 900000)); IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(120, -3); SharpMap.Geometries.Point pUtm = trans.MathTransform.Transform(pGeo); SharpMap.Geometries.Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); SharpMap.Geometries.Point expected = new Point(5009726.58, 569150.82); Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Mercator_1SP forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString())); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Mercator_1SP reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString())); }
public void TestAlbersProjection() { CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East), new AxisInfo("Lat", AxisOrientationEnum.North)); //System.Collections.ObjectModel.Collection<ProjectionParameter> parameters = new System.Collections.ObjectModel.Collection<ProjectionParameter>(5); System.Collections.ObjectModel.Collection<ProjectionParameter> parameters = new System.Collections.ObjectModel.Collection<ProjectionParameter>(); parameters.Add(new ProjectionParameter("central_meridian", -96)); parameters.Add(new ProjectionParameter("latitude_of_origin", 23)); parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5)); parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); SharpMap.Geometries.Point pGeo = new SharpMap.Geometries.Point(-75, 35); SharpMap.Geometries.Point pUtm = trans.MathTransform.Transform(pGeo); SharpMap.Geometries.Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); SharpMap.Geometries.Point expected = new Point(1885472.7, 1535925); Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.05), String.Format("Albers forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString())); Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Albers reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString())); }
public static void Run() { var p1 = new Point(10, 10); var p2 = new Point(20, 20); // p1 does NOT get boxed to call ToString (a virtual method) Console.WriteLine(p1.ToString()); // (10, 10) // p DOES get boxed to call GetType (a non-virtual method) Console.WriteLine(p1.GetType()); // Point // p1 does NOT get boxed to call CompareTo // p2 does NOT get boxed because CompareTo(Point) is called Console.WriteLine(p1.CompareTo(p2)); // -1 // p1 DOES get boxed, and the reference is placed in c IComparable c = p1; Console.WriteLine(c.GetType()); // Point // p1 does NOT get boxed to call ComapreTo // Since CompareTo is not being passed a Point variable, // CompareTo(Object) is called which requires a reference to // a boxed Point // c does NOT get boxed because it already refers to a boxed Point Console.WriteLine(p1.CompareTo(c)); // 0 // c does NOT get boxed because it is already refers ti a boxed Point. // p2 DOES get boxed because CompareTo(Object) is called Console.WriteLine(c.CompareTo(p2)); // -1 // c is unboxed, and fields are copied into p2 p2 = (Point)c; // Proves that the fields got copied into p2 Console.WriteLine(p2.ToString()); // (10, 10) }
public static Message BuildMoveMessage(this Tile tile, Point to) { return new Message{ Type = GameConstants.MOVEMENT, From = tile.Location.ToString(), To = to.ToString(), Name = tile.Name }; }
static void Main(string[] args) { Console.WriteLine("***** Fun with Generic Structures *****\n"); // Point using ints. Point<int> p = new Point<int>(10, 10); Console.WriteLine("p.ToString()={0}", p.ToString()); p.ResetPoint(); Console.WriteLine("p.ToString()={0}", p.ToString()); Console.WriteLine(); // Point using double. Point<double> p2 = new Point<double>(5.4, 3.3); Console.WriteLine("p2.ToString()={0}", p2.ToString()); p2.ResetPoint(); Console.WriteLine("p2.ToString()={0}", p2.ToString()); Console.ReadKey(); }
public void BoxingAndUnboxingExample() { Point p = new Point(1, 1); p.ToString().ShouldBe("1, 1"); p.Change(2, 2); p.ToString().ShouldBe("2, 2"); object o = p; o.ToString().ShouldBe("2, 2"); ((Point)o).Change(3, 3); o.ToString().ShouldBe("2, 2"); // Box p. Change the boxed object and discard it. ((IChangeBoxedPoint)p).Change(4, 4); p.ToString().ShouldBe("2, 2"); // Change the already boxed object on the heap. ((IChangeBoxedPoint)o).Change(5, 5); o.ToString().ShouldBe("5, 5"); }
public void ShouldSerializeToWkt(double x, double y, double? z, string expectedWkt) { var wgs84Mock=new Mock<ICoordinateSystem>(MockBehavior.Loose); var coords=new List<double>(new double[] { x, y }); if (z.HasValue) coords.Add(z.Value); var point=new Point() { pos=new pos(), CoordinateSystem=CommonServiceLocator.GetCoordinateSystemProvider().Wgs84 }; point.pos.Untyped.Value=string.Join( " ", coords.Select<double, string>(d => d.ToString(CultureInfo.InvariantCulture)) ); Assert.Equal<string>(expectedWkt, point.ToString()); }
public bool run(int n, int dimension, double c, Point X) { generator = new RandomPointGenerator(); planeProjector = new PlaneProjector(); pointProcessor = new PointProcessor(); Console.WriteLine("=================== NEW RUN ===================\n"); if (X == null) { X = generator.generatePoint(dimension); } Console.WriteLine("X= " + X.ToString() + "\n"); //Preparing background worker; prepareObjects(); Object[] arguments = { n, dimension, c, X }; bgWorker.RunWorkerAsync(arguments); return true; }
/// <summary> /// Calculates the value this animation believes should be the current value for the property. /// </summary> /// <param name="defaultOriginValue"> /// This value is the suggested origin value provided to the animation /// to be used if the animation does not have its own concept of a /// start value. If this animation is the first in a composition chain /// this value will be the snapshot value if one is available or the /// base property value if it is not; otherise this value will be the /// value returned by the previous animation in the chain with an /// animationClock that is not Stopped. /// </param> /// <param name="defaultDestinationValue"> /// This value is the suggested destination value provided to the animation /// to be used if the animation does not have its own concept of an /// end value. This value will be the base value if the animation is /// in the first composition layer of animations on a property; /// otherwise this value will be the output value from the previous /// composition layer of animations for the property. /// </param> /// <param name="animationClock"> /// This is the animationClock which can generate the CurrentTime or /// CurrentProgress value to be used by the animation to generate its /// output value. /// </param> /// <returns> /// The value this animation believes should be the current value for the property. /// </returns> protected override Point GetCurrentValueCore(Point defaultOriginValue, Point defaultDestinationValue, AnimationClock animationClock) { Debug.Assert(animationClock.CurrentState != ClockState.Stopped); if (!_isAnimationFunctionValid) { ValidateAnimationFunction(); } double progress = animationClock.CurrentProgress.Value; IEasingFunction easingFunction = EasingFunction; if (easingFunction != null) { progress = easingFunction.Ease(progress); } Point from = new Point(); Point to = new Point(); Point accumulated = new Point(); Point foundation = new Point(); // need to validate the default origin and destination values if // the animation uses them as the from, to, or foundation values bool validateOrigin = false; bool validateDestination = false; switch(_animationType) { case AnimationType.Automatic: from = defaultOriginValue; to = defaultDestinationValue; validateOrigin = true; validateDestination = true; break; case AnimationType.From: from = _keyValues[0]; to = defaultDestinationValue; validateDestination = true; break; case AnimationType.To: from = defaultOriginValue; to = _keyValues[0]; validateOrigin = true; break; case AnimationType.By: // According to the SMIL specification, a By animation is // always additive. But we don't force this so that a // user can re-use a By animation and have it replace the // animations that precede it in the list without having // to manually set the From value to the base value. to = _keyValues[0]; foundation = defaultOriginValue; validateOrigin = true; break; case AnimationType.FromTo: from = _keyValues[0]; to = _keyValues[1]; if (IsAdditive) { foundation = defaultOriginValue; validateOrigin = true; } break; case AnimationType.FromBy: from = _keyValues[0]; to = AnimatedTypeHelpers.AddPoint(_keyValues[0], _keyValues[1]); if (IsAdditive) { foundation = defaultOriginValue; validateOrigin = true; } break; default: Debug.Fail("Unknown animation type."); break; } if (validateOrigin && !AnimatedTypeHelpers.IsValidAnimationValuePoint(defaultOriginValue)) { throw new InvalidOperationException( SR.Get( SRID.Animation_Invalid_DefaultValue, this.GetType(), "origin", defaultOriginValue.ToString(CultureInfo.InvariantCulture))); } if (validateDestination && !AnimatedTypeHelpers.IsValidAnimationValuePoint(defaultDestinationValue)) { throw new InvalidOperationException( SR.Get( SRID.Animation_Invalid_DefaultValue, this.GetType(), "destination", defaultDestinationValue.ToString(CultureInfo.InvariantCulture))); } if (IsCumulative) { double currentRepeat = (double)(animationClock.CurrentIteration - 1); if (currentRepeat > 0.0) { Point accumulator = AnimatedTypeHelpers.SubtractPoint(to, from); accumulated = AnimatedTypeHelpers.ScalePoint(accumulator, currentRepeat); } } // return foundation + accumulated + from + ((to - from) * progress) return AnimatedTypeHelpers.AddPoint( foundation, AnimatedTypeHelpers.AddPoint( accumulated, AnimatedTypeHelpers.InterpolatePoint(from, to, progress))); }
public void TestLambertConicConformal2SP_Projection() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 20925832.16, 294.97470, LinearUnit.USSurveyFoot); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientation.East), new AxisInfo("Lat", AxisOrientation.North)); //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 27.833333333)); parameters.Add(new ProjectionParameter("central_meridian", -99)); parameters.Add(new ProjectionParameter("standard_parallel_1", 28.3833333333)); parameters.Add(new ProjectionParameter("standard_parallel_2", 30.2833333333)); parameters.Add(new ProjectionParameter("false_easting", 2000000)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("NAD27 / Texas South Central", gcs, projection, LinearUnit.USSurveyFoot, new AxisInfo("East", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); Point pGeo = new Point(-96, 28.5); Point pUtm = trans.MathTransform.Transform(pGeo); Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); Point expected = new Point(2963503.91, 254759.80); Assert.IsTrue(toleranceLessThan(pUtm, expected, 0.02), String.Format( "LambertConicConformal2SP forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString())); Assert.IsTrue(toleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format( "LambertConicConformal2SP reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString())); }
public void TestTransverseMercator_Projection() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Airy 1830", 6377563.396, 299.32496, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Airy 1830", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Airy 1830", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientation.East), new AxisInfo("Lat", AxisOrientation.North)); //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 49)); parameters.Add(new ProjectionParameter("central_meridian", -2)); parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717)); parameters.Add(new ProjectionParameter("false_easting", 400000)); parameters.Add(new ProjectionParameter("false_northing", -100000)); IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("OSGB 1936 / British National Grid", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); Point pGeo = new Point(0.5, 50.5); Point pUtm = trans.MathTransform.Transform(pGeo); Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); Point expected = new Point(577274.99, 69740.50); Assert.IsTrue(toleranceLessThan(pUtm, expected, 0.02), String.Format( "TransverseMercator forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString())); Assert.IsTrue(toleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format( "TransverseMercator reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString())); }
public void TestMercator_2SP_Projection() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre); IHorizontalDatum datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null); IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees, datum, PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientation.East), new AxisInfo("Lat", AxisOrientation.North)); //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5); Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(); parameters.Add(new ProjectionParameter("latitude_of_origin", 42)); parameters.Add(new ProjectionParameter("central_meridian", 51)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientation.East), new AxisInfo("North", AxisOrientation.North)); ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys); Point pGeo = new Point(53, 53); Point pUtm = trans.MathTransform.Transform(pGeo); Point pGeo2 = trans.MathTransform.Inverse().Transform(pUtm); Point expected = new Point(165704.29, 5171848.07); Assert.IsTrue(toleranceLessThan(pUtm, expected, 0.02), String.Format("Mercator_2SP forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString())); Assert.IsTrue(toleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Mercator_2SP reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString())); }
public Point Transform(ProjFourWrapper destinationProj, Point point) { double[] x = new double[] { point.X }; double[] y = new double[] { point.Y }; if (this.IsLatLong) { x[0] = x[0] * DegreesToRadians; y[0] = y[0] * DegreesToRadians; } int errno = pj_transform(this.projPJ, destinationProj.projPJ, 1, 0, x, y, new double[] {0}) ; if (errno != 0) { throw new ProjFourException(errno, GetError() + " " + point.ToString()); } if (destinationProj.IsLatLong) { x[0] = x[0] / DegreesToRadians; y[0] = y[0] / DegreesToRadians; } Point p = new Point(x[0], y[0]); p.LabelFieldValue = point.LabelFieldValue; p.ThemeFieldValue = point.ThemeFieldValue; return p; }
public void TestToString() { var point = new Point { X = 3, Y = 1 }; Assert.That(point.ToString(), Is.EqualTo("3,1")); }