← back to darwin__supex

Function bodies 257 total

All specs Real LLM only Function bodies
build_material_data function · ruby · L232-L240 (9 LOC)
runtime/src/supex_runtime/tools.rb
    def build_material_data(material)
      data = { name: material.name, display_name: material.display_name }

      if material.color
        data[:color] = {
          red: material.color.red, green: material.color.green,
          blue: material.color.blue, alpha: material.alpha
        }
      end
build_camera_info_response function · ruby · L246-L261 (16 LOC)
runtime/src/supex_runtime/tools.rb
    def build_camera_info_response(model)
      camera = model.active_view.camera
      eye = camera.eye
      target = camera.target
      up = camera.up

      {
        success: true,
        eye: [eye.x, eye.y, eye.z],
        target: [target.x, target.y, target.z],
        up: [up.x, up.y, up.z],
        fov: camera.fov,
        aspect_ratio: camera.aspect_ratio,
        perspective: camera.perspective?
      }
    end
determine_screenshot_path function · ruby · L263-L273 (11 LOC)
runtime/src/supex_runtime/tools.rb
    def determine_screenshot_path(output_path)
      if output_path
        path = File.expand_path(output_path)
        FileUtils.mkdir_p(File.dirname(path))
        path
      else
        screenshots_dir = File.join(File.dirname(__FILE__), '..', '..', '..', '.tmp', 'screenshots')
        FileUtils.mkdir_p(screenshots_dir)
        timestamp = Time.now.strftime('%Y%m%d-%H%M%S')
        File.join(screenshots_dir, "screenshot-#{timestamp}.png")
      end
write_screenshot function · ruby · L276-L292 (17 LOC)
runtime/src/supex_runtime/tools.rb
    def write_screenshot(model, screenshot_path, params)
      width = params['width'] || 1920
      height = params['height'] || 1080

      options = {
        filename: screenshot_path, width: width, height: height,
        antialias: true, compression: 0.9, transparent: params['transparent'] || false
      }

      model.active_view.write_image(options)

      {
        success: true, file_path: screenshot_path, file_name: File.basename(screenshot_path),
        width: width, height: height, format: 'png',
        message: "Screenshot saved to #{screenshot_path}. Use Read tool to view if needed."
      }
    end
perform_save function · ruby · L294-L301 (8 LOC)
runtime/src/supex_runtime/tools.rb
    def perform_save(model, path)
      if path
        model.save(path)
        path
      else
        model.save
        model.path
      end
SupexRuntime::Utils.bounds_to_hash method · ruby · L9-L15 (7 LOC)
runtime/src/supex_runtime/utils.rb
    def self.bounds_to_hash(bounds)
      {
        min: [bounds.min.x, bounds.min.y, bounds.min.z],
        max: [bounds.max.x, bounds.max.y, bounds.max.z],
        center: [bounds.center.x, bounds.center.y, bounds.center.z]
      }
    end
SupexRuntime::Utils.show_console method · ruby · L25-L32 (8 LOC)
runtime/src/supex_runtime/utils.rb
    def self.show_console
      SKETCHUP_CONSOLE.show
    rescue StandardError
      begin
        Sketchup.send_action('showRubyPanel:')
      rescue StandardError
        UI.start_timer(0) { SKETCHUP_CONSOLE.show }
      end
Repobility — same analyzer, your code, free for public repos · /scan/
SupexRuntime.create_circle_points method · ruby · L56-L64 (9 LOC)
runtime/src/supex_runtime/utils.rb
    def self.create_circle_points(center, radius, segments = 24)
      points = []
      segments.times do |i|
        angle = Math::PI * 2 * i / segments
        x = center[0] + (radius * Math.cos(angle))
        y = center[1] + (radius * Math.sin(angle))
        z = center[2]
        points << [x, y, z]
      end
create_success_response function · ruby · L72-L78 (7 LOC)
runtime/src/supex_runtime/utils.rb
    def self.create_success_response(request, result)
      {
        jsonrpc: request['jsonrpc'] || '2.0',
        result: result,
        id: request['id']
      }
    end
create_error_response function · ruby · L86-L99 (14 LOC)
runtime/src/supex_runtime/utils.rb
    def self.create_error_response(request, error_message, error_code = -32_603, data = nil)
      error_data = data || { success: false }
      error_data[:success] = false unless error_data.key?(:success)

      {
        jsonrpc: request['jsonrpc'] || '2.0',
        error: {
          code: error_code,
          message: error_message,
          data: error_data
        },
        id: request['id']
      }
    end
SupexStdlib::Color#components method · ruby · L110-L117 (8 LOC)
stdlib/src/supex_stdlib/color.rb
    def components(color)
      {
        r: color.red,
        g: color.green,
        b: color.blue,
        a: color.alpha
      }
    end
SupexStdlib::ComponentDefinition#erase method · ruby · L25-L33 (9 LOC)
stdlib/src/supex_stdlib/component_definition.rb
    def erase(definition)
      definition.instances.each(&:erase!)

      # Erasing all entities purges the definition from the model.
      # Must be done within an operation for safety.
      definition.entities.clear!

      nil
    end
SupexStdlib::ComponentDefinition#place_axes method · ruby · L50-L59 (10 LOC)
stdlib/src/supex_stdlib/component_definition.rb
    def place_axes(definition, new_axes, adjust_instances = true)
      definition.entities.transform_entities(
        new_axes.inverse,
        definition.entities.to_a
      )

      if adjust_instances
        definition.instances.each do |instance|
          instance.transformation *= new_axes
        end
unique_to? function · ruby · L77-L88 (12 LOC)
stdlib/src/supex_stdlib/component_definition.rb
    def unique_to?(definition, scopes)
      raise ArgumentError, 'Expected ComponentDefinition.' unless definition.is_a?(Sketchup::ComponentDefinition)

      scopes = [scopes] unless scopes.is_a?(Array)
      raise ArgumentError, 'Scope is empty.' if scopes.empty?

      # Get all instance paths for this definition
      all_paths = all_instance_paths(definition)

      all_paths.all? do |path|
        scopes.any? { |scope| instance_path_matches_scope?(path, scope) }
      end
all_instance_paths function · ruby · L98-L103 (6 LOC)
stdlib/src/supex_stdlib/component_definition.rb
    def all_instance_paths(definition)
      paths = []

      definition.instances.each do |instance|
        collect_paths_to_instance(instance, [], paths)
      end
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
collect_paths_to_instance function · ruby · L111-L122 (12 LOC)
stdlib/src/supex_stdlib/component_definition.rb
    def collect_paths_to_instance(instance, current_path, paths)
      new_path = current_path + [instance]

      parent = instance.parent
      if parent.is_a?(Sketchup::ComponentDefinition)
        if parent.instances.empty?
          # Definition is in model root
          paths << new_path
        else
          parent.instances.each do |parent_instance|
            collect_paths_to_instance(parent_instance, new_path, paths)
          end
instance_path_matches_scope? function · ruby · L131-L136 (6 LOC)
stdlib/src/supex_stdlib/component_definition.rb
    def instance_path_matches_scope?(path, scope)
      case scope
      when Sketchup::ComponentDefinition
        path.any? do |instance|
          Entity.instance?(instance) && Entity.definition(instance) == scope
        end
SupexStdlib::Edge#midpoint method · ruby · L18-L25 (8 LOC)
stdlib/src/supex_stdlib/edge.rb
    def midpoint(edge)
      ::Geom.linear_combination(
        0.5,
        edge.start.position,
        0.5,
        edge.end.position
      )
    end
SupexStdlib::Entity#swap_definition method · ruby · L56-L70 (15 LOC)
stdlib/src/supex_stdlib/entity.rb
    def swap_definition(instance, new_definition)
      if instance.is_a?(Sketchup::Group) || new_definition.group?
        old_instance = instance
        instance = old_instance.parent.entities.add_instance(
          new_definition,
          old_instance.transformation
        )
        instance.material = old_instance.material
        instance.layer = old_instance.layer
        instance.hidden = old_instance.hidden?
        copy_attributes(instance, old_instance)
        old_instance.erase!
      else
        instance.definition = new_definition
      end
