<commit_before>module CP
  # FIXME tell <NAME> that this function is missing from chipmunk_ffi.h
  # cp_static_inline :cpArbiterIsFirstContact, [:pointer], :int
  
  cp_static_inline :cpArbiterGetNormal, [:pointer, :int], Vect.by_value
  cp_static_inline :cpArbiterGetPoint, [:pointer, :int], Vect.by_value
  
  func :cpArbiterTotalImpulse, [:pointer], Vect.by_value
  func :cpArbiterTotalImpulseWithFriction, [:pointer], Vect.by_value
  
  class ArbiterStruct < NiceFFI::Struct
    layout(
      :num_contacts, :int,
      :contacts, :pointer,
      :a, :pointer,
      :b, :pointer,
      :e, CP_FLOAT,
      :u, CP_FLOAT,
      :surf_vr, Vect.by_value,
      :stamp, :int,
      :handler, :pointer,
      :swapped_col, :char,
      :first_col, :char
    )
  end
  
  class Arbiter
    attr_reader :struct
    def initialize(ptr)
      @struct = ArbiterStruct.new(ptr)
      @shapes = nil
    end
    
    def first_contact?
      # CP.cpArbiterIsFirstContact(@struct.pointer).nonzero?
      @struct.first_col.nonzero?
    end
    
    def point(index = 0)
      raise IndexError unless (0...@struct.num_contacts).include? index
      
      # FIXME I think this shouldn't happen but it does:
      raise FFI::NullPointerError if @struct.contacts.null?
      
      Vec2.new CP.cpArbiterGetPoint(@struct.pointer, index)
    end
    
    def normal(index = 0)
      raise IndexError unless (0...@struct.num_contacts).include? index
      
      # FIXME I think this shouldn't happen but it does:
      raise FFI::NullPointerError if @struct.contacts.null?
      
      Vec2.new CP.cpArbiterGetNormal(@struct.pointer, index)
    end
    
    def impulse with_friction = false
      if with_friction
        Vec2.new CP.cpArbiterTotalImpulseWithFriction(@struct.pointer)
      else
        Vec2.new CP.cpArbiterTotalImpulse(@struct.pointer)
      end
    end
    
    def shapes
      return @shapes if @shapes

      swapped = @struct.swapped_col.nonzero?
      arba = swapped ? @struct.b : @struct.a
      arbb = swapped ? @struct.a : @struct.b
<commit_msg>added a message to out NullPointerError bug so nobody gets confused<commit_after>module CP
  # FIXME tell <NAME> that this function is missing from chipmunk_ffi.h
  # cp_static_inline :cpArbiterIsFirstContact, [:pointer], :int
  
  cp_static_inline :cpArbiterGetNormal, [:pointer, :int], Vect.by_value
  cp_static_inline :cpArbiterGetPoint, [:pointer, :int], Vect.by_value
  
  func :cpArbiterTotalImpulse, [:pointer], Vect.by_value
  func :cpArbiterTotalImpulseWithFriction, [:pointer], Vect.by_value
  
  class ArbiterStruct < NiceFFI::Struct
    layout(
      :num_contacts, :int,
      :contacts, :pointer,
      :a, :pointer,
      :b, :pointer,
      :e, CP_FLOAT,
      :u, CP_FLOAT,
      :surf_vr, Vect.by_value,
      :stamp, :int,
      :handler, :pointer,
      :swapped_col, :char,
      :first_col, :char
    )
  end
  
  class Arbiter
    attr_reader :struct
    def initialize(ptr)
      @struct = ArbiterStruct.new(ptr)
      @shapes = nil
    end
    
    def first_contact?
      # CP.cpArbiterIsFirstContact(@struct.pointer).nonzero?
      @struct.first_col.nonzero?
    end
    
    def point(index = 0)
      raise IndexError unless (0...@struct.num_contacts).include? index
      
      # FIXME I think this shouldn't happen but it does:
      raise FFI::NullPointerError, "Arbiter structure returned a null pointer; this is probably a bug" \
        if @struct.contacts.null?
      
      Vec2.new CP.cpArbiterGetPoint(@struct.pointer, index)
    end
    
    def normal(index = 0)
      raise IndexError unless (0...@struct.num_contacts).include? index
      
      # FIXME I think this shouldn't happen but it does:
      raise FFI::NullPointerError, "Arbiter structure returned a null pointer; this is probably a bug" \
        if @struct.contacts.null?
      
      Vec2.new CP.cpArbiterGetNormal(@struct.pointer, index)
    end
    
    def impulse with_friction = false
      if with_friction
        Vec2.new CP.cpArbiterTotalImpulseWithFriction(@struct.pointer)
      else
        Vec2.new CP.cpArbiterTotalImpulse(@struct.pointer)
      end
    end
    
    def shapes
      return @shapes if @shapes

      swapped = @struct.swapped_col.nonzero?
      arba = swapped ? @struct.b : @struct.a
      arbb = swapped ? @struct.a : @struct.b

{'fraction_non_alphanumeric': 0.09750462107208872, 'fraction_numerical': 0.0036968576709796672, 'mean_word_length': 2.722269991401548, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3597879', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1464, 'n_words': 344}