Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created April 8, 2017 16:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jianminchen/ff813b8a6cb1ed10a94ba728044fc796 to your computer and use it in GitHub Desktop.
H Tree - mocking experience study - April 8, 2017
///
///H-tree
// center (1,1) , starting_length 2, depth 2
// | - | => H
// drawLine((0,0), (0,2)) = vertical line, x = 0
// drawLine (0,1), (2, 1) - horizontal line, height is same, y = 1, center 1,1
// drawLine (2,0), (2, 2) - vertical line, x = 2
//
// H - tree
// H (10,10), starting_length 50, depth 5
// length = 50, length = 50/ 1.41 = 30, you have to min
//
class H-Tree {
static void Main(string[] args) {
Console.WriteLine("Study the performance");
}
internal class Node{
public Tuple<int,int> node {get; set;}
public int depth {get; set;}
public Node(Tuple<int,int> node1, int depth1)
{
node = new Tuple<int,int>(node1.Item1, node1.Item2);
depth = depth1;
}
}
/// total tree - 4 * (startLenght/1.4)^depth
public static IList<Tuple<int,int>> DrawHTreeToDepthUsingBFS(int centerX, int centerY, int startLength, int depth)
{
IList<Tupple<int,int>> centers = new List<Tuple<int,int>();
if(depth == 0)
{
return centers;
}
var node = new Node(new Node(new Tuple<centerX, centerY), 0);
var queue = new Queue<node>();
queue.Enqueue(new Tuple<int,int>(centerX, centerY));
var adjustLength = depth;
while(queue.count > 0)
{
var current = queue.Dequeue();
var centerX1 = current.node.Item1;
var centerY1 = current.node.Item2;
var depth = current.depth;
centers.Add(newTuple(centerX1, centerY1));
depth ++;
adjustLength /= depth;
var leftTop = new Node(Tuple<int,int>(centerX1 - adjustLength/2, centY1 - adjustLength/2), depth);
var leftBottome = new Node(Tuple<int,int>(centerX1 - adjustLength/2, centY1 - adjustLength/2), depth);
var rightTop = new Node(Tuple<int,int>(centerX1 - adjustLength/2, centY1 - adjustLength/2), depth);
var rightBottom = new Node(Tuple<int,int>(centerX1 - adjustLength/2, centY1 - adjustLength/2), depth);
queue.endque(leftTop) ;
queue.endque(leftBottome) ;
queue.endque(rightTop) ;
queue.endque(rightBottom) ;
}
return centers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment