Advertisement
jwow22

Vertex

Jan 5th, 2022
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3.  
  4. public class Vertex
  5. {
  6.     public Vector3 Position;
  7.     public HashSet<Edge> Edges;
  8.    
  9.     public SelectableVertex Selectable;
  10.     public VertexRenderer Renderer;
  11.  
  12.     public Vertex(Vector3 position)
  13.     {
  14.         Position = position;
  15.         Edges = new HashSet<Edge>();
  16.  
  17.         Selectable = new SelectableVertex(this);
  18.         Renderer = new VertexRenderer(this);
  19.     }
  20.    
  21.     public Edge AddEdge(Vertex target)
  22.     {
  23.         Edge edge = new Edge(this, target);
  24.         Edges.Add(edge);
  25.         return edge;
  26.     }
  27.  
  28.     public void RemoveEdge(Vertex target)
  29.     {
  30.         foreach (Edge edge in Edges)
  31.         {
  32.             if (edge.Destination == target)
  33.             {
  34.                 Edges.Remove(edge);
  35.                 return;
  36.             }
  37.         }
  38.     }
  39.  
  40.     public List<Vertex> GetConnectedVertices()
  41.     {
  42.         List<Vertex> connectedVertices = new List<Vertex>();
  43.         foreach (Edge edge in Edges)
  44.         {
  45.             connectedVertices.Add(edge.Destination);
  46.         }
  47.         return connectedVertices;
  48.     }
  49.  
  50.     public void MoveTo(Vector3 position)
  51.     {
  52.         Position = position;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement