/// <summary> /// Returns true if the object is visible on the view. /// </summary> /// <returns>true</returns> /// <c>false</c> /// <param name="view">View.</param> /// <param name="zoom"></param> public bool IsVisibleIn(View2D view, float zoom) { if (this.MinZoom > zoom || this.MaxZoom < zoom) { // outside of zoom bounds! return(false); } return(view.Contains(this.X, this.Y)); }
public void View2DTestCreateFromWithDirection() { double delta = 0.000001; // create a new view that is tilted. View2D view = View2D.CreateFrom(0, 0, System.Math.Sqrt(2), System.Math.Sqrt(2), 1, false, false, 45); Assert.AreEqual(-1, view.LeftBottom[0], delta); Assert.AreEqual(0, view.LeftBottom[1], delta); Assert.AreEqual(0, view.RightBottom[0], delta); Assert.AreEqual(-1, view.RightBottom[1], delta); Assert.AreEqual(0, view.LeftTop[0], delta); Assert.AreEqual(1, view.LeftTop[1], delta); Assert.AreEqual(1, view.RightTop[0], delta); Assert.AreEqual(0, view.RightTop[1], delta); Assert.IsTrue(view.Contains(0, 0)); double[] bottomLeft = view.FromViewPort(1000, 1000, 0, 0); Assert.AreEqual(bottomLeft[0], view.LeftBottom[0], delta); Assert.AreEqual(bottomLeft[1], view.LeftBottom[1], delta); double[] topRight = view.FromViewPort(1000, 1000, 1000, 1000); Assert.AreEqual(topRight[0], view.RightTop[0], delta); Assert.AreEqual(topRight[1], view.RightTop[1], delta); double[] topLeft = view.FromViewPort(1000, 1000, 0, 1000); Assert.AreEqual(topLeft[0], view.LeftTop[0], delta); Assert.AreEqual(topLeft[1], view.LeftTop[1], delta); double[] bottomRight = view.FromViewPort(1000, 1000, 1000, 0); Assert.AreEqual(bottomRight[0], view.RightBottom[0], delta); Assert.AreEqual(bottomRight[1], view.RightBottom[1], delta); double[] viewBottomLeft = view.ToViewPort(1000, 1000, view.LeftBottom[0], view.LeftBottom[1]); Assert.AreEqual(view.LeftBottom[0], view.FromViewPort(1000, 1000, viewBottomLeft[0], viewBottomLeft[1])[0], delta); Assert.AreEqual(view.LeftBottom[1], view.FromViewPort(1000, 1000, viewBottomLeft[0], viewBottomLeft[1])[1], delta); double[] viewBottomRight = view.ToViewPort(1000, 1000, view.RightBottom[0], view.RightBottom[1]); Assert.AreEqual(view.RightBottom[0], view.FromViewPort(1000, 1000, viewBottomRight[0], viewBottomRight[1])[0], delta); Assert.AreEqual(view.RightBottom[1], view.FromViewPort(1000, 1000, viewBottomRight[0], viewBottomRight[1])[1], delta); double[] viewTopLeft = view.ToViewPort(1000, 1000, view.LeftTop[0], view.LeftTop[1]); Assert.AreEqual(view.LeftTop[0], view.FromViewPort(1000, 1000, viewTopLeft[0], viewTopLeft[1])[0], delta); Assert.AreEqual(view.LeftTop[1], view.FromViewPort(1000, 1000, viewTopLeft[0], viewTopLeft[1])[1], delta); double[] viewTopRight = view.ToViewPort(1000, 1000, view.RightTop[0], view.RightTop[1]); Assert.AreEqual(view.RightTop[0], view.FromViewPort(1000, 1000, viewTopRight[0], viewTopRight[1])[0], delta); Assert.AreEqual(view.RightTop[1], view.FromViewPort(1000, 1000, viewTopRight[0], viewTopRight[1])[1], delta); }
/// <summary> /// Returns true if the object is visible in the given view. /// </summary> /// <param name="view"></param> /// <returns></returns> public override bool IsVisibleIn(View2D view) { return view.Contains(this.X, this.Y); }
/// <summary> /// Returns true if the object is visible on the view. /// </summary> /// <returns>true</returns> /// <c>false</c> /// <param name="view">View.</param> /// <param name="zoom"></param> public override bool IsVisibleIn(View2D view) { return(view.Contains(this.X, this.Y)); }
/// <summary> /// Returns true if the object is visible on the view. /// </summary> /// <returns>true</returns> /// <c>false</c> /// <param name="view">View.</param> /// <param name="zoom"></param> public override bool IsVisibleIn(View2D view, float zoom) { if (this.MinZoom > zoom || this.MaxZoom < zoom) { // outside of zoom bounds! return false; } return view.Contains(this.X, this.Y); }
/// <summary> /// Draws the line text segment. /// </summary> /// <param name="target">Target.</param> /// <param name="xTransformed">X transformed.</param> /// <param name="yTransformed">Y transformed.</param> /// <param name="text">Text.</param> /// <param name="color">Color.</param> /// <param name="size">Size.</param> /// <param name="haloColor">Halo color.</param> /// <param name="haloRadius">Halo radius.</param> /// <param name="middlePosition">Middle position.</param> /// <param name="characterWidths">Character widths.</param> /// <param name="textLength">Text length.</param> /// <param name="characterHeight">Character height.</param> public void DrawLineTextSegment(Target2DWrapper <global::Android.Graphics.Canvas> target, double[] xTransformed, double[] yTransformed, string text, int color, double size, int?haloColor, int?haloRadius, double middlePosition, float[] characterWidths, double textLength, float characterHeight) { _paint.Color = new global::Android.Graphics.Color(color); _paint.SetStyle(global::Android.Graphics.Paint.Style.Fill); // see if the text is 'upside down'. double averageAngle = 0; double first = middlePosition - (textLength / 2.0); PointF2D current = Polyline2D.PositionAtPosition(xTransformed, yTransformed, first); bool isVisible = false; for (int idx = 0; idx < text.Length; idx++) { double nextPosition = middlePosition - (textLength / 2.0) + ((textLength / (text.Length)) * (idx + 1)); PointF2D next = Polyline2D.PositionAtPosition(xTransformed, yTransformed, nextPosition); // calculate the angle. VectorF2D vector = next - current; VectorF2D horizontal = new VectorF2D(1, 0); double angleDegrees = ((Degree)horizontal.Angle(vector)).Value; averageAngle = averageAngle + angleDegrees; current = next; double[] untransformed = this.TransformReverse(next [0], next [1]); if (_view.Contains(untransformed [0], untransformed [1])) { isVisible = true; } } averageAngle = averageAngle / text.Length; if (!isVisible) { return; } // reverse if 'upside down'. double[] xText = xTransformed; double[] yText = yTransformed; // if (averageAngle > 90 && averageAngle < 180 + 90) // { // the average angle is > PI => means upside down. // for (int idx = 0; idx < (xTransformed.Length / 2) + 1; idx++) { // double other = xTransformed [xTransformed.Length - idx - 1]; // xTransformed [xTransformed.Length - idx - 1] = xTransformed [0]; // xTransformed [0] = other; // other = yTransformed [yTransformed.Length - idx - 1]; // yTransformed [yTransformed.Length - idx - 1] = yTransformed [0]; // yTransformed [0] = other; // } // } // calculate a central position along the line. first = middlePosition - (textLength / 2.0); current = Polyline2D.PositionAtPosition(xText, yText, first); double nextPosition2 = first; for (int idx = 0; idx < text.Length; idx++) { nextPosition2 = nextPosition2 + characterWidths[idx]; //double nextPosition = middle - (textLength / 2.0) + ((textLength / (text.Length)) * (idx + 1)); PointF2D next = Polyline2D.PositionAtPosition(xText, yText, nextPosition2); char currentChar = text[idx]; global::Android.Graphics.Path characterPath = new global::Android.Graphics.Path();; _paint.GetTextPath(text, idx, idx + 1, 0, 0, characterPath); using (characterPath) { // Transformation matrix to move the character to the correct location. // Note that all actions on the Matrix class are prepended, so we apply them in reverse. using (var transform = new Matrix()) { // Translate to the final position, the center of line-segment between 'current' and 'next' PointF2D position = current; //PointF2D position = current + ((next - current) / 2.0); //double[] transformed = this.Tranform(position[0], position[1]); transform.SetTranslate((float)position [0], (float)position [1]); // calculate the angle. VectorF2D vector = next - current; VectorF2D horizontal = new VectorF2D(1, 0); double angleDegrees = ((Degree)horizontal.Angle(vector)).Value; // Rotate the character transform.PreRotate((float)angleDegrees); // Translate the character so the centre of its base is over the origin transform.PreTranslate(0, characterHeight / 2.5f); //transform.Scale((float)this.FromPixels(_target, _view, 1), // (float)this.FromPixels(_target, _view, 1)); characterPath.Transform(transform); if (haloColor.HasValue && haloRadius.HasValue && haloRadius.Value > 0) { _paint.SetStyle(global::Android.Graphics.Paint.Style.FillAndStroke); _paint.StrokeWidth = haloRadius.Value; _paint.Color = new global::Android.Graphics.Color(haloColor.Value); using (global::Android.Graphics.Path haloPath = new global::Android.Graphics.Path()) { _paint.GetFillPath(characterPath, haloPath); // Draw the character target.Target.DrawPath(haloPath, _paint); } } // Draw the character _paint.SetStyle(global::Android.Graphics.Paint.Style.Fill); _paint.StrokeWidth = 0; _paint.Color = new global::Android.Graphics.Color(color); target.Target.DrawPath(characterPath, _paint); } } current = next; } }
public void View2DTestCreateFrom() { View2D view = View2D.CreateFrom(0, 0, 200, 200, 1, false, false); // test result. Assert.AreEqual(view.LeftTop[0], -100); Assert.AreEqual(view.RightTop[0], 100); Assert.AreEqual(view.RightBottom[1], -100); Assert.AreEqual(view.RightTop[1], 100); Assert.IsTrue(view.Contains(0, 0)); double[] topLeft = view.FromViewPort(1000, 1000, 0, 0); Assert.AreEqual(topLeft[0], -100); Assert.AreEqual(topLeft[1], -100); double[] bottomRight = view.FromViewPort(1000, 1000, 1000, 1000); Assert.AreEqual(bottomRight[0], 100); Assert.AreEqual(bottomRight[1], 100); double[] viewTopLeft = view.ToViewPort(1000, 1000, view.LeftTop[0], view.RightTop[1]); Assert.AreEqual(0, viewTopLeft[0]); Assert.AreEqual(1000, viewTopLeft[1]); double[] viewBottomRight = view.ToViewPort(1000, 1000, view.RightBottom[0], view.RightBottom[1]); Assert.AreEqual(1000, viewBottomRight[0]); Assert.AreEqual(0, viewBottomRight[1]); view = View2D.CreateFrom(0, 0, 200, 200, 1, true, false); // test result. Assert.AreEqual(view.LeftTop[0], 100); Assert.AreEqual(view.RightTop[0], -100); Assert.AreEqual(view.RightBottom[1], -100); Assert.AreEqual(view.RightTop[1], 100); Assert.IsTrue(view.Contains(0, 0)); topLeft = view.FromViewPort(1000, 1000, 0, 0); Assert.AreEqual(topLeft[0], 100); Assert.AreEqual(topLeft[1], -100); bottomRight = view.FromViewPort(1000, 1000, 1000, 1000); Assert.AreEqual(bottomRight[0], -100); Assert.AreEqual(bottomRight[1], 100); viewTopLeft = view.ToViewPort(1000, 1000, view.LeftTop[0], view.LeftTop[1]); Assert.AreEqual(0, viewTopLeft[0]); Assert.AreEqual(1000, viewTopLeft[1]); viewBottomRight = view.ToViewPort(1000, 1000, view.RightBottom[0], view.RightBottom[1]); Assert.AreEqual(1000, viewBottomRight[0]); Assert.AreEqual(0, viewBottomRight[1]); view = View2D.CreateFrom(0, 0, 200, 200, 1, false, true); // test result. Assert.AreEqual(view.LeftTop[0], -100); Assert.AreEqual(view.RightTop[0], 100); Assert.AreEqual(view.RightBottom[1], 100); Assert.AreEqual(view.RightTop[1], -100); Assert.IsTrue(view.Contains(0, 0)); topLeft = view.FromViewPort(1000, 1000, 0, 0); Assert.AreEqual(topLeft[0], -100); Assert.AreEqual(topLeft[1], 100); bottomRight = view.FromViewPort(1000, 1000, 1000, 1000); Assert.AreEqual(bottomRight[0], 100); Assert.AreEqual(bottomRight[1], -100); viewTopLeft = view.ToViewPort(1000, 1000, view.LeftTop[0], view.LeftTop[1]); Assert.AreEqual(0, viewTopLeft[0]); Assert.AreEqual(1000, viewTopLeft[1]); viewBottomRight = view.ToViewPort(1000, 1000, view.RightBottom[0], view.RightBottom[1]); Assert.AreEqual(1000, viewBottomRight[0]); Assert.AreEqual(0, viewBottomRight[1]); view = View2D.CreateFrom(0, 0, 200, 200, 1, true, true); // test result. Assert.AreEqual(view.LeftTop[0], 100); Assert.AreEqual(view.RightTop[0], -100); Assert.AreEqual(view.RightBottom[1], 100); Assert.AreEqual(view.RightTop[1], -100); Assert.IsTrue(view.Contains(0, 0)); topLeft = view.FromViewPort(1000, 1000, 0, 0); Assert.AreEqual(topLeft[0], 100); Assert.AreEqual(topLeft[1], 100); bottomRight = view.FromViewPort(1000, 1000, 1000, 1000); Assert.AreEqual(bottomRight[0], -100); Assert.AreEqual(bottomRight[1], -100); viewTopLeft = view.ToViewPort(1000, 1000, view.LeftTop[0], view.LeftTop[1]); Assert.AreEqual(0, viewTopLeft[0]); Assert.AreEqual(1000, viewTopLeft[1]); viewBottomRight = view.ToViewPort(1000, 1000, view.RightBottom[0], view.RightBottom[1]); Assert.AreEqual(1000, viewBottomRight[0]); Assert.AreEqual(0, viewBottomRight[1]); view = View2D.CreateFromBounds(100, -100, -100, 100); // test result. Assert.AreEqual(view.LeftTop[0], -100); Assert.AreEqual(view.RightTop[0], 100); Assert.AreEqual(view.RightBottom[1], -100); Assert.AreEqual(view.RightTop[1], 100); Assert.IsTrue(view.Contains(0, 0)); view = View2D.CreateFromBounds(-100, 100, 100, -100); // test result. Assert.AreEqual(view.LeftTop[0], 100); Assert.AreEqual(view.RightTop[0], -100); Assert.AreEqual(view.RightBottom[1], 100); Assert.AreEqual(view.RightTop[1], -100); Assert.IsTrue(view.Contains(0, 0)); }