本文整理匯總了C#中OsmSharp.Math.Primitives.PointF2D類的典型用法代碼示例。如果您正苦於以下問題:C# PointF2D類的具體用法?C# PointF2D怎麽用?C# PointF2D使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PointF2D類屬於OsmSharp.Math.Primitives命名空間,在下文中一共展示了PointF2D類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RectangleF2D
/// <summary>
/// Initializes a new instance of the <see cref="OsmSharp.Math.Primitives.RectangleF2D"/> class.
/// </summary>
/// <param name="x">The x coordinate of the bottom-left corner.</param>
/// <param name="y">The y coordinate of the bottom-left corner.</param>
/// <param name="width">Width.</param>
/// <param name="height">Height.</param>
/// <param name="angleY">The angle relative to the y-axis.</param>
public RectangleF2D(double x, double y, double width, double height, Degree angleY)
{
_bottomLeft = new PointF2D (x, y);
VectorF2D directionY = VectorF2D.FromAngleY (angleY);
_vectorY = directionY * height;
_vectorX = directionY.Rotate90 (true) * width;
}
示例2: PolygonF2D
/// <summary>
/// Creates a new polygon.
/// </summary>
/// <param name="points"></param>
public PolygonF2D(PointF2D[] points)
{
// make a copy.
_points = new List<PointF2D>(points).ToArray();
if (_points.Length <= 2)
{
throw new ArgumentOutOfRangeException("Minimum three points make a polygon!");
}
}
示例3: RotateAroundPoint
/// <summary>
/// Rotates a point around another around point with a given angle clockwise.
/// </summary>
/// <returns>The around point.</returns>
/// <param name="angle">Angle.</param>
/// <param name="center">Center.</param>
/// <param name="point">Point.</param>
public static PointF2D RotateAroundPoint(Radian angle, PointF2D center, PointF2D point)
{
double sin = System.Math.Sin (angle.Value);
double cos = System.Math.Cos (angle.Value);
double newX = center [0] + (cos * (point [0] - center[0]) + sin * (point [1] - center [1]));
double newY = center [1] + (-sin * (point [0] - center[0]) + cos * (point [1] - center [1]));
return new PointF2D (newX, newY);
}
示例4: RotationSimpleTest
public void RotationSimpleTest()
{
double delta = 0.00001;
PointF2D center = new PointF2D (1, 1);
PointF2D point = new PointF2D (1, 2);
PointF2D rotated = Rotation.RotateAroundPoint ((Degree)90, center, point);
Assert.AreEqual (2, rotated [0], delta);
Assert.AreEqual (1, rotated [1], delta);
rotated = Rotation.RotateAroundPoint ((Degree)180, center, point);
Assert.AreEqual (1, rotated [0], delta);
Assert.AreEqual (0, rotated [1], delta);
}
示例5: SimplifyBetween
/// <summary>
/// Simplify the specified points using epsilon.
/// </summary>
/// <param name="points">Points.</param>
/// <param name="epsilon">Epsilon.</param>
/// <param name="first">First.</param>
/// <param name="last">Last.</param>
public static PointF2D[] SimplifyBetween(PointF2D[] points, double epsilon, int first, int last)
{
if (points == null)
throw new ArgumentNullException ("points");
if (epsilon <= 0)
throw new ArgumentOutOfRangeException("epsilon");
if (first > last)
throw new ArgumentException(string.Format("first[{0}] must be smaller or equal than last[{1}]!",
first, last));
if (first + 1 != last) {
// find point with the maximum distance.
double maxDistance = 0;
int foundIndex = -1;
// create the line between first-last.
LineF2D line = new LineF2D (points[first], points [last]);
for (int idx = first + 1; idx < last; idx++) {
double distance = line.Distance (points[idx]);
if (distance > maxDistance) {
// larger distance found.
maxDistance = distance;
foundIndex = idx;
}
}
if (foundIndex > 0 && maxDistance > epsilon) { // a point was found and it is far enough.
PointF2D[] before = SimplifyCurve.SimplifyBetween (points, epsilon, first, foundIndex);
PointF2D[] after = SimplifyCurve.SimplifyBetween (points, epsilon, foundIndex, last);
// build result.
PointF2D[] result = new PointF2D[before.Length + after.Length - 1];
for (int idx = 0; idx < before.Length - 1; idx++) {
result [idx] = before [idx];
}
for (int idx = 0; idx < after.Length; idx++) {
result [idx + before.Length - 1] = after [idx];
}
return result;
}
}
return new PointF2D[] { points[first], points[last] };
}
示例6: Point2DTest
public void Point2DTest()
{
// create the test cases.
PointF2D a = new PointF2D(0, 0);
PointF2D b = new PointF2D(1, 1);
// calculate the results
double sqrt_2 = (double)System.Math.Sqrt(2);
//double sqrt_2_div_2 = (double)System.Math.Sqrt(2) / 2.0f;
// test distance.
Assert.AreEqual(a.Distance(b), sqrt_2, string.Format("Distance should be {0}!", sqrt_2));
// test substraction into vector.
VectorF2D ab = b - a;
Assert.AreEqual(ab[0], 1, "Vector should be 1 at index 0!");
Assert.AreEqual(ab[1], 1, "Vector should be 1 at index 1!");
VectorF2D ba = a - b;
Assert.AreEqual(ba[0], -1, "Vector should be -1 at index 0!");
Assert.AreEqual(ba[1], -1, "Vector should be -1 at index 1!");
}
示例7: ExpandWith
/// <summary>
/// Expands this geo coordinate box with the given coordinate.
/// </summary>
/// <param name="coordinate"></param>
public void ExpandWith(GeoCoordinate coordinate)
{
if (!this.Contains(coordinate))
{
PointF2D[] newCorners = new PointF2D[3];
newCorners[0] = this.TopLeft;
newCorners[1] = this.BottomRight;
newCorners[2] = coordinate;
this.Mutate(newCorners);
}
}
示例8: Simplify
/// <summary>
/// Simplify the specified points using epsilon.
/// </summary>
/// <param name="points">Points.</param>
/// <param name="epsilon">Epsilon.</param>
public static PointF2D[] Simplify(PointF2D[] points, double epsilon)
{
return SimplifyCurve.SimplifyBetween (points, epsilon, 0, points.Length - 1);
}
示例9: Serialize
/// <summary>
/// Serializes the given scene.
/// </summary>
/// <param name="stream"></param>
/// <param name="scene"></param>
/// <param name="compress"></param>
public static void Serialize(Stream stream, TagsCollectionBase metaTags, Scene2D scene, bool compress)
{
RuntimeTypeModel typeModel = SceneSerializer.BuildRuntimeTypeModel();
// [MetaIndexLenght:4][Metadata][SeneIndexLength:4][SceneIndex][SceneLengths:4*zoomFactors.length][Scenes]
// MetaIndexLenght: int The lenght of the meta index.
// Metadata: a number of serialized tags.
// SceneIndexLength: int The length of the sceneindex in bytes.
// SceneIndex: the serialized scene index.
// SceneLengths: int[] The lengths of the scenes per zoom level as in the zoomfactors array.
// Scenes: The serialized scenes themselves.
// serialize meta tags.
(new TagsCollectionSerializer()).SerializeWithSize(metaTags, stream);
// index index.
SceneIndex sceneIndex = new SceneIndex();
sceneIndex.LineStyles = scene.GetStyleLines();
sceneIndex.PointStyles = scene.GetStylePoints();
sceneIndex.PolygonStyles = scene.GetStylePolygons();
sceneIndex.TextStyles = scene.GetStyleTexts();
sceneIndex.ZoomRanges = scene.GetZoomRanges();
sceneIndex.ZoomFactors = scene.GetZoomFactors();
sceneIndex.IconImage = scene.GetImages();
// write SceneIndex
long positionAfterMeta = stream.Position;
stream.Seek(positionAfterMeta + 4, SeekOrigin.Begin);
long indexStart = stream.Position;
typeModel.Serialize(stream, sceneIndex);
// write SeneIndexLength
int indexSize = (int)(stream.Position - indexStart);
stream.Seek(positionAfterMeta + 0, SeekOrigin.Begin);
stream.Write(BitConverter.GetBytes(indexSize), 0, 4);
// write Scenes.
stream.Seek(positionAfterMeta + 4 + indexSize + 4 * sceneIndex.ZoomFactors.Length, SeekOrigin.Begin);
// index into r-trees and serialize.
int[] lengths = new int[sceneIndex.ZoomFactors.Length];
for (int idx = 0; idx < lengths.Length; idx++)
{
long position = stream.Position;
Dictionary<uint, SceneObject> sceneAtZoom = scene.GetObjectsAt(idx);
RTreeMemoryIndex<SceneObject> memoryIndex = new RTreeMemoryIndex<SceneObject>(50, 100);
float latestProgress = 0;
int sceneObjectIdx = 0;
foreach (KeyValuePair<uint, SceneObject> sceneObjectPair in sceneAtZoom)
{ // loop over all primitives in order.
SceneObject sceneObject = sceneObjectPair.Value;
uint id = sceneObjectPair.Key;
switch (sceneObject.Enum)
{
case SceneObjectType.IconObject:
case SceneObjectType.PointObject:
case SceneObjectType.TextObject:
OsmSharp.UI.Renderer.Scene.Scene2D.ScenePoint geo = scene.GetPoint(sceneObject.GeoId);
PointF2D point = new PointF2D(geo.X, geo.Y);
memoryIndex.Add(new BoxF2D(point), sceneObject);
break;
case SceneObjectType.LineObject:
case SceneObjectType.LineTextObject:
case SceneObjectType.PolygonObject:
OsmSharp.UI.Renderer.Scene.Scene2D.ScenePoints geos = scene.GetPoints(sceneObject.GeoId);
memoryIndex.Add(new BoxF2D(geos.X, geos.Y), sceneObject);
break;
}
float progress = (float)System.Math.Round((((double)sceneObjectIdx / (double)sceneAtZoom.Count) * 100));
if (progress != latestProgress)
{
OsmSharp.Logging.Log.TraceEvent("SceneSerializer", OsmSharp.Logging.TraceEventType.Information,
"Indexing scene objects at zoom {1} ({2}/{3})... {0}%", progress, sceneIndex.ZoomFactors[idx],
sceneObjectIdx, sceneAtZoom.Count);
latestProgress = progress;
}
sceneObjectIdx++;
}
// serialize the r-tree.
OsmSharp.Logging.Log.TraceEvent("SceneSerializer", OsmSharp.Logging.TraceEventType.Information,
"Serializing RTRee...");
SceneObjectRTreeSerializer memoryIndexSerializer = new SceneObjectRTreeSerializer(
scene, compress, idx, SceneSerializer.CalculateScaleFactor(sceneIndex.ZoomFactors[idx]));
memoryIndexSerializer.Serialize(new LimitedStream(stream), memoryIndex);
lengths[idx] = (int)(stream.Position - position);
}
// write SceneLengths
long end = stream.Position;
//.........這裏部分代碼省略.........
示例10: ZoomToMarkers
/// <summary>
/// Zooms to the given list of markers.
/// </summary>
/// <param name="markers"></param>
public void ZoomToMarkers(List<MapMarker> markers, double percentage, bool notifyChange)
{
float height = this.Height;
float width = this.Width;
if (width > 0) {
PointF2D[] points = new PointF2D[markers.Count];
for (int idx = 0; idx < markers.Count; idx++) {
points [idx] = new PointF2D (this.Map.Projection.ToPixel (markers [idx].Location));
}
View2D view = this.CreateView ();
View2D fittedView = view.Fit (points, percentage);
float zoom = (float)this.Map.Projection.ToZoomLevel (fittedView.CalculateZoom (
width, height));
GeoCoordinate center = this.Map.Projection.ToGeoCoordinates (
fittedView.Center [0], fittedView.Center [1]);
if (notifyChange) {
this.SetMapView (center, this.MapTilt, zoom, true);
this.NotifyMovement ();
this.Change ();
} else {
this.SetMapView (center, this.MapTilt, zoom, false);
}
} else {
_latestZoomCall = new MapViewMarkerZoomEvent()
{
Markers = markers,
Percentage = percentage
};
}
}
示例11: GeoCoordinate
/// <summary>
/// Creates a geo coordinate.
/// </summary>
public GeoCoordinate(PointF2D point)
: this(point[1], point[0])
{
}
示例12: Contains
/// <summary>
/// Returns true if this box contains the specified x, y.
/// </summary>
/// <param name="point">The point.</param>
public bool Contains(PointF2D point)
{
double[] coordinates = this.TransformTo (100, 100, false, false, point);
return (coordinates [0] >= 0 && coordinates [0] <= 100 &&
coordinates [1] >= 0 && coordinates [1] <= 100);
}
示例13: ZoomToMarkers
/// <summary>
/// Zoom to the given makers list.
/// </summary>
/// <param name="marker"></param>
public void ZoomToMarkers(List<MapMarker> markers, double percentage)
{
float width = (float)this.Frame.Width;
float height = (float)this.Frame.Height;
CGRect rect = this.Frame;
if (width > 0)
{
PointF2D[] points = new PointF2D[markers.Count];
for (int idx = 0; idx < markers.Count; idx++)
{
points[idx] = new PointF2D(this.Map.Projection.ToPixel(markers[idx].Location));
}
View2D view = this.CreateView(rect);
View2D fittedView = view.Fit(points, percentage);
float zoom = (float)this.Map.Projection.ToZoomLevel(fittedView.CalculateZoom(
width, height));
GeoCoordinate center = this.Map.Projection.ToGeoCoordinates(
fittedView.Center[0], fittedView.Center[1]);
this.MapCenter = center;
this.MapZoom = zoom;
this.NotifyMovementByInvoke();
}
}
示例14: Fit
/// <summary>
/// Fites this view around the given points but keeps aspect ratio and
/// </summary>
/// <param name="points"></param>
/// <returns></returns>
public View2D Fit(PointF2D[] points, double percentage)
{
RectangleF2D rotated = this.Rectangle.FitAndKeepAspectRatio(points, percentage);
return new View2D(rotated, _invertX, _invertY);
}
示例15: RotateAround
/// <summary>
/// Rotates this rectangle around the given center point with a given angle in clockwise direction.
/// </summary>
/// <returns>The around.</returns>
/// <param name="angle">Angle.</param>
/// <param name="center">Center.</param>
public RectangleF2D RotateAround(Degree angle, PointF2D center)
{
PointF2D[] corners = new PointF2D[] { this.TopLeft, this.TopRight, this.BottomLeft, this.BottomRight };
PointF2D[] cornersRotated = Rotation.RotateAroundPoint (angle, center, corners);
return new RectangleF2D (cornersRotated [2], this.Width, this.Height,
cornersRotated [0] - cornersRotated [2]);
}