<commit_before>module Joybox
  module Physics

    class PhysicsSprite < Joybox::Core::Sprite

      attr_accessor :body

      def initialize(options = {})
        super
        self.body = options[:body] if options.include? :body
      end

      # We need this method to return true, so Cocos2d continue
      # to call the nodeToParentTransform method
      def dirty
        true 
      end

      def position=(position)
        if @body
          @body.position = position
        end
      end

      def position
        if @body
          @body.position
        else
          [0,0]
        end  
      end

      def nodeToParentTransform
        return super if @body.nil?

        super
        
        position = @body.position
        position = position + anchorPointInPoints if ignoreAnchorPointForPosition
        angle = @body.angle

        x = position.x
        y = position.y
        cosine = Math.cos(angle)
        sine = Math.sin(angle)

        unless anchorPointInPoints == CGPointZero
          x = x + cosine * -anchorPointInPoints.x + -sine * -anchorPointInPoints.y
          y = y + sine * -anchorPointInPoints.x + cosine * -anchorPointInPoints.y        
        end

        rotated_transform = CGAffineTransformMake(cosine, sine, -sine, cosine, x, y)
        CGAffineTransformScale(rotated_transform, self.scaleX, self.scaleY)
      end

    end
<commit_msg>fix for position() and position= for PhysicsSprite when body is not set<commit_after>module Joybox
  module Physics

    class PhysicsSprite < Joybox::Core::Sprite

      attr_accessor :body

      def initialize(options = {})
        super
        self.body = options[:body] if options.include? :body
      end

      # We need this method to return true, so Cocos2d continue
      # to call the nodeToParentTransform method
      def dirty
        true 
      end

      def position=(position)
        if @body
          @body.position = position
        else
          super
        end
      end

      def position
        if @body
          @body.position
        else
          super
        end
      end

      def nodeToParentTransform
        return super if @body.nil?

        super
        
        position = @body.position
        position = position + anchorPointInPoints if ignoreAnchorPointForPosition
        angle = @body.angle

        x = position.x
        y = position.y
        cosine = Math.cos(angle)
        sine = Math.sin(angle)

        unless anchorPointInPoints == CGPointZero
          x = x + cosine * -anchorPointInPoints.x + -sine * -anchorPointInPoints.y
          y = y + sine * -anchorPointInPoints.x + cosine * -anchorPointInPoints.y        
        end

        rotated_transform = CGAffineTransformMake(cosine, sine, -sine, cosine, x, y)
        CGAffineTransformScale(rotated_transform, self.scaleX, self.scaleY)
      end

    end

{'fraction_non_alphanumeric': 0.06757227446882619, 'fraction_numerical': 0.0013932427725531174, 'mean_word_length': 1.8212180746561886, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3855553', 'n_tokens_mistral': 819, 'n_tokens_neox': 786, 'n_words': 225}