Beispiel #1
0
 /// <summary>
 /// Initialize new instance of <see cref="ArcSelection"/> class.
 /// </summary>
 /// <param name="layer">The selection shapes layer.</param>
 /// <param name="shape">The selected shape.</param>
 /// <param name="style">The selection shapes style.</param>
 /// <param name="point">The selection point shape.</param>
 public ArcSelection(XLayer layer, IArc shape, ShapeStyle style, BaseShape point)
 {
     _layer = layer;
     _arc   = shape;
     _style = style;
     _point = point;
 }
Beispiel #2
0
        private void Render(Canvas canvas, IArc arc)
        {
            double x      = Math.Min(arc.Point1.X, arc.Point2.X);
            double y      = Math.Min(arc.Point1.Y, arc.Point2.Y);
            double width  = Math.Abs(arc.Point2.X - arc.Point1.X);
            double height = Math.Abs(arc.Point2.Y - arc.Point1.Y);

            if (width > 0.0 && height > 0.0)
            {
                var paint = new Paint()
                {
                    Color       = ToNativeColor(arc.Stroke),
                    StrokeWidth = (float)arc.StrokeThickness,
                    AntiAlias   = true,
                    StrokeCap   = Paint.Cap.Butt
                };
                paint.SetStyle(Paint.Style.Stroke);

                canvas.DrawArc(
                    new RectF(
                        (float)x,
                        (float)y,
                        (float)(x + width),
                        (float)(y + height)),
                    (float)arc.StartAngle,
                    (float)arc.SweepAngle,
                    false,
                    paint);

                paint.Dispose();
            }
        }
Beispiel #3
0
        public void CreateGraph(IArc arc)
        {
            //form
            Form form = new Form();
            //view
            GViewer viewer = new GViewer();
            //graph
            Graph graph = new Graph("graph");

            graph.Attr.LayerDirection = LayerDirection.LR;

            foreach (ILine line in arc.Lines)
            {
                graph.AddEdge(line.Start.Id.ToString(), line.Time.ToString(), line.End.Id.ToString());
            }

            viewer.Graph = graph;

            form.SuspendLayout();
            viewer.Dock = DockStyle.Fill;
            form.Controls.Add(viewer);
            form.ResumeLayout();

            Thread thread = new Thread(() => form.ShowDialog());

            thread.Start();
        }
Beispiel #4
0
    public virtual void AddArc(IArc arc)
    {
        if (arc == null)
        {
            throw new ArgumentNullException();
        }
        if (_arcs == null || _adjacencyList == null)
        {
            throw new NullReferenceException();
        }

        foreach (IArc element in _arcs)
        {
            if (element.Equals(arc))
            {
                return;
            }
        }
        IArc  newArc = arc.Clone();
        INode begin  = newArc.Begin;
        INode end    = newArc.End;

        AddNode(begin);
        AddNode(end);

        _arcs.Add(newArc);
        _adjacencyList[end].Add(newArc);
        _adjacencyList[begin].Add(newArc);
    }
        public static Vector3 LeftIntersection(this IArc arc, Sweepline sweepline)
        {
            var p = arc.LeftNeighbour.Position;
            var q = arc.Site.Position;
            var Z = sweepline.Z;

            if (Vector.AlmostEqual(p, q))
            {
                return(AngleUtilities.EquatorialDirection(p));
            }
            if (Number.AlmostEqual(Z, p.Z) && Number.AlmostEqual(Z, q.Z))
            {
                return(AngleUtilities.EquatorialMidpoint(p, q));
            }

            var A = p.X * (Z - q.Z) - q.X * (Z - p.Z);
            var B = p.Y * (Z - q.Z) - q.Y * (Z - p.Z);
            var C = (p.Z - q.Z) * Math.Sign(sweepline.Priority) * Math.Sqrt(1 - Z * Z);

            var A2PlusB2MinusC2 = Math.Max(A * A + B * B - C * C, 0);
            var x = (A * C + B * Math.Sqrt(A2PlusB2MinusC2)) / (A * A + B * B);
            var y = (B * C - A * Math.Sqrt(A2PlusB2MinusC2)) / (A * A + B * B);

            return(new Vector3(x, y, 0));
        }
