本文整理汇总了C#中Set.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# Set.Insert方法的具体用法?C# Set.Insert怎么用?C# Set.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Edges
IEnumerable<PointPair> Edges() {
var set = new Set<PointPair>();
foreach (var poly in Polylines)
for (var pp = poly.StartPoint; pp.Next != null; pp = pp.Next)
set.Insert(FlipCollapser.OrderedPair(pp));
return set;
}
示例2: SwitchFlips
void SwitchFlips() {
var queued = new Set<Polyline>(Polylines);
var queue = new Queue<Polyline>();
foreach (Polyline e in Polylines)
queue.Enqueue(e);
while (queue.Count > 0) {
Polyline initialPolyline = queue.Dequeue();
queued.Remove(initialPolyline);
Polyline changedPolyline = ProcessPolyline(initialPolyline);
if (changedPolyline != null) {
//we changed both polylines
if (!queued.Contains(initialPolyline)) {
queued.Insert(initialPolyline);
queue.Enqueue(initialPolyline);
}
if (!queued.Contains(changedPolyline)) {
queued.Insert(changedPolyline);
queue.Enqueue(changedPolyline);
}
}
}
}
示例3: EdgePassport
/// <summary>
/// The set of shapes where the edgeGeometry source and target ports shapes are citizens.
/// In the simple case it is the union of the target port shape parents and the sourceport shape parents.
/// When one end shape contains another, the passport is the set consisting of the end shape and all other shape parents.
/// </summary>
/// <param name="edge"></param>
/// <returns></returns>
Set<Shape> EdgePassport(Edge edge) {
EdgeGeometry edgeGeometry = edge.EdgeGeometry;
var ret = new Set<Shape>();
var sourceShape = portsToShapes[edgeGeometry.SourcePort];
var targetShape = portsToShapes[edgeGeometry.TargetPort];
if (IsAncestor(sourceShape, targetShape)) {
ret.InsertRange(targetShape.Parents);
ret.Insert(sourceShape);
return ret;
}
if (IsAncestor(targetShape, sourceShape)) {
ret.InsertRange(sourceShape.Parents);
ret.Insert(targetShape);
return ret;
}
if (sourceShape != looseRoot)
ret.InsertRange(sourceShape.Parents);
if (targetShape != looseRoot)
ret.InsertRange(targetShape.Parents);
return ret;
}
示例4: chromatogramListForm_CellClick
void chromatogramListForm_CellClick( object sender, ChromatogramListCellClickEventArgs e )
{
if( e.Chromatogram == null || e.Button != MouseButtons.Right )
return;
ChromatogramListForm chromatogramListForm = sender as ChromatogramListForm;
List<GraphItem> selectedGraphItems = new List<GraphItem>();
Set<int> selectedRows = new Set<int>();
foreach( DataGridViewCell cell in chromatogramListForm.GridView.SelectedCells )
{
if( selectedRows.Insert( cell.RowIndex ).WasInserted )
selectedGraphItems.Add( chromatogramListForm.GetChromatogram( cell.RowIndex ) as GraphItem );
}
if( selectedRows.Count == 0 )
chromatogramListForm.GridView[e.ColumnIndex, e.RowIndex].Selected = true;
ContextMenuStrip menu = new ContextMenuStrip();
if( CurrentGraphForm != null )
{
if( selectedRows.Count == 1 )
{
menu.Items.Add( "Show as Current Graph", null, new EventHandler( graphListForm_showAsCurrentGraph ) );
menu.Items.Add( "Overlay on Current Graph", null, new EventHandler( graphListForm_overlayOnCurrentGraph ) );
menu.Items.Add( "Stack on Current Graph", null, new EventHandler( graphListForm_stackOnCurrentGraph ) );
} else
{
menu.Items.Add( "Overlay All on Current Graph", null, new EventHandler( graphListForm_overlayAllOnCurrentGraph ) );
menu.Items.Add( "Stack All on Current Graph", null, new EventHandler( graphListForm_showAllAsStackOnCurrentGraph ) );
}
}
if( selectedRows.Count == 1 )
{
menu.Items.Add( "Show as New Graph", null, new EventHandler( graphListForm_showAsNewGraph ) );
menu.Items.Add( "Show Table of Data Points", null, new EventHandler( graphListForm_showTableOfDataPoints ) );
menu.Items[0].Font = new Font( menu.Items[0].Font, FontStyle.Bold );
menu.Tag = e.Chromatogram;
} else
{
menu.Items.Add( "Show All as New Graphs", null, new EventHandler( graphListForm_showAllAsNewGraph ) );
menu.Items.Add( "Overlay All on New Graph", null, new EventHandler( graphListForm_overlayAllOnNewGraph ) );
menu.Items.Add( "Stack All on New Graph", null, new EventHandler( graphListForm_showAllAsStackOnNewGraph ) );
menu.Tag = selectedGraphItems;
}
menu.Show( Form.MousePosition );
}
示例5: MapClustersToIds
void MapClustersToIds(Cluster cluster) {
string id;
var setOfIds = new Set<string>(nodeIds.Values);
foreach (Cluster child in cluster.AllClustersDepthFirst()) {
if (!nodeIds.TryGetValue(child, out id)) {
id = FindNewId(setOfIds);
nodeIds[child] = id;
setOfIds.Insert(id);
}
}
}
示例6: OGraphChanged
/// <summary>
/// oGraph has changed too
/// </summary>
void OGraphChanged()
{
var vDrawingEdges = new Set<DrawingEdge>();
var vDrawingNodes = new Set<DrawingNode>();
foreach (var dro in drawingObjectsToIViewerObjects.Keys) {
var n = dro as DrawingNode;
if (n != null)
vDrawingNodes.Insert(n);
else {
var edge = dro as DrawingEdge;
if (edge != null)
vDrawingEdges.Insert((DrawingEdge) dro);
}
}
var oDrawgingEdges = new Set<DrawingEdge>();
var oDrawingNodes = new Set<DrawingNode>();
var oGraph = ((LgLayoutSettings) Graph.LayoutAlgorithmSettings).OGraph;
foreach (var node in oGraph.Nodes)
oDrawingNodes.Insert((DrawingNode) node.UserData);
foreach (var edge in oGraph.Edges)
oDrawgingEdges.Insert((DrawingEdge) edge.UserData);
ProcessRemovalsForLg(vDrawingNodes - oDrawingNodes, vDrawingEdges - oDrawgingEdges);
ProcessAdditions(oDrawingNodes - vDrawingNodes, oDrawgingEdges - vDrawingEdges);
// TestCorrectness(oGraph, oDrawingNodes, oDrawgingEdges);
double pathThickness = GetBorderPathThickness();
foreach (var viewerObject in Entities) {
if (viewerObject is XNode)
{
((XNode)viewerObject).BorderPathThickness = pathThickness;
}
else if (viewerObject is XEdge)
{
((XEdge)viewerObject).StrokePathThickness = pathThickness / 2;
}
Invalidate(viewerObject);
}
SetBackgroundRectanglePositionAndSize(((LgLayoutSettings) drawingGraph.LayoutAlgorithmSettings).OGraph);
}
示例7: MoveNodePositions
/// <summary>
/// Lets the tree grow according to the ideal distances.
/// </summary>
/// <param name="treeEdges"></param>
/// <param name="nodePositions"></param>
/// <param name="rootNodeId"></param>
static void MoveNodePositions(List<Tuple<int, int, double, double, double>> treeEdges, Point[] nodePositions,
int rootNodeId) {
var posOld = (Point[]) nodePositions.Clone();
var visited = new Set<int>();
visited.Insert(rootNodeId);
for (int i = 0; i < treeEdges.Count; i++) {
var tupleEdge = treeEdges[i];
if (visited.Contains(tupleEdge.Item1))
MoveUpperSite(tupleEdge, nodePositions, posOld, visited);
else {
Debug.Assert(visited.Contains(tupleEdge.Item2));
MoveLowerSite(tupleEdge, nodePositions, posOld, visited);
}
}
}
示例8: UpdateRegionsForPossibleJumpersAndInsertJumpers
/// <summary>
/// some other jumpers may stop being ones if the jump
/// was just in to their destination layer, so before the actual
/// jump we have to recheck if the jump makes sense
///
/// </summary>
/// <param name="jumperLayer">old layer of jumper</param>
/// <param name="jumper"></param>
void UpdateRegionsForPossibleJumpersAndInsertJumpers(int jumperLayer, int jumper) {
Set<int> neighborPossibleJumpers = new Set<int>();
//update possible jumpers neighbors
foreach (int v in new Pred(dag, jumper))
if (IsJumper(v)) {
this.CalculateRegionAndInsertJumper(v);
neighborPossibleJumpers.Insert(v);
}
foreach (int v in new Succ(dag, jumper))
if (IsJumper(v)) {
this.CalculateRegionAndInsertJumper(v);
neighborPossibleJumpers.Insert(v);
}
List<int> possibleJumpersToUpdate = new List<int>();
foreach (KeyValuePair<int, IntPair> kv in this.possibleJumperFeasibleIntervals) {
if (!neighborPossibleJumpers.Contains(kv.Key))
if (kv.Value.x > jumperLayer && kv.Value.y < jumperLayer)
possibleJumpersToUpdate.Add(kv.Key);
}
foreach (int v in possibleJumpersToUpdate)
this.CalculateRegionAndInsertJumper(v);
}
示例9: CreatePregraphFromSetOfEdgeGeometries
private PreGraph CreatePregraphFromSetOfEdgeGeometries(EdgeGeometry[] egs) {
var nodeBoundaries = new Set<ICurve>();
var eg = egs[0];
var c = GetPortCurve(eg.SourcePort);
var rect = c.BoundingBox;
nodeBoundaries.Insert(c);
nodeBoundaries.Insert(eg.TargetPort.Curve);
rect.Add(eg.TargetPort.Curve.BoundingBox);
var overlapped = nodeTree.GetNodeItemsIntersectingRectangle(rect);
foreach (var nodeBoundary in overlapped)
nodeBoundaries.Insert(nodeBoundary);
return new PreGraph(egs, nodeBoundaries);
}
示例10: ThreadBoneEdgeThroughCdt
Set<CdtEdge> ThreadBoneEdgeThroughCdt(SdBoneEdge boneEdge) {
var start = boneEdge.SourcePoint;
var currentTriangle = boneEdge.Source.Triangle;
Debug.Assert(Cdt.PointIsInsideOfTriangle(start, currentTriangle));
var crossedEdges = new Set<CdtEdge>();
var end = boneEdge.TargetPoint;
if (Cdt.PointIsInsideOfTriangle(end, currentTriangle))
return crossedEdges;
var threader = new CdtThreader(currentTriangle, start, end);
while (threader.MoveNext()) {
CdtEdge piercedEdge = threader.CurrentPiercedEdge;
Debug.Assert(piercedEdge != null);
if (Gates.Contains(piercedEdge))
crossedEdges.Insert(piercedEdge);
}
/*
CdtEdge piercedEdge = CdtIntersections.FindFirstPiercedEdge(currentTriangle, start, end, out negativeSign, out positiveSign, this.Cdt );
Debug.Assert(piercedEdge != null);
do {
if (Gates.Contains(piercedEdge))
crossedEdges.Insert(piercedEdge);
}
while (CdtIntersections.FindNextPierced(start, end, ref currentTriangle, ref piercedEdge, ref negativeSign, ref positiveSign));
*/
//if(ddd(boneEdge))
//CdtSweeper.ShowFront(Cdt.GetTriangles(),null,new []{new LineSegment(boneEdge.SourcePoint,boneEdge.TargetPoint)}, crossedEdges.Select(e=>new LineSegment(e.upperSite.Point,e.lowerSite.Point)));
return crossedEdges;
}
示例11: CreateAbridgedGraph
/// <summary>
/// Create an abstraction of the graph by pairing edges with the shortest
/// symmetric difference of neighbour sets. In a perfect world the result
/// would have half as many nodes as the input graph. In practice we only
/// process the edge list once, and don't pair edges whose ends are already
/// paired so the output may have more than n/2 nodes.
/// </summary>
/// <param name="graph">The input graph</param>
/// <param name="edgeLengthOffset">Initial edge length adjustment percent before proportional adjustments.</param>
/// <param name="edgeLengthMultiplier">The percent length adjustment unit.</param>
/// <returns>an abridged graph</returns>
private GeometryGraph CreateAbridgedGraph(GeometryGraph graph, double edgeLengthOffset, double edgeLengthMultiplier)
{
LayoutAlgorithmHelpers.SetEdgeLengthsProportionalToSymmetricDifference(graph, edgeLengthOffset, edgeLengthMultiplier);
var g2 = new GeometryGraph();
var nodes = new Set<Node>(graph.Nodes);
var rand = new Random(1);
// edges sorted by increasing weight, edges with the same weight shuffled
var edges = (from e in graph.Edges
let r = rand.Next()
orderby e.Length, r
select e).ToList();
// mapping from nodes in graph to nodes in g2
// each node in g2 may represent either 1 or 2 nodes from graph
var nodeMap = new Dictionary<Node, Node>();
// populate g2 with nodes representing pairs of nodes, paired across the shortest edges first
foreach (var e in edges)
{
if (nodes.Contains(e.Source) && nodes.Contains(e.Target))
{
var pairNode = new Node
{
UserData = e
};
nodeMap[e.Source] = pairNode;
nodeMap[e.Target] = pairNode;
g2.Nodes.Add(pairNode);
nodes.Remove(e.Source);
nodes.Remove(e.Target);
}
}
// populate g2 with remaining singleton nodes from graph
foreach (var u in nodes)
{
var v = new Node
{
UserData = u
};
g2.Nodes.Add(v);
nodeMap[u] = v;
}
// populate g2 with edges - no duplicates, reverse duplicates or self edges allowed
var neighbours = new Set<KeyValuePair<Node, Node>>();
foreach (var e in edges)
{
Node u = nodeMap[e.Source], v = nodeMap[e.Target];
var pair = new KeyValuePair<Node, Node>(u, v);
var raip = new KeyValuePair<Node, Node>(v, u);
if (pair.Key != pair.Value
&& !neighbours.Contains(pair)
&& !neighbours.Contains(raip))
{
var e2 = new Edge(u, v) { Length = e.Length };
neighbours.Insert(pair);
g2.Edges.Add(e2);
}
}
return g2;
}
示例12: PropagateChangesToClusterParents
void PropagateChangesToClusterParents() {
var touchedClusters = new Set<Cluster>();
foreach (var n in objectsToDrag) {
var node = n as GeomNode;
if (node == null) continue;
foreach (var c in node.AllClusterAncestors)
if (c != graph.RootCluster && !objectsToDrag.Contains(c))
touchedClusters.Insert(c);
}
if (touchedClusters.Any())
foreach (var c in graph.RootCluster.AllClustersDepthFirstExcludingSelf())
if (touchedClusters.Contains(c))
c.CalculateBoundsFromChildren(layoutSettings.ClusterMargin);
}
示例13: ReadClusters
void ReadClusters() {
XmlRead();
while (TokenIs(GeometryToken.Cluster))
ReadCluster();
FleshOutClusters();
var rootClusterSet = new Set<Cluster>();
foreach (var cluster in stringToClusters.Values.Select(c => c.Cluster))
if (cluster.ClusterParents == null || !cluster.ClusterParents.Any())
rootClusterSet.Insert(cluster);
if (rootClusterSet.Count == 1)
_graph.RootCluster = rootClusterSet.First();
else {
_graph.RootCluster.AddRangeOfCluster(rootClusterSet);
}
if (!XmlReader.IsStartElement())
ReadEndElement();
}
示例14: ReadEdgeRailIds
void ReadEdgeRailIds(LgData lgData, Dictionary<string, Set<string>> edgeIdToEdgeRailsSet) {
string edgeId = GetAttribute(GeometryToken.EdgeId);
Set<string> railIdSet;
edgeIdToEdgeRailsSet[edgeId] = railIdSet = new Set<string>();
string edgeRailsString = GetAttribute(GeometryToken.EdgeRails);
LgEdgeInfo edgeInfo = lgData.GeometryEdgesToLgEdgeInfos[idToEdges[edgeId]];
foreach (var railId in edgeRailsString.Split(' ')) {
UpdateToRankedEdgeInfoForRail(railId, edgeInfo);
railIdSet.Insert(railId);
}
XmlRead();
}
示例15: RemoveInsidePortsAndSplitBoundaryIfNeeded
Set<Point> RemoveInsidePortsAndSplitBoundaryIfNeeded(Polyline boundary) {
var ret = new Set<Point>();
if (boundary == null) {
foreach (var point in portRTree.GetAllLeaves())
ret.Insert(point);
portRTree.Clear();
return ret;
}
Rectangle boundaryBox = boundary.BoundingBox;
var portLocationsInQuestion = portRTree.GetAllIntersecting(boundaryBox).ToArray();
foreach (var point in portLocationsInQuestion) {
switch (Curve.PointRelativeToCurveLocation(point, boundary)) {
case PointLocation.Inside:
ret.Insert(point);
portLocationsToLoosePolylines[point] = boundary;
portRTree.Remove(new Rectangle(point), point);
break;
case PointLocation.Boundary:
portRTree.Remove(new Rectangle(point), point);
portLocationsToLoosePolylines[point] = boundary;
PolylinePoint polylinePoint = FindPointOnPolylineToInsertAfter(boundary, point);
if (polylinePoint != null)
LineSweeper.InsertPointIntoPolylineAfter(boundary, polylinePoint, point);
else
throw new InvalidOperationException();
break;
}
}
return ret;
}