public MarkGeometriesWrapper(IMarkGeometry[] geometries) { foreach (var geometry in geometries) { if (geometry is MarkGeometryPoint point) { Points.Add(point); } else if (geometry is MarkGeometryLine line) { Lines.Add(line); } else if (geometry is MarkGeometryPath path) { Paths.Add(path); } else if (geometry is MarkGeometryArc arc) { Arcs.Add(arc); } else if (geometry is MarkGeometryCircle circle) { Circles.Add(circle); } } Update(); }
public int RangeToShipBySector(GenericShip anotherShip, ArcType arcType) { GenericArc arc = Arcs.First(n => n.ArcType == arcType); ShotInfoArc arcInfo = new ShotInfoArc(HostShip, anotherShip, arc); return(arcInfo.Range); }
/// <summary> /// Добавление дуги /// </summary> /// <param name="fromID">ID вершины, откуда идёт дуга</param> /// <param name="arcName">Имя дуги</param> /// <param name="toID">ID вершины, куда идёт дуга</param> public Arc AddArc(int fromID, string arcName, int toID) { var fromNode = Mota(fromID); var toNode = Mota(toID); if (ArcExists(fromID, arcName, toID)) { throw new ArgumentException(string.Format("Между вершинами {0} и {1} " + "уже есть дуга {2}", fromNode.Name, toNode.Name, arcName)); } if (fromID == toID) { throw new ArgumentException("Нельзя ссылаться на себя"); } //Добавляем дугу в список var arc = new Arc { From = fromNode.ID, Name = arcName.Trim(), To = toNode.ID }; Arcs.Add(arc); IsChanged = true; return(arc); }
private void OnDoManagement(object sender, EventArgs e) { bool more = true; while (more) { more = false; double bestScore = -1.0; RuleAction bestArc = null; foreach (var arc in Arcs.FindAll(arc => arc.SourceName == CurrentState)) { double score = 1; foreach (string testCondition in arc.Conditions) { object value = FindByPath(testCondition)?.Value; if (value == null) { throw new Exception($"Test condition '{testCondition}' returned nothing"); } score *= Convert.ToDouble(value, CultureInfo.InvariantCulture); } if (score > bestScore) { bestScore = score; bestArc = arc; } } if (bestScore > 0.0) { TransitionTo(bestArc); more = true; } } }
/// <summary> /// Получает список вершин, из которых можно попасть в данную вершину nodeID по /// данной дуге arcName. Список может оказаться пустым. /// </summary> /// <param name="nodeID">ID вершины, куда хотим попасть</param> /// <param name="arcName">имя дуги</param> /// <returns></returns> public List <Node> GetNodesDirectedToMe(int nodeID, string arcName) { return(Arcs .Where(x => x.To == nodeID && x.Name.Trim().ToUpper() == arcName.Trim().ToUpper()) .Select(x => Mota(x.From)).ToList()); }
/// <summary> /// Для неименованной вершины nodeID находит самого верхнего предка по дугам is_a и is_instance /// и возвращает имя дуги, которой этот предок связан с вершиной System /// </summary> /// <param name="nodeID">ID вершины</param> /// <returns>имя дуги, которой предок связан с вершиной System</returns> public string OldestParentArc(int nodeID) { WayToSystemNodes = new List <Node>(); WayToSystemArcs = new List <Arc>(); Node parentNode = Mota(nodeID); WayToSystemNodes.Add(parentNode); if (ArcExists(parentNode.ID, "#is_instance")) { WayToSystemArcs.Add(Arcs.Single(x => x.From == parentNode.ID && x.Name == "#is_instance")); parentNode = GetAttr(parentNode.ID, "#is_instance"); WayToSystemNodes.Add(parentNode); } while (ArcExists(parentNode.ID, "#is_a")) { WayToSystemArcs.Add(Arcs.Single(x => x.From == parentNode.ID && x.Name == "#is_a")); parentNode = GetAttr(parentNode.ID, "#is_a"); WayToSystemNodes.Add(parentNode); } var arcToSystem = GetArcsBetweenNodes(Atom("#System"), parentNode.ID).ToList(); if (!arcToSystem.Any()) { return(string.Empty); } if (arcToSystem.Count() > 1) { throw new ArgumentException("Между родителем и системной вершиной больше 1 дуги"); } WayToSystemArcs.Add(Arcs.Single(x => x.From == Atom("#System") && x.Name == arcToSystem[0].Name && x.To == parentNode.ID)); WayToSystemNodes.Add(Mota(Atom("#System"))); return(arcToSystem[0].Name); }
private SvgPath CreateSlotPath() { var endCapRadius = FastenerDiameter / 2f - Constants.Kerf; var innerArcRadius = Constants.JigHoleSpacing - (FastenerDiameter / 2f - Constants.Kerf); float innerArcX = innerArcRadius * DegreeTrig.Cos(startAngle); float innerArcY = -innerArcRadius *DegreeTrig.Sin(startAngle); // y's are negative b/c they are above the origin hole float outerArcX = outerArcRadius * DegreeTrig.Cos(startAngle); float outerArcY = -outerArcRadius *DegreeTrig.Sin(startAngle); var pointA = Points.MetricPoint(-outerArcX, outerArcY); var pointB = Points.MetricPoint(outerArcX, outerArcY); var pointC = Points.MetricPoint(innerArcX, innerArcY); var pointD = Points.MetricPoint(-innerArcX, innerArcY); var slotPath = Paths.CutPath(); var leftEndCap = MakeEndCap(-innerArcX, innerArcY, -outerArcX, outerArcY); var rightEndCap = MakeEndCap(outerArcX, outerArcY, innerArcX, innerArcY); slotPath.PathData.Add(new SvgMoveToSegment(pointA)); slotPath.PathData.Add(Arcs.SimpleSegment(pointA, outerArcRadius, SvgArcSweep.Positive, pointB)); slotPath.PathData.Add(Arcs.SimpleSegment(pointB, endCapRadius, SvgArcSweep.Positive, pointC)); slotPath.PathData.Add(Arcs.SimpleSegment(pointC, innerArcRadius, SvgArcSweep.Negative, pointD)); // Negative makes the lower arc path back "into" the body of the shape slotPath.PathData.Add(Arcs.SimpleSegment(pointD, endCapRadius, SvgArcSweep.Positive, pointA)); return(slotPath); }
public bool IsShipInSector(GenericShip anotherShip, ArcType arcType) { GenericArc arc = Arcs.First(n => n.ArcType == arcType); ShotInfoArc arcInfo = new ShotInfoArc(HostShip, anotherShip, arc); return(arcInfo.IsShotAvailable); }
/// <summary> /// Adds arc /// </summary> /// <param name="arc">Arc for adding</param> /// <param name="index">Arc index</param> /// <exception cref="ArgumentOutOfRangeException"/> public void AddArc(Arc arc, int index = -1) { if (arc.StartVertex >= Vertices.Count) { throw new ArgumentOutOfRangeException(nameof(arc.StartVertex), @"Index of the vertex must be a non-negative number less than the number of elements in the vertices list"); } if (arc.EndVertex >= Vertices.Count) { throw new ArgumentOutOfRangeException(nameof(arc.EndVertex), @"Index of the vertex must be a non-negative number less than the number of elements in the vertices list"); } if (!Arcs.TrueForAll(arc1 => arc1.StartVertex != arc.StartVertex || arc1.EndVertex != arc.EndVertex)) { throw new ArgumentOutOfRangeException(nameof(arc), @"The Arc already exists"); } if (index == -1) { index = Arcs.Count; } Arcs.Insert(index, arc); ArcAdded?.Invoke(arc, new DigraphChangedEventArgs(index)); }
public void QueueInit() { //this.sweep = 0; //this.siteEvents = []; //var n = this.sites.length; //for (var i = 0; i < n; i++) //{ // var site = this.sites[i]; // this.queuePushSite({ type: this.SITE_EVENT, x: site.x, y: site.y, site: site}); //} //this.NUM_SITES_PROCESSED = this.siteEvents.length; //this.circEvents = []; //this.arcs = []; //this.edges = []; //this.cells = {}; sweep = 0; Sites.Clear(); for (int i = 0; i < Input.Count; i++) { var site = Input[i]; QueuePushSite(site); } CircleEvents.Clear(); Arcs.Clear(); Edges.Clear(); Cells.Clear(); }
public void Clear() { Points.Clear(); Lines.Clear(); Arcs.Clear(); Circles.Clear(); Paths.Clear(); }
private void OnDoManagement(object sender, EventArgs e) { bool more = true; while (more) { more = false; double bestScore = -1.0; RuleAction bestArc = null; foreach (var arc in Arcs.FindAll(arc => arc.SourceName == CurrentState)) { double score = 1; foreach (string testCondition in arc.Conditions) { object value = FindByPath(testCondition)?.Value; if (value == null) { throw new Exception($"Test condition '{testCondition}' returned nothing"); } score *= Convert.ToDouble(value, CultureInfo.InvariantCulture); } if (Verbose) { string arcName = $"Transition from {arc.DestinationName} to {arc.DestinationName}"; string message; if (score > 0) { if (score > bestScore) { message = $"{arcName} is possible and weight of {score} exceeds previous best weight of {bestScore}"; } else { message = $"{arcName} is possible but weight of {score} does not exceed previous best weight of {bestScore}"; } } else { message = $"{arcName} is not possible. Weight = {score}"; } summary.WriteMessage(this, message, MessageType.Diagnostic); } if (score > bestScore) { bestScore = score; bestArc = arc; } } if (bestScore > 0.0) { TransitionTo(bestArc); more = true; } } }
public void AddArc(Arc arc) { if (arc.Link != null) { throw new ArgumentException("The arc already belongs to a link."); } arc.Link = this; Arcs.Add(arc); Connect(arc); }
/// <summary> /// Получает вершину, куда можно попасть из данной вершины по данной дуге /// </summary> /// <param name="fromID">ID вершины, откуда выходит дуга</param> /// <param name="arcName">имя дуги</param> /// <returns></returns> public Node GetAttr(int fromID, string arcName) { try { var t = Arcs.SingleOrDefault(x => x.From == fromID && x.Name.ToUpper() == arcName.Trim().ToUpper()); return(t != null?Mota(t.To) : null); } catch (Exception e) { throw new ArgumentException(ErrMsg + e.Message); } }
public ShotInfoArc GetSectorInfo(GenericShip anotherShip, ArcType arcType) { GenericArc arc = Arcs.FirstOrDefault(n => n.ArcType == arcType); if (arc != null) { return(new ShotInfoArc(HostShip, anotherShip, arc)); } else { return(null); } }
/// <summary> /// Removes arc from the list of digraph vertices /// </summary> /// <param name="index">Index of the arc in the list</param> /// <exception cref="ArgumentOutOfRangeException"/> public void RemoveArc(int index) { if (Arcs.Count <= index || index < 0) { throw new ArgumentOutOfRangeException(nameof(index), @"Index of the arc must be a non-negative number less than the number of elements in the arcs list"); } var removed = Arcs[index]; Arcs.RemoveAt(index); ArcRemoved?.Invoke(removed, new DigraphChangedEventArgs(index)); }
public bool IsShipInSector(GenericShip anotherShip, ArcType arcType) { GenericArc arc = Arcs.First(n => n.ArcType == arcType); ShotInfoArc arcInfo = new ShotInfoArc(HostShip, anotherShip, arc); bool result = arcInfo.IsShotAvailable; if (arcType == ArcType.Bullseye) { HostShip.CallOnBullseyeArcCheck(anotherShip, ref result); } return(result); }
/// <summary> /// Удаляет дугу с именем arcName, проходящую между вершинами from и to. /// </summary> /// <param name="fromID">ID вершины, откуда выходит дуга</param> /// <param name="arcName">Имя дуги</param> /// <param name="toID">ID вершины куда идёт дуга</param> public void DeleteArc(int fromID, string arcName, int toID) { try { var arcToRemove = Arcs.SingleOrDefault(x => x.From == fromID && x.Name.Trim().ToUpper() == arcName.Trim().ToUpper() && x.To == toID); Arcs.Remove(arcToRemove); IsChanged = true; } catch (Exception ex) { throw new ArgumentException(ErrMsg + ex.Message); } }
public Vector2 AddArc(string name, Vector2 start, Vector2 end, Vector2 center, AngleDirection orientation = AngleDirection.CCW) { var radius = Math.Min(Math.Abs((start - center).Modulus()), Math.Abs((end - center).Modulus())); double startAngle = orientation == AngleDirection.CCW? Vector2.Angle(start - center).ToDegree() : Vector2.Angle(end - center).ToDegree(); double endAngle = orientation == AngleDirection.CCW ? Vector2.Angle(end - center).ToDegree() : Vector2.Angle(start - center).ToDegree(); var arc = new Arc(center, radius, startAngle, endAngle) { Comment = name }; Arcs.Add(arc); return(end); }
public IQueryable <ArcEpisodes> FetchArcsWithEpisodes() { var list = new List <Arc>(); var parents = Arcs.ToList(); var children = Episodes.ToList(); return(parents.GroupJoin( children, p => p.Id, c => c.ArcId, (arc, episodes) => new ArcEpisodes { Arc = arc, Episodes = episodes } ).AsQueryable()); }
public virtual void ReadChildData(BinaryReader reader) { int x = 0; _attachmentMarkerName.ReadString(reader); for (x = 0; (x < _arcs.Count); x = (x + 1)) { Arcs.Add(new LiquidArcBlockBlock()); Arcs[x].Read(reader); } for (x = 0; (x < _arcs.Count); x = (x + 1)) { Arcs[x].ReadChildData(reader); } }
/// <summary> /// Adds the specified Arc to the game board. /// </summary> public bool Push(Arc arc, Field field) { if (!field.ValidPlacement(arc)) { return(false); } // Push the arc onto the field arc.Push(field); Arcs.Add(arc); // Notify the island set of connected nodes IslandSet.Connect(field); return(true); }
private void RenderPaths(GCodeFile file) { ClearPaths(); foreach (var cmd in file.Commands) { if (cmd is GCodeLine) { var gcodeLine = cmd as GCodeLine; if (gcodeLine.Rapid) { RapidMoves.Add(new Line3D() { Start = gcodeLine.Start, End = gcodeLine.End }); } else { Lines.Add(new Line3D() { Start = gcodeLine.Start, End = gcodeLine.End }); } } if (cmd is GCodeArc) { var arc = cmd as GCodeArc; var segmentLength = arc.Length / 50; var segments = (cmd as GCodeArc).Split(segmentLength); foreach (var segment in segments) { Arcs.Add(new Line3D() { Start = segment.Start, End = segment.End }); } } } RaisePropertyChanged(nameof(Lines)); RaisePropertyChanged(nameof(RapidMoves)); RaisePropertyChanged(nameof(Arcs)); }
public virtual XElement ToXml() { var xLink = new XElement(ElementName, new XAttribute(XLinkXNames.Type, XLinkTypes.Extended), new XAttribute(XLinkXNames.Role, Role) ); var xNodes = NodesMap.Values.Select(n => n.ToXml()); xLink.Add(xNodes); var xArcs = Arcs.Select(a => a.ToXml()); xLink.Add(xArcs); return(xLink); }
/// <summary> /// Удаление вершины /// </summary> /// <param name="nodeID">ID вершины</param> public void DeleteNode(int nodeID) { if (Nodes.All(x => x.ID != nodeID)) { throw new ArgumentException(ErrMsg + "Мы пытаемся удалить несуществующую вершину"); } //Удаляем входящие и исходящие дуги var arc = Arcs.Where(x => (x.From == nodeID || x.To == nodeID)).ToList(); for (int i = arc.Count - 1; i >= 0; i--) { DeleteArc(arc[i]); } //удаляем вершину Nodes.Remove(Nodes.Single(x => x.ID == nodeID)); IsChanged = true; }
/// <summary> /// Removes the specified Arc from the game board. /// </summary> public bool Pull(Arc arc) { if (arc.IsPulled) { return(false); } // Pull the arc from the field var field = arc.Field; arc.Pull(); Arcs.Remove(arc); // Notify the island set of disconnected nodes IslandSet.Disconnect(field); return(true); }
public Graph(int count) { int number = 0; Points = Enumerable.Range(0, count).Select(i => new Point { Value = number++ }).ToList(); for (int i = 0; i < Points.Count; i++) { for (int j = i + 1; j < Points.Count; j++) { if (!IsAlreadyArc(new Arc(Points[i], Points[j]))) { Arcs.Add(new Arc(Points[i], Points[j])); } } } }
public override void Create() { const float jigTopRadius = Constants.JigHoleSpacing + widthAboveRadiusHoles; const float cornerRadius = 3f; CreateRadiusHoles(out float pivotY); // pivotY is ~26mm Children.Add(Lines.EtchLine(0, -widthAboveRadiusHoles, 0, -(widthAboveRadiusHoles - guideLineLength))); var path = Paths.CutPath(); var pointA = Points.MetricPoint(0, Constants.JigHoleSpacing + pivotY); float pointerCornersY = Constants.JigHoleSpacing + pivotY - rightSideWidth; var pointB = Points.MetricPoint(rightSideWidth, pointerCornersY); const float jigSweep = 45f; // degrees of sweep the jig body will have var angleBeta = Math.PI / 180f * (90 - jigSweep / 2); var angleP = Math.Acos(rightSideWidth / jigTopRadius) - angleBeta; var n = jigTopRadius * DegreeTrig.Sin(jigSweep / 2); var d = 2 * n * Math.Sin(angleP); var c = 2 * n * Math.Cos(angleP); var cY = Constants.JigHoleSpacing - Math.Sqrt(Math.Pow(jigTopRadius, 2) - Math.Pow(rightSideWidth, 2)); var pointC = Points.MetricPoint(rightSideWidth, (float)cY); var dX = -(c - rightSideWidth); var dY = cY + d; var pointD = Points.MetricPoint((float)dX, (float)dY); var pointE = Points.MetricPoint(-rightSideWidth, pointerCornersY); path.PathData.Add(new SvgMoveToSegment(pointA)); path.PathData.Add(new SvgLineSegment(pointA, pointB)); path.PathData.Add(new SvgLineSegment(pointB, pointC)); path.PathData.Add(Arcs.SimpleSegment(pointC, jigTopRadius, SvgArcSweep.Negative, pointD)); path.PathData.Add(new SvgLineSegment(pointD, pointE)); path.PathData.Add(new SvgLineSegment(pointE, pointA)); Children.Add(path); }
private void RenderPaths() { ClearPaths(); foreach (var cmd in _file.Commands) { if (cmd is GCodeLine) { var gcodeLine = cmd as GCodeLine; if (gcodeLine.Rapid) { RapidMoves.Add(new Line3D() { Start = gcodeLine.Start, End = gcodeLine.End }); } else { Lines.Add(new Line3D() { Start = gcodeLine.Start, End = gcodeLine.End }); } } if (cmd is GCodeArc) { var gcodeArc = cmd as GCodeArc; Arcs.Add(new Line3D() { Start = gcodeArc.Start, End = gcodeArc.End }); } } RaisePropertyChanged(nameof(Lines)); RaisePropertyChanged(nameof(RapidMoves)); RaisePropertyChanged(nameof(Arcs)); }
private SvgVisualElement CreateOutline() { const float cornerRadius = 3f; var path = Paths.CutPath(); var bottomY = armThickness / 2; var rightBorderX = bodyRadius; // start drawing the path @ E. E, F, G, A, B, C, D var pointE = Points.MetricPoint(rightBorderX, 0); var pointF = Points.MetricPoint(rightBorderX, bottomY - cornerRadius); var pointG = Points.MetricPoint(rightBorderX - cornerRadius, bottomY); path.PathData.Add(new SvgMoveToSegment(pointE)); path.PathData.Add(new SvgLineSegment(pointE, pointF)); path.PathData.Add(Arcs.SimpleSegment(pointF, cornerRadius, SvgArcSweep.Positive, pointG)); if (armLength > 0) { float leftArmX = -bodyRadius - armLength + cornerRadius; var pointA = Points.MetricPoint(leftArmX, bottomY); var pointB = Points.MetricPoint(leftArmX, bottomY - armThickness); var dY = bottomY - armThickness - cornerRadius; var dX = -(float)Math.Sqrt(Math.Pow(bodyRadius, 2) - Math.Pow(dY, 2)); var pointC = Points.MetricPoint(dX - cornerRadius, dY + cornerRadius); var pointD = Points.MetricPoint(dX, dY); path.PathData.Add(new SvgLineSegment(pointG, pointA)); path.PathData.Add(Arcs.SimpleSegment(pointA, armThickness / 2, SvgArcSweep.Positive, pointB)); path.PathData.Add(new SvgLineSegment(pointB, pointC)); path.PathData.Add(Arcs.SimpleSegment(pointC, cornerRadius, SvgArcSweep.Negative, pointD)); path.PathData.Add(Arcs.SimpleSegment(pointD, bodyRadius, SvgArcSweep.Positive, pointE)); } // todo: else for zero arm return(path); }
//============================ // Use this for initialization void Start() { currentArc = Arcs.Intro; behaviorAgent = new BehaviorAgent (this.InteractiveBehaviorTree()); BehaviorManager.Instance.Register (behaviorAgent); behaviorAgent.StartBehavior (); }
protected Node setArc(Arcs set) { return new Sequence ( new LeafInvoke (() => {currentArc = set;}), new LeafTrace ("Arc set to " + set) ); }
protected Node SelectStoryById(Arcs arcID) { switch (arcID) { case Arcs.Intro: return this.IntroArc (); case Arcs.Round1: return this.Round1Arc (); case Arcs.Round2: return this.Round2Arc (); default: Debug.LogWarning("No arc selected. Default case occured."); return null; } }
protected Node SelectStoryArc(Arcs arcID) { return new SelectorParallel ( new DecoratorLoop(new LeafAssert(() => {return (currentArc != arcID);})), this.SelectStoryById (arcID) ); }