Beispiel #6
0
        public WpfArc(IArc arc)
        {
            _xarc = arc;

            _fillBrush = new SolidColorBrush(_xarc.Fill.ToNativeColor());
            _fillBrush.Freeze();
            _strokeBrush = new SolidColorBrush(_xarc.Stroke.ToNativeColor());
            _strokeBrush.Freeze();

            _path = new Path();
            _path.Tag = this;
            _path.Fill = _fillBrush;
            _path.Stroke = _strokeBrush;
            _path.StrokeThickness = arc.StrokeThickness;
            _pg = new PathGeometry();
            _pf = new PathFigure();
            _pf.IsFilled = arc.IsFilled;
            _pf.IsClosed = arc.IsClosed;
            _start = new Point();
            _as = new ArcSegment();
            SetArcSegment(_as, arc, out _start);
            _pf.StartPoint = _start;
            _pf.Segments.Add(_as);
            _pg.Figures.Add(_pf);
            _path.Data = _pg;

            Native = _path;
        }
Beispiel #7
0
 private static IEnumerable <Vector3> ArcVertices(IArc arc, IArc nextArc, Sweepline sweepline)
 {
     if (arc.LeftNeighbour == arc.Site)
     {
         var azimuths = DrawingUtilities.AnglesInRange(0, 2 * Mathf.PI, NumberOfVerticesPerArc);
         var vertices = azimuths.Select(azimuth => PointOnEllipse(arc, azimuth, sweepline)).ToList();
         return(vertices);
     }
     else if (Mathf.Approximately((float)arc.Site.Priority, (float)sweepline.Priority))
     {
         var intersection = arc.PointOfIntersection(sweepline).ToUnityVector3();
         var site         = arc.Site.Position.ToUnityVector3();
         var downArc      = DrawingUtilities.VerticesOnGeodesic(intersection, site, NumberOfVerticesPerArc);
         var upArc        = DrawingUtilities.VerticesOnGeodesic(site, intersection, NumberOfVerticesPerArc);
         var vertices     = downArc.Concat(upArc);
         return(vertices);
     }
     else
     {
         var leftLimit  = DrawingUtilities.AzimuthOf(arc.LeftIntersection(sweepline).ToUnityVector3());
         var rightLimit = DrawingUtilities.AzimuthOf(nextArc.LeftIntersection(sweepline).ToUnityVector3());
         var azimuths   = DrawingUtilities.AnglesInRange(leftLimit, rightLimit, NumberOfVerticesPerArc);
         var vertices   = azimuths.Select(azimuth => PointOnEllipse(arc, azimuth, sweepline)).ToList();
         return(vertices);
     }
 }
Beispiel #8
0
        public WpfArc(IArc arc)
        {
            _xarc = arc;

            _fillBrush = new SolidColorBrush(_xarc.Fill.ToNativeColor());
            _fillBrush.Freeze();
            _strokeBrush = new SolidColorBrush(_xarc.Stroke.ToNativeColor());
            _strokeBrush.Freeze();

            _path                 = new Path();
            _path.Tag             = this;
            _path.Fill            = _fillBrush;
            _path.Stroke          = _strokeBrush;
            _path.StrokeThickness = arc.StrokeThickness;
            _pg          = new PathGeometry();
            _pf          = new PathFigure();
            _pf.IsFilled = arc.IsFilled;
            _pf.IsClosed = arc.IsClosed;
            _start       = new Point();
            _as          = new ArcSegment();
            SetArcSegment(_as, arc, out _start);
            _pf.StartPoint = _start;
            _pf.Segments.Add(_as);
            _pg.Figures.Add(_pf);
            _path.Data = _pg;

            Native = _path;
        }
Beispiel #9
0
 /// <summary>
 /// Initialize new instance of <see cref="ArcSelection"/> class.
 /// </summary>
 /// <param name="layer">The selection shapes layer.</param>
 /// <param name="shape">The selected shape.</param>
 /// <param name="style">The selection shapes style.</param>
 /// <param name="point">The selection point shape.</param>
 public ArcSelection(XLayer layer, IArc shape, ShapeStyle style, BaseShape point)
 {
     _layer = layer;
     _arc = shape;
     _style = style;
     _point = point;
 }