SupexStdlib#copy_attributes method · ruby · L88-L96 (9 LOC)
stdlib/src/supex_stdlib/entity.rb
    def copy_attributes(target, source)
      dicts = source.attribute_dictionaries || []

      dicts.each do |dict|
        next if dict.name == CREDITS_DICT

        dict.each_pair do |key, value|
          target.set_attribute(dict.name, key, value)
        end
has_dictionary? function · ruby · L129-L134 (6 LOC)
stdlib/src/supex_stdlib/entity.rb
    def has_dictionary?(entity, dict_name)
      dicts = entity.attribute_dictionaries
      return false if dicts.nil?

      dicts.any? { |dict| dict.name == dict_name }
    end
dictionary_names function · ruby · L140-L145 (6 LOC)
stdlib/src/supex_stdlib/entity.rb
    def dictionary_names(entity)
      dicts = entity.attribute_dictionaries
      return [] if dicts.nil?

      dicts.map(&:name)
    end
SupexStdlib::Face#arbitrary_interior_point method · ruby · L21-L33 (13 LOC)
stdlib/src/supex_stdlib/face.rb
    def arbitrary_interior_point(face)
      return nil if face.area.zero?

      # In rare situations polygon_points_at returns collinear points,
      # which would lead to a point on the boundary. Loop until we find
      # non-collinear points.
      index = 1
      points = nil
      loop do
        points = face.mesh.polygon_points_at(index)
        index += 1
        break unless points[0].on_line?([points[1], points[2]])
      end
Want this analysis on your repo? https://repobility.com/scan/
SupexStdlib#includes_point? method · ruby · L53-L58 (6 LOC)
stdlib/src/supex_stdlib/face.rb
    def includes_point?(face, point, include_boundary = true)
      pc = face.classify_point(point)
      return include_boundary if [Sketchup::Face::PointOnEdge, Sketchup::Face::PointOnVertex].include?(pc)

      pc == Sketchup::Face::PointInside
    end
SupexStdlib#triangulate method · ruby · L83-L90 (8 LOC)
stdlib/src/supex_stdlib/face.rb
    def triangulate(face, transformation = IDENTITY)
      mesh = face.mesh
      indices = mesh.polygons.flatten.map(&:abs)
      points = indices.map { |i| mesh.point_at(i) }
      points.each { |pt| pt.transform!(transformation) }

      points.each_slice(3).to_a
    end
SupexStdlib#wrapping_face method · ruby · L101-L109 (9 LOC)
stdlib/src/supex_stdlib/face.rb
    def wrapping_face(face)
      edge_faces = face.edges.map(&:faces)
      return nil if edge_faces.empty?

      common_faces = edge_faces.inject(:&)
      return nil if common_faces.nil?

      (common_faces - [face]).first
    end
SupexStdlib::Geom::BoundingBox#center method · ruby · L165-L178 (14 LOC)
stdlib/src/supex_stdlib/geom/bounding_box.rb
      def center
        return nil if empty?

        if is_2d?
          # Center of 4 points
          x = @points.sum(&:x) / 4.0
          y = @points.sum(&:y) / 4.0
          z = @points.sum(&:z) / 4.0
        else
          # Center of 8 points
          x = @points.sum(&:x) / 8.0
          y = @points.sum(&:y) / 8.0
          z = @points.sum(&:z) / 8.0
        end
SupexStdlib#direction_internal method · ruby · L78-L87 (10 LOC)
stdlib/src/supex_stdlib/geom/line.rb
      def direction_internal
        second = at(1)
        if second.is_a?(::Geom::Vector3d)
          second.normalize
        elsif second.is_a?(Array) && second.size == 3
          ::Geom::Vector3d.new(second).normalize
        else
          # Assume second is a point, compute vector from first to second
          at(0).vector_to(second).normalize
        end
