<commit_before>class MeshTriangle
  require_relative '../intersectable.rb'
  require_relative '../ray.rb'
  require_relative '../hit_record.rb'
  
  include Intersectable
  
  # Defines a triangle by referring back to a Mesh and its vertex and
  # index arrays.
  
  attr_accessor :mesh,
                :index,
                :spanning_vertices,
                :spanning_normal
  
  def initialize(mesh, index)
    @mesh = mesh
    @index = index
    
    # build triangle
    vertices = mesh.vertices
    indices = mesh.indices
    
    spanning_vertices_idx = indices.values_at(index, index+1, index+2)
    @spanning_vertices = []
    @spanning_vertices = vertices.values_at(index, index+1, index+2).map do |v|
      Vector3f.make_from_floats(v)
    end
    # 
    # 3.times do |i|
    #   @spanning_vertices << Vector3f.make_from_floats(spanning_vertices[i])
    # end
    
    # do further stuff here, prepare for intersection testing
    # prepare for later boundung box init
    # store as much as possible
  end
  
  private 
  
  # use BC coordinates
  def inside_triangle? (beta, gamma)
    unit_range = [0.0, 1.0]
    no_triangle_hit = ([beta,gamma].all? do |expression| 
      is_between(expression, unit_range, "<=")})
    end
    
    # inside or outhsie triangle but not ON triangle (i.e. hit)
    no_triangle_hit ? false : is_between((gamma+beta), unit_range, "<")
  end
  
  # is given  value fulfilling condition
  # condition: range.first <= value <= range.last
  # @param value to check whether it is in range.
  # @param range Array contining upper and lower bound of range.
  # @param operation, i.e. comparission operator, as string 
  # @return condition:Boolean state 
  def is_between?(value, range, operation)
    (value <= range.last) && (value >= )
    value.send(operation, range.last) && range.first.send(operation, value)
  end
  
  
  
end<commit_msg>Changed constructor of mesh triangles<commit_after>class MeshTriangle
  require_relative '../intersectable.rb'
  require_relative '../ray.rb'
  require_relative '../hit_record.rb'
  
  include Intersectable
  
  # Defines a triangle by referring back to a Mesh and its vertex and
  # index arrays.
  
  attr_accessor :p_x, :p_y, :p_z
  
  # compute triangle spanning vertices
  # TODO explain beta_gama
  def initialize(mesh, index)
    binding.pry
    
    idxs = mesh.indices.values_at(index, index+1, index+2)
    verts = mesh.vertices.values_at(idxs[0], idxs[1], idxs[2]).map do |v|
      Vector3f.make_from_floats(v)
    end
    
    # spanning triangle points
    @p_x = verts[0]
    @p_y = verts[1]
    @p_z = verts[2]
  end
  
  def intersect ray
    hit_record = nil
    
    a_to_b = @p_x.s_copy.sub(@p_y)
    a_to_c = @p_x.s_copy.sub(@p_z)
    
    triangle = Matrix3f.new(nil, nil, nil)
		triangle.set_column_at(1, a_to_b);
		triangle.set_column_at(2, a_to_c);
    triangle.set_column_at(3, ray.direction);    
    b = @p_x.s_copy.sub(ray.origin)
    
    # solve system
    # beta_gamma_triangle = System.solve3x3System(triangle, b)
    # TODO please extand functionalitz in oder to work with a 
    # LUP or Cholesky solver
    # highly unstable under certain circumstances
    beta_gamma_triangle = triangle.invert.mult(b)
    if beta_gamma_triangle.nil?
      return nil
    elsif inside_triangle?(beta_gamma_triangle)
      # compute hit_record data
    end
    hit_record
  end
  
  
  
  private 
  
  # use BC coordinates
  # was triangle intersected
  def inside_triangle? (beta, gamma)
    unit_range = [0.0, 1.0]
    no_triangle_hit = ([beta,gamma].all? do |expression| 
      is_between(expression, unit_range, "<=")})
    end
    
    # inside or outhsie triangle but not ON triangle (i.e. hit)
    no_triangle_hit ? false : is_between((gamma+beta), unit_range, "<")
  end
  
  # is given  value fulfilling condition
  # condition: range.first <= value <= range.last
  # @param value to check whether it is in range.
  # @param range Array contining upper and lower bound of range.
  # @param operation, i.e. comparission operator, as string 
  # @return condition:Boolean state 
  def is_between?(value, range, operation)
    (value <= range.last) && (value >= )
    value.send(operation, range.last) && range.first.send(operation, value)
  end
  
  
end
{'fraction_non_alphanumeric': 0.10056258790436005, 'fraction_numerical': 0.007032348804500703, 'mean_word_length': 2.9399815327793166, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4993710', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1418, 'n_words': 377}