Beispiel #10
0
        public void AddArc(IArc arc)
        {
            if (this != arc.Source && this != arc.Target)
            {
                throw new ArgumentException("The current vertex must be either the arc source or the arc target.");
            }

            if (arc.Source == arc.Target)
            {
                throw new ArgumentException("Arc source and target must be different.");
            }

            if (this == arc.Source)
            {
                if (outArcs.Contains(arc))
                {
                    throw new InvalidOperationException("Arc already added.");
                }
                outArcs.Add(arc);
            }
            if (this == arc.Target)
            {
                if (inArcs.Contains(arc))
                {
                    throw new InvalidOperationException("Arc already added.");
                }
                inArcs.Add(arc);
            }
            OnArcAdded(this, new EventArgs <IArc>(arc));
        }
Beispiel #11
0
 /// <summary>
 /// Initialize new instance of <see cref="ToolArcSelection"/> class.
 /// </summary>
 /// <param name="layer">The selection shapes layer.</param>
 /// <param name="shape">The selected shape.</param>
 /// <param name="style">The selection shapes style.</param>
 /// <param name="point">The selection point shape.</param>
 public ToolArcSelection(LayerContainer layer, IArc shape, ShapeStyle style, BaseShape point)
 {
     _layer = layer;
     _arc   = shape;
     _style = style;
     _point = point;
 }
Beispiel #12
0
 private void TryRemoveEventCorrespondingTo(IArc arc)
 {
     if (_queueHandles.ContainsKey(arc))
     {
         _queue.Delete(_queueHandles[arc]);
         _queueHandles.Remove(arc);
     }
 }
        public CircleEvent(IArc leftArc, IArc middleArc, IArc rightArc)
        {
            LeftArc   = leftArc;
            MiddleArc = middleArc;
            RightArc  = rightArc;

            Priority = CalculatePriority();
        }
        public virtual void RemoveArc(IArc arc)
        {
            arcs.Remove(arc);
            var source = (Vertex)arc.Source;
            var target = (Vertex)arc.Target;

            source.RemoveArc(arc);
            target.RemoveArc(arc);
        }
Beispiel #15
0
 public void AddArc(IArc arc1, IArc arc2)
 {
     if (arc1 == null || arc2 == null)
     {
         throw new ArgumentNullException();
     }
     AddArc(arc1);
     AddArc(arc2);
 }
Beispiel #16
0
        private void FixPosition(IArc arc, CircleEvent circle)
        {
            var vertex = _vertexLists[arc].Last();

            vertex.Position = circle.Center();
            vertex.Sites    = new List <SiteEvent> {
                circle.LeftArc.Site, circle.MiddleArc.Site, circle.RightArc.Site
            };
        }
        public bool AreInOrder(IArc a, IArc b, IArc c)
        {
            var aLeft = a.LeftIntersection(_sweepline);
            var bLeft = b.LeftIntersection(_sweepline);
            var cLeft = c.LeftIntersection(_sweepline);

            var areInOrder = (cLeft - bLeft).CrossMultiply(aLeft - bLeft)[2] >= 0;

            return(areInOrder);
        }
Beispiel #18
0
        public static void Convert(IArc oldArc, IArc newArc)
        {
            var drawing = oldArc.Drawing;

            newArc.Style     = oldArc.Style;
            newArc.Clockwise = oldArc.Clockwise;
            Actions.ReplaceWithNew(oldArc, newArc);
            drawing.RaiseUserIsAddingFigures(new Drawing.UIAFEventArgs()
            {
                Figures = newArc.AsEnumerable <IFigure>()
            });
        }
Beispiel #19
0
 /// <summary>
 /// Group of methods and operator overloads that add some (0-...) arcs to the graph,
 /// AddArc(IArc arc) only is basic method
 /// </summary>
 /// <param name="arc"></param>
 public virtual void AddArc(IArc arc)
 {
     if (arc == null)
     {
         throw new ArgumentNullException();
     }
     if (_insideGraph == null)
     {
         throw new NullReferenceException();
     }
     _insideGraph.AddArc(arc.Clone());
 }
Beispiel #20
0
 /// <summary>
 /// Method and operator overload that remove arc from the graph
 /// </summary>
 /// <param name="arc"></param>
 public virtual void RemoveArc(IArc arc)
 {
     if (arc == null)
     {
         throw new ArgumentNullException();
     }
     if (_insideGraph == null)
     {
         throw new NullReferenceException();
     }
     _insideGraph.RemoveArc(arc);
 }
Beispiel #21
0
 /// <summary>
 /// 鼠标移动正切?如果m_tanSnap.Owner is IArc,则设置端点P1为圆上的切点,p2为传入的值,如果p1为空,则设置p1p2均为圆弧的中点
 /// </summary>
 /// <param name="canvas"></param>
 /// <param name="point"></param>
 protected virtual void MouseMoveTangent(ICanvas canvas, UnitPoint point)
 {
     if (m_tanSnap.Owner is IArc)
     {
         IArc src = m_tanSnap.Owner as IArc;
         m_p1 = HitUtil.TangentPointOnCircle(src.Center, src.Radius, point, m_tanReverse);
         m_p2 = point;
         if (m_p1 == UnitPoint.Empty)
         {
             m_p2 = m_p1 = src.Center;
         }
     }
 }
Beispiel #22
0
    public override void AddArc(IArc arc)
    {
        if (arc == null)
        {
            throw new ArgumentNullException();
        }
        if (_arcs == null || _adjacencyList == null)
        {
            throw new NullReferenceException();
        }

        foreach (IArc element in _arcs)
        {
            if (element.Equals(arc))
            {
                return;
            }
        }
        IArc newArc = arc.Clone();

        _arcs.Add(newArc);
        INode begin = newArc.Begin;
        INode end   = newArc.End;

        base.AddNode(begin);
        base.AddNode(end);
        _adjacencyList[end].Add(newArc);
        _adjacencyList[begin].Add(newArc);
        if (!_components.ContainsKey(begin))
        {
            if (!_components.ContainsKey(end))
            {
                _components[end] = _components[begin] = ++_maxComponent;
            }
            else
            {
                _components[begin] = _components[end];
            }
        }
        else
        {
            if (!_components.ContainsKey(end))
            {
                _components[end] = _components[begin];
            }
            else
            {
                BFS(begin, Math.Min(_components[begin], _components[end]));
            }
        }
    }
Beispiel #23
0
 private void Write(IArc arc)
 {
     Write(NativeType.Arc);
     _writer.Write(arc.Id);
     Write(arc.Point1);
     Write(arc.Point2);
     _writer.Write(arc.StartAngle);
     _writer.Write(arc.SweepAngle);
     Write(arc.Stroke);
     _writer.Write(arc.StrokeThickness);
     Write(arc.Fill);
     _writer.Write(arc.IsFilled);
     _writer.Write(arc.IsClosed);
 }
Beispiel #24
0
    /// <summary>
    /// check if is such arc
    /// </summary>
    /// <param name="arc"></param>
    /// <returns></returns>
    public bool IsArc(IArc arc)
    {
        if (_insideGraph == null)
        {
            throw new NullReferenceException();
        }
        INode node;

        if (_insideGraph.TryGetNode(arc.Begin.ID, out node) && _insideGraph.TryGetNode(arc.End.ID, out node))
        {
            return(true);
        }
        return(false);
    }
Beispiel #25
0
            /// <summary>
            /// Adds the given element to the collection
            /// </summary>
            /// <param name="item">The item to add</param>
            public override void Add(IModelElement item)
            {
                IElement elementsCasted = item.As <IElement>();

                if ((elementsCasted != null))
                {
                    this._parent.Elements.Add(elementsCasted);
                }
                IArc arcsCasted = item.As <IArc>();

                if ((arcsCasted != null))
                {
                    this._parent.Arcs.Add(arcsCasted);
                }
            }
Beispiel #26
0
 /// <summary>
 /// 鼠标垂直移动?如果是perSnap.Owner线则设置p1为点到直线最近距离直线上的点,p2为传入的点,如果是IArc则设置p1为到圆最近距离的点,p2为传入的点
 /// </summary>
 /// <param name="canvas"></param>
 /// <param name="point"></param>
 protected virtual void MouseMovePerpendicular(ICanvas canvas, UnitPoint point)
 {
     if (m_perSnap.Owner is Line)
     {
         Line src = m_perSnap.Owner as Line;
         m_p1 = HitUtil.NearestPointOnLine(src.P1, src.P2, point, true);
         m_p2 = point;
     }
     if (m_perSnap.Owner is IArc)
     {
         IArc src = m_perSnap.Owner as IArc;
         m_p1 = HitUtil.NearestPointOnCircle(src.Center, src.Radius, point, 0);
         m_p2 = point;
     }
 }
Beispiel #27
0
    public void AddArc(IArc arc1, IArc arc2, IArc arc3, IArc arc4, __arglist)
    {
        ArgIterator argIterator = new ArgIterator(__arglist);
        int         num         = argIterator.GetRemainingCount() + 4;

        IArc[] array = new IArc[num];
        array[0] = arc1;
        array[1] = arc2;
        array[2] = arc3;
        array[3] = arc4;
        for (int i = 4; i < num; i++)
        {
            array[i] = (IArc)TypedReference.ToObject(argIterator.GetNextArg());
        }
    }
Beispiel #28
0
    public virtual void RemoveArc(IArc arc)
    {
        if (arc == null)
        {
            throw new ArgumentNullException();
        }
        if (_arcs == null || _adjacencyList == null)
        {
            throw new NullReferenceException();
        }

        _arcs.Remove(arc);
        _adjacencyList[arc.Begin].Remove(arc);
        _adjacencyList[arc.End].Remove(arc);
    }
 public IArc Convert(IArc arc)
 {
     return(new XArc()
     {
         Point1 = Convert(arc.Point1),
         Point2 = Convert(arc.Point2),
         StartAngle = arc.StartAngle,
         SweepAngle = arc.SweepAngle,
         Stroke = Convert(arc.Stroke),
         StrokeThickness = arc.StrokeThickness,
         Fill = Convert(arc.Fill),
         IsFilled = arc.IsFilled,
         IsClosed = arc.IsClosed
     });
 }
Beispiel #30
0
        public void Arc_Translate_returnVal()
        {
            Arc arc = new Arc();

            arc.Radius = 1;
            arc.Center = new Vector3(1, 1, 1);

            arc.StartAngleRad = 0;
            arc.EndAngleRad   = Math.PI / 2;

            IArc arcTrans = arc.Translate(new Vector3(1, 1, 2));

            Assert.AreEqual(2d, arcTrans.Center.X, "centx");
            Assert.AreEqual(2d, arcTrans.Center.Y, "centy");
            Assert.AreEqual(3d, arcTrans.Center.Z, "centz");
        }
Beispiel #31
0
        public ArcBounds(
            INativeConverter nativeConverter,
            ICanvasFactory canvasFactory,
            ICanvas canvas,
            IArc arc,
            double size,
            double offset)
        {
            _arc = arc;
            _size = size;
            _offset = offset;
            _canvas = canvas;

            _hitResult = HitResult.None;

            InitBounds(nativeConverter, canvasFactory);
        }
Beispiel #32
0
            /// <summary>
            /// Removes the given item from the collection
            /// </summary>
            /// <returns>True, if the item was removed, otherwise False</returns>
            /// <param name="item">The item that should be removed</param>
            public override bool Remove(IModelElement item)
            {
                IElement elementItem = item.As <IElement>();

                if (((elementItem != null) &&
                     this._parent.Elements.Remove(elementItem)))
                {
                    return(true);
                }
                IArc arcItem = item.As <IArc>();

                if (((arcItem != null) &&
                     this._parent.Arcs.Remove(arcItem)))
                {
                    return(true);
                }
                return(false);
            }
Beispiel #33
0
        public void ShowOrganizedGraph(IArc arc)
        {
            //form
            Form form = new Form();
            //view
            GViewer viewer = new GViewer();
            //graph
            Graph graph = new Graph("graph");


            graph.Attr.LayerDirection = LayerDirection.LR;
            StringBuilder sb  = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();

            sb.Append("Porządek: ");

            foreach (ILine line in arc.Lines)
            {
                sb.Clear();
                sb2.Clear();

                sb.Append("Porządek: ");
                sb.Append(line.Start.Order.ToString());
                sb.Append("\n ID: ");
                sb.Append(line.Start.Id.ToString());

                sb2.Append("Porządek: ");
                sb2.Append(line.End.Order.ToString());
                sb2.Append("\n ID: ");
                sb2.Append(line.End.Id.ToString());
                graph.AddEdge(sb.ToString(), sb2.ToString()).LabelText = line.Time.ToString();
            }

            viewer.Graph = graph;

            form.SuspendLayout();
            viewer.Dock = DockStyle.Fill;
            form.Controls.Add(viewer);
            form.ResumeLayout();

            Thread thread = new Thread(() => form.ShowDialog());

            thread.Start();
        }
Beispiel #34
0
 /// <summary>
 /// Adds the specified arc to this Node.
 /// </summary>
 /// <param name="addedArc">The arc to be added to this Node.</param>
 public void AddArc(IArc addedArc)
 {
     if (addedArc != null)
     {
         foreach (IArc arc in Arcs)
         {
             if (arc.Equals(addedArc)) { return; }
         }
         Arcs.Add(addedArc);
     }
     else
         throw new ArgumentNullException("addedArc");
 }
Beispiel #35
0
    public virtual void AddArc(IArc arc) {
      var source = arc.Source;
      var target = arc.Target;

      if (source == target)
        throw new InvalidOperationException("Source and target cannot be the same.");

      if (!vertices.Contains(source) || !vertices.Contains(target))
        throw new InvalidOperationException("Cannot add arc connecting vertices that are not in the graph.");

      source.AddArc(arc);
      target.AddArc(arc);
      arcs.Add(arc);
    }
Beispiel #36
0
 public static void Convert(IArc oldArc, IArc newArc)
 {
     var drawing = oldArc.Drawing;
     newArc.Style = oldArc.Style;
     newArc.Clockwise = oldArc.Clockwise;
     Actions.ReplaceWithNew(oldArc, newArc);
     drawing.RaiseUserIsAddingFigures(new Drawing.UIAFEventArgs() { Figures = newArc.AsEnumerable<IFigure>() });
 }
Beispiel #37
0
 public virtual void RemoveArc(IArc arc) {
   arcs.Remove(arc);
   var source = (Vertex)arc.Source;
   var target = (Vertex)arc.Target;
   source.RemoveArc(arc);
   target.RemoveArc(arc);
 }
Beispiel #38
0
 /// <summary>
 /// Removes the specified arc from this Node.
 /// </summary>
 /// <param name="deletedArc">The arc to be removed from this Node.</param>
 public void RemoveArc(IArc deletedArc)
 {
     Arcs.Remove(deletedArc);
 }
