internal static c_line_segment[] parse_path(string input_path) { List <c_line_segment> results = new List <c_line_segment>(); c_vector previous_position = new c_vector(); int total_distance = 0; foreach (string input_direction in input_path.Split(",")) { c_vector new_position = new c_vector(previous_position); int input_direction_magnitude = int.Parse(input_direction.Substring(1)); switch (input_direction[0]) { case 'L': new_position.x -= input_direction_magnitude; break; case 'R': new_position.x += input_direction_magnitude; break; case 'D': new_position.y -= input_direction_magnitude; break; case 'U': new_position.y += input_direction_magnitude; break; } results.Add(new c_line_segment(previous_position, total_distance, new_position)); total_distance += new_position.taxi_distance(previous_position); previous_position = new_position; } return(results.ToArray()); }
private c_scanner( c_vector input_scanner, c_vector[] input_beacons) { scanner = input_scanner; beacons = input_beacons; }
public static c_matrix scale(c_vector s) { c_matrix result = identity(); result.values[0, 0] *= s.x; result.values[1, 1] *= s.y; result.values[2, 2] *= s.z; return(result); }
public static c_matrix translate(c_vector t) { c_matrix result = identity(); result.values[0, 3] += t.x; result.values[1, 3] += t.y; result.values[2, 3] += t.z; return(result); }
// create a new scanner that is equivalent to this, but with operation applied to all the objects. private c_scanner apply(c_matrix operation) { c_vector result_scanner = operation.multiply(scanner); c_vector[] result_beacons = new c_vector[beacons.Length]; for (int i = 0; i < beacons.Length; i++) { result_beacons[i] = operation.multiply(beacons[i]); } return(new c_scanner(result_scanner, result_beacons)); }
public c_scanner(c_input_reader input_reader) { List <c_vector> beacon_list = new List <c_vector>(); while (input_reader.has_more_lines()) { string input_line = input_reader.read_line(); if (string.IsNullOrEmpty(input_line)) { break; } int[] input_numbers = input_line.Split(",").Select(x => int.Parse(x)).ToArray(); beacon_list.Add(new c_vector(input_numbers[0], input_numbers[1], input_numbers[2])); } scanner = new c_vector(0, 0, 0); beacons = beacon_list.ToArray(); }
public c_vector multiply(c_vector vector) { // applies the current operation to the inputted vector. c_vector result = new c_vector(); result.x = vector.x * this.values[0, 0] + vector.y * this.values[0, 1] + vector.z * this.values[0, 2] + this.values[0, 3]; result.y = vector.x * this.values[1, 0] + vector.y * this.values[1, 1] + vector.z * this.values[1, 2] + this.values[1, 3]; result.z = vector.x * this.values[2, 0] + vector.y * this.values[2, 1] + vector.z * this.values[2, 2] + this.values[2, 3]; return(result); }
public c_line_segment(c_vector s, int d, c_vector e) { start = s; base_distance = d; size = new c_rectangle(s, e); }
public c_intersection(c_vector p, int t_d) { position = p; total_distance = t_d; }