Sha256: 37e808c97b139029c95c02ba887751fbc9256ffb9b13ee575a1f1755104a7feb

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module GDAL
  module Transformers
    class TPSTransformer
      # @return [FFI::Function]
      def self.function
        FFI::GDAL::Alg::TPSTransform
      end

      # @param pointer [FFI::Pointer]
      def self.release(pointer)
        return unless pointer && !pointer.null?

        FFI::GDAL::Alg.GDALDestroyTPSTransformer(pointer)
      end

      # @return [FFI::Pointer] C pointer to the C TPS transformer.
      attr_reader :c_pointer

      # @param gcp_list [Array<FFI::GDAL::GCP>]
      # @param reversed [Boolean]
      def initialize(gcp_list, reversed: false)
        gcp_list_ptr = FFI::MemoryPointer.new(:pointer, gcp_list.size)

        # TODO: fasterer: each_with_index is slower than loop
        gcp_list.each_with_index do |gcp, i|
          gcp_list_ptr[i].put_pointer(0, gcp.to_ptr)
        end

        pointer = FFI::GDAL::Alg.GDALCreateTPSTransformer(gcp_list.size, gcp_list_ptr, reversed)

        @c_pointer = FFI::AutoPointer.new(pointer, TPSTransformer.method(:release))
      end

      def destroy!
        TPSTransformer.release(@c_pointer)

        @c_pointer = nil
      end

      # @return [FFI::Function]
      def function
        self.class.function
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ffi-gdal-1.1.0 lib/gdal/transformers/tps_transformer.rb
ffi-gdal-1.0.4 lib/gdal/transformers/tps_transformer.rb
ffi-gdal-1.0.3 lib/gdal/transformers/tps_transformer.rb
ffi-gdal-1.0.2 lib/gdal/transformers/tps_transformer.rb
ffi-gdal-1.0.1 lib/gdal/transformers/tps_transformer.rb
ffi-gdal-1.0.0 lib/gdal/transformers/tps_transformer.rb