Beispiel #39
0
        private void SetArcSegment(
            ArcSegment segment,
            IArc arc,
            out Point startPoint)
        {
            // original code https://pdfsharp.codeplex.com/
            // PDFsharp/code/PdfSharp/PdfSharp.Internal/Calc.cs
            // PDFsharp/code/PdfSharp/PdfSharp.Drawing/GeometryHelper.cs

            double x = Math.Min(arc.Point1.X, arc.Point2.X);
            double y = Math.Min(arc.Point1.Y, arc.Point2.Y);
            double width = Math.Abs(arc.Point2.X - arc.Point1.X);
            double height = Math.Abs(arc.Point2.Y - arc.Point1.Y);
            double startAngle = arc.StartAngle;
            double sweepAngle = arc.SweepAngle;

            // normalize the angles
            double α = startAngle;
            if (α < 0)
            {
                α = α + (1 + Math.Floor((Math.Abs(α) / 360))) * 360;
            }
            else if (α > 360)
            {
                α = α - Math.Floor(α / 360) * 360;
            }

            Debug.Assert(α >= 0 && α <= 360);

            if (Math.Abs(sweepAngle) >= 360)
            {
                sweepAngle = Math.Sign(sweepAngle) * 360;
            }

            double β = startAngle + sweepAngle;
            if (β < 0)
            {
                β = β + (1 + Math.Floor((Math.Abs(β) / 360))) * 360;
            }
            else if (β > 360)
            {
                β = β - Math.Floor(β / 360) * 360;
            }

            if (α == 0 && β < 0)
            {
                α = 360;
            }
            else if (α == 360 && β > 0)
            {
                α = 0;
            }

            // scanling factor
            double δx = width / 2;
            double δy = height / 2;
            // center of ellipse
            double x0 = x + δx;
            double y0 = y + δy;
            double cosα, cosβ, sinα, sinβ;

            if (width == height)
            {
                // circular arc needs no correction
                α = α * Deg2Rad;
                β = β * Deg2Rad;
            }
            else
            {
                // elliptic arc needs the angles to be adjusted
                // such that the scaling transformation is compensated
                α = α * Deg2Rad;
                sinα = Math.Sin(α);
                if (Math.Abs(sinα) > 1E-10)
                {
                    if (α < Math.PI)
                    {
                        α = Math.PI / 2 - Math.Atan(δy * Math.Cos(α) / (δx * sinα));
                    }
                    else
                    {
                        α = 3 * Math.PI / 2 - Math.Atan(δy * Math.Cos(α) / (δx * sinα));
                    }
                }
                // α = πHalf - Math.Atan(δy * Math.Cos(α) / (δx * sinα));
                β = β * Deg2Rad;
                sinβ = Math.Sin(β);
                if (Math.Abs(sinβ) > 1E-10)
                {
                    if (β < Math.PI)
                    {
                        β = Math.PI / 2 - Math.Atan(δy * Math.Cos(β) / (δx * sinβ));
                    }
                    else
                    {
                        β = 3 * Math.PI / 2 - Math.Atan(δy * Math.Cos(β) / (δx * sinβ));
                    }
                }
                // β = πHalf - Math.Atan(δy * Math.Cos(β) / (δx * sinβ));
            }

            sinα = Math.Sin(α);
            cosα = Math.Cos(α);
            sinβ = Math.Sin(β);
            cosβ = Math.Cos(β);

            startPoint = new Point(x0 + δx * cosα, y0 + δy * sinα);
            var destPoint = new Point(x0 + δx * cosβ, y0 + δy * sinβ);
            var size = new Size(δx, δy);
            bool isLargeArc = Math.Abs(sweepAngle) >= 180;
            SweepDirection sweepDirection =
                sweepAngle > 0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
            bool isStroked = true;

            segment.Point = destPoint;
            segment.Size = size;
            segment.RotationAngle = 0.0;
            segment.IsLargeArc = isLargeArc;
            segment.SweepDirection = sweepDirection;
            segment.IsStroked = isStroked;
        }
Beispiel #40
0
 public IArc Convert(IArc arc)
 {
     return arc;
 }
Beispiel #41
0
    public void RemoveArc(IArc arc) {
      if (this != arc.Source && this != arc.Target)
        throw new ArgumentException("The current vertex must be either the arc source or the arc target.");

      if (this == arc.Source) {
        if (!outArcs.Remove(arc)) throw new InvalidOperationException("Arc is not present in this vertex' outgoing arcs.");
      }
      if (this == arc.Target) {
        if (!inArcs.Remove(arc)) throw new InvalidOperationException("Arc is not present in this vertex' incoming arcs.");
      }
      OnArcRemoved(this, new EventArgs<IArc>(arc));
    }