SupexStdlib::Geom::Plane#normal method · ruby · L25-L32 (8 LOC)
stdlib/src/supex_stdlib/geom/plane.rb
      def normal(plane)
        raise ArgumentError, "Object doesn't represent a plane." unless valid?(plane)

        return plane[1].normalize if plane.size == 2

        a, b, c = plane
        ::Geom::Vector3d.new(a, b, c).normalize
      end
SupexStdlib::Geom::Plane#point method · ruby · L41-L49 (9 LOC)
stdlib/src/supex_stdlib/geom/plane.rb
      def point(plane)
        raise ArgumentError, "Object doesn't represent a plane." unless valid?(plane)

        return plane[0] if plane.size == 2

        a, b, c, d = plane
        v = ::Geom::Vector3d.new(a, b, c)
        ORIGIN.offset(v, -d)
      end
SupexStdlib::Geom::Plane#parallel? method · ruby · L59-L64 (6 LOC)
stdlib/src/supex_stdlib/geom/plane.rb
      def parallel?(plane_a, plane_b)
        raise ArgumentError, "Object 'plane_a' doesn't represent a plane." unless valid?(plane_a)
        raise ArgumentError, "Object 'plane_b' doesn't represent a plane." unless valid?(plane_b)

        normal(plane_a).parallel?(normal(plane_b))
      end
Same scanner, your repo: https://repobility.com — Repobility
SupexStdlib::Geom::Plane#same? method · ruby · L75-L83 (9 LOC)
stdlib/src/supex_stdlib/geom/plane.rb
      def same?(plane_a, plane_b, include_flipped = false)
        raise ArgumentError, "Object 'plane_a' doesn't represent a plane." unless valid?(plane_a)
        raise ArgumentError, "Object 'plane_b' doesn't represent a plane." unless valid?(plane_b)

        return false unless point(plane_a).on_plane?(plane_b)
        return false unless parallel?(plane_a, plane_b)

        include_flipped || normal(plane_a).samedirection?(normal(plane_b))
      end
SupexStdlib::Geom::Plane#transform method · ruby · L93-L101 (9 LOC)
stdlib/src/supex_stdlib/geom/plane.rb
      def transform(plane, transformation)
        raise ArgumentError, "Object doesn't represent a plane." unless valid?(plane)
        raise ArgumentError, 'Requires transformation.' unless transformation.is_a?(::Geom::Transformation)

        [
          point(plane).transform(transformation),
          Vector.transform_as_normal(normal(plane), transformation)
        ]
      end
SupexStdlib::Geom::Plane#valid? method · ruby · L111-L116 (6 LOC)
stdlib/src/supex_stdlib/geom/plane.rb
      def valid?(plane)
        return false unless plane.is_a?(Array)

        (plane.size == 4 && plane.all? { |e| e.is_a?(Numeric) }) ||
          (plane.size == 2 && valid_point?(plane[0]) && valid_vector?(plane[1]))
      end
SupexStdlib::Geom::Point#between? method · ruby · L22-L33 (12 LOC)
stdlib/src/supex_stdlib/geom/point.rb
      def between?(point, boundary_a, boundary_b, include_boundaries = true)
        return false unless point.on_line?([boundary_a, boundary_b])

        vector_a = point - boundary_a
        vector_b = point - boundary_b

        # Point is on one of the boundaries
        return include_boundaries if !vector_a.valid? || !vector_b.valid?

        # Point is between if vectors point in opposite directions
        !vector_a.samedirection?(vector_b)
      end
SupexStdlib::Geom::Point#front_of_plane? method · ruby · L42-L49 (8 LOC)
stdlib/src/supex_stdlib/geom/point.rb
      def front_of_plane?(point, plane)
        # Get plane normal (handle both plane formats)
        normal = if plane.size == 2
                   plane[1].normalize
                 else
                   # [a, b, c, d] format - normal is [a, b, c]
                   ::Geom::Vector3d.new(plane[0], plane[1], plane[2]).normalize
                 end
SupexStdlib::Geom#mid_point method · ruby · L38-L46 (9 LOC)
stdlib/src/supex_stdlib/geom.rb
    def mid_point(*args)
      case args.size
      when 1 # Edge
        points = args.first.vertices.map(&:position)
      when 2 # Points
        points = args
      else
        raise ArgumentError, "wrong number of arguments (#{args.size} for 1..2)"
      end
SupexStdlib#polygon_area method · ruby · L71-L83 (13 LOC)
stdlib/src/supex_stdlib/geom.rb
    def polygon_area(points)
      origin = points.first
      normal = polygon_normal(points)

      area = 0
      points.each_with_index do |pt0, i|
        pt1 = points[i + 1] || points.first
        triangle_area = ((pt1 - pt0) * (origin - pt0)).length / 2
        if (pt1 - pt0) * (origin - pt0) % normal > 0
          area += triangle_area
        else
          area -= triangle_area
        end
polygon_normal function · ruby · L96-L103 (8 LOC)
stdlib/src/supex_stdlib/geom.rb
    def polygon_normal(points)
      normal = ::Geom::Vector3d.new(0, 0, 0)
      points.each_with_index do |pt0, i|
        pt1 = points[i + 1] || points.first
        normal.x = normal.x + (pt0.y - pt1.y) * (pt0.z + pt1.z)
        normal.y = normal.y + (pt0.z - pt1.z) * (pt0.x + pt1.x)
        normal.z = normal.z + (pt0.x - pt1.x) * (pt0.y + pt1.y)
      end
Repobility — same analyzer, your code, free for public repos · /scan/
angle_in_plane function · ruby · L132-L142 (11 LOC)
stdlib/src/supex_stdlib/geom.rb
    def angle_in_plane(minuend, subtrahend, normal = Z_AXIS)
      # Project vectors to plane by double cross product
      minuend = normal * minuend * normal
      subtrahend = normal * subtrahend * normal

      # Determine if we need to go the "long way" around
      if (minuend * subtrahend) % normal > 0
        Math::PI * 2 - minuend.angle_between(subtrahend)
      else
        minuend.angle_between(subtrahend)
      end
SupexStdlib::Geom#from_euler_angles method · ruby · L56-L61 (6 LOC)
stdlib/src/supex_stdlib/geom/transformation.rb
      def from_euler_angles(origin = ORIGIN, x_angle = 0, y_angle = 0, z_angle = 0)
        ::Geom::Transformation.new(origin) *
          ::Geom::Transformation.rotation(ORIGIN, Z_AXIS, z_angle) *
          ::Geom::Transformation.rotation(ORIGIN, Y_AXIS, y_angle) *
          ::Geom::Transformation.rotation(ORIGIN, X_AXIS, x_angle)
      end
SupexStdlib::Geom#euler_angles method · ruby · L84-L95 (12 LOC)
stdlib/src/supex_stdlib/geom/transformation.rb
      def euler_angles(transformation)
        a = remove_scaling(remove_shearing(transformation, false)).to_a

        x = Math.atan2(a[6], a[10])
        c2 = Math.sqrt(a[0]**2 + a[1]**2)
        y = Math.atan2(-a[2], c2)
        s = Math.sin(x)
        c1 = Math.cos(x)
        z = Math.atan2(s * a[8] - c1 * a[4], c1 * a[5] - s * a[9])

        [x, y, z]
      end
SupexStdlib::Geom#remove_scaling method · ruby · L140-L149 (10 LOC)
stdlib/src/supex_stdlib/geom/transformation.rb
      def remove_scaling(transformation, allow_flip = false)
        x_axis = xaxis(transformation).normalize
        x_axis = x_axis.reverse if flipped?(transformation) && !allow_flip
        from_axes(
          transformation.origin,
          x_axis,
          yaxis(transformation).normalize,
          zaxis(transformation).normalize
        )
      end
SupexStdlib::Geom#remove_shearing method · ruby · L161-L174 (14 LOC)
stdlib/src/supex_stdlib/geom/transformation.rb
      def remove_shearing(transformation, preserve_determinant = false)
        x = xaxis(transformation)
        y = yaxis(transformation)
        z = zaxis(transformation)

        x_norm = x.normalize
        new_yaxis = x_norm * y * x_norm
        y_norm = new_yaxis.normalize
        new_zaxis = y_norm * (x_norm * z * x_norm) * y_norm

        unless preserve_determinant
          new_yaxis = set_vector_length(new_yaxis, y.length)
          new_zaxis = set_vector_length(new_zaxis, z.length)
        end
SupexStdlib#same? method · ruby · L218-L223 (6 LOC)
stdlib/src/supex_stdlib/geom/transformation.rb
      def same?(tr_a, tr_b)
        xaxis(tr_a) == xaxis(tr_b) &&
          yaxis(tr_a) == yaxis(tr_b) &&
          zaxis(tr_a) == zaxis(tr_b) &&
          tr_a.origin == tr_b.origin
      end
SupexStdlib#scale_factor_in_plane method · ruby · L233-L244 (12 LOC)
stdlib/src/supex_stdlib/geom/transformation.rb
      def scale_factor_in_plane(transformation, plane)
        normal = Plane.normal(plane)

        tr = from_axes(
          ORIGIN,
          yaxis(transformation) * zaxis(transformation),
          zaxis(transformation) * xaxis(transformation),
          xaxis(transformation) * yaxis(transformation)
        )

        normal.transform(tr).length.to_f
      end
SupexStdlib#transpose method · ruby · L264-L273 (10 LOC)
stdlib/src/supex_stdlib/geom/transformation.rb
      def transpose(transformation)
        a = transformation.to_a

        ::Geom::Transformation.new([
                                     a[0], a[4], a[8], 0,
                                     a[1], a[5], a[9], 0,
                                     a[2], a[6], a[10], 0,
                                     0, 0, 0, a[15]
                                   ])
      end
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
SupexStdlib#set_vector_length method · ruby · L338-L343 (6 LOC)
stdlib/src/supex_stdlib/geom/transformation.rb
      def set_vector_length(vector, length)
        return vector unless vector.valid?

        normalized = vector.normalize
        ::Geom::Vector3d.new(normalized.x * length, normalized.y * length, normalized.z * length)
      end
SupexStdlib::Geom::Vector#transform_as_normal method · ruby · L50-L82 (33 LOC)
stdlib/src/supex_stdlib/geom/vector.rb
      def transform_as_normal(normal, transformation)
        # Get the 3x3 rotation/scale matrix from the transformation
        # and compute its transpose, then inverse, then apply to normal
        #
        # For a pure rotation, transpose = inverse, so this simplifies.
        # For scaling/shearing, we need the full computation.

        # Extract the 3x3 matrix
        a = transformation.to_a
        m = [
          [a[0], a[1], a[2]],
          [a[4], a[5], a[6]],
          [a[8], a[9], a[10]]
        ]

        # Transpose
        mt = [
          [m[0][0], m[1][0], m[2][0]],
          [m[0][1], m[1][1], m[2][1]],
          [m[0][2], m[1][2], m[2][2]]
        ]

        # Create transformation from transposed matrix (at origin)
        tr_t = ::Geom::Transformation.new([
                                            mt[0][0], mt[0][1], mt[0][2], 0,
                                            mt[1][0], mt[1][1], mt[1][2], 0,
                                            mt[2][0], 
SupexStdlib::Platform#temp_path method · ruby · L46-L57 (12 LOC)
stdlib/src/supex_stdlib/platform.rb
      def temp_path
        paths = [
          Sketchup.temp_dir,
          ENV.fetch('TMPDIR', nil),
          ENV.fetch('TMP', nil),
          ENV.fetch('TEMP', nil)
        ]
        temp = paths.find { |path| path && File.exist?(path) }
        raise 'Unable to locate temp directory' if temp.nil?

        File.expand_path(temp)
      end
‹ prevpage 5 / 6next ›