Beispiel #42
0
        public XArcEditor(
            INativeConverter nativeConverter, 
            ICanvasFactory canvasFactory,
            IBoundsFactory boundsFactory,
            ICanvas canvas)
        {
            _canvas = canvas;

            Name = "Arc";
            Key = "A";
            Modifiers = "";

            var moves = _canvas.Moves.Where(_ => _canvas.IsCaptured);
            var drags = Observable.Merge(_canvas.Downs, _canvas.Ups, moves);

            _downs = _canvas.Downs.Where(_ => IsEnabled).Subscribe(p =>
            {
                if (_canvas.IsCaptured)
                {
                    //_xarc.Point2.X = p.X;
                    //_xarc.Point2.Y = p.Y;
                    //_narc.Point2 = _xarc.Point2;
#if CONNECTORS
                    ConnectPoint2(p);
#endif
                    _narc.Bounds.Hide();
                    _canvas.Render(null);
                    _state = State.None;
                    _canvas.ReleaseCapture();
                }
                else
                {
                    _xarc = canvasFactory.CreateArc();
                    _xarc.Point1.X = p.X;
                    _xarc.Point1.Y = p.Y;
                    _xarc.Point2.X = p.X;
                    _xarc.Point2.Y = p.Y;
                    _narc = nativeConverter.Convert(_xarc);
                    _canvas.History.Snapshot(_canvas);
#if CONNECTORS
                    ConnectPoint1(p);
#endif
                    _canvas.Add(_narc);
                    _narc.Bounds = boundsFactory.Create(_canvas, _narc);
                    _narc.Bounds.Update();
                    _narc.Bounds.Show();
                    _canvas.Render(null);
                    _canvas.Capture();
                    _state = State.Size;
                }
            });

            _drags = drags.Where(_ => IsEnabled).Subscribe(p =>
            {
                if (_state == State.Size)
                {
                    _xarc.Point2.X = p.X;
                    _xarc.Point2.Y = p.Y;
                    _narc.Point2 = _xarc.Point2;
                    _narc.Bounds.Update();
                    _canvas.Render(null);
                }
            });
        }
Beispiel #43
0
    public void AddArc(IArc arc) {
      if (this != arc.Source && this != arc.Target)
        throw new ArgumentException("The current vertex must be either the arc source or the arc target.");

      if (arc.Source == arc.Target)
        throw new ArgumentException("Arc source and target must be different.");

      if (this == arc.Source) {
        if (outArcs.Contains(arc)) throw new InvalidOperationException("Arc already added.");
        outArcs.Add(arc);
      }
      if (this == arc.Target) {
        if (inArcs.Contains(arc)) throw new InvalidOperationException("Arc already added.");
        inArcs.Add(arc);
      }
      OnArcAdded(this, new EventArgs<IArc>(arc));
    }
Beispiel #44
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="arc"></param>
 /// <returns></returns>
 public static GdiArc FromXArc(IArc arc)
 {
     return FromXArc(arc.Point1, arc.Point2, arc.Point3, arc.Point4);
 }
Beispiel #45
0
 private void Write(IArc arc)
 {
     Write(NativeType.Arc);
     _writer.Write(arc.Id);
     Write(arc.Point1);
     Write(arc.Point2);
     _writer.Write(arc.StartAngle);
     _writer.Write(arc.SweepAngle);
     Write(arc.Stroke);
     _writer.Write(arc.StrokeThickness);
     Write(arc.Fill);
     _writer.Write(arc.IsFilled);
     _writer.Write(arc.IsClosed);
 }
Beispiel #46
0
        private void DrawArc(XGraphics gfx, IArc arc)
        {
            var pen = new XPen(
                ToXColor(arc.Stroke),
                X(arc.StrokeThickness));

            double x = Math.Min(arc.Point1.X, arc.Point2.X);
            double y = Math.Min(arc.Point1.Y, arc.Point2.Y);
            double width = Math.Abs(arc.Point2.X - arc.Point1.X);
            double height = Math.Abs(arc.Point2.Y - arc.Point1.Y);

            gfx.DrawArc(
                pen,
                X(x),
                Y(y),
                X(width),
                Y(height),
                arc.StartAngle,
                arc.SweepAngle);
        }
Beispiel #47
0
 private void Process(IArc arc)
 {
     arc.Id = NextId();
     Process(arc.Point1);
     Process(arc.Point2);
 }
Beispiel #48
0
 public IArc Convert(IArc arc)
 {
     return new WpfArc(arc);
 }
Beispiel #49
0
 private void Reset(IArc arc)
 {
     arc.Id = 0;
     Reset(arc.Point1);
     Reset(arc.Point2);
 }
Beispiel #50
0
 public void AddArc(IArc arc)
 {
 }
Beispiel #51
0
 public IBounds Create(ICanvas canvas, IArc arc)
 {
     return new ArcBounds(
         _nativeConverter,
         _canvasFactory,
         canvas,
         arc,
         0.0,
         7.5);
 }