Sha256: 0bee7c9a608c1c58ac0d747154dfdcfee8e8c51dd9b36ba9c9dfb38477e37486

Contents?: true

Size: 1.64 KB

Versions: 9

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

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

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

      # @param gcp_list [Array<FFI::GDAL::GCP>]
      # @param requested_polynomial_order [Fixnum] 1, 2, or 3.
      # @param reversed [Boolean]
      def initialize(gcp_list, requested_polynomial_order, reversed = false, tolerance: nil, minimum_gcps: nil)
        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

        @c_pointer = if tolerance || minimum_gcps
                       FFI::GDAL::Alg.GDALCreateGCPRefineTransformer(
                         gcp_list.size,
                         gcp_list_ptr,
                         requested_polynomial_order,
                         reversed
                       )
                     else
                       FFI::GDAL::Alg.GDALCreateGCPTransformer(
                         gcp_list.size,
                         gcp_list_ptr,
                         requested_polynomial_order,
                         reversed
                       )
                     end
      end

      def destroy!
        return unless @c_pointer

        FFI::GDAL::Alg.GDALDestroyGCPTransformer(@c_pointer)
        @c_pointer = nil
      end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ffi-gdal-1.0.0.beta16 lib/gdal/transformers/gcp_transformer.rb
ffi-gdal-1.0.0.beta15 lib/gdal/transformers/gcp_transformer.rb
ffi-gdal-1.0.0.beta14 lib/gdal/transformers/gcp_transformer.rb
ffi-gdal-1.0.0.beta13 lib/gdal/transformers/gcp_transformer.rb
ffi-gdal-1.0.0.beta12 lib/gdal/transformers/gcp_transformer.rb
ffi-gdal-1.0.0.beta11 lib/gdal/transformers/gcp_transformer.rb
ffi-gdal-1.0.0.beta10 lib/gdal/transformers/gcp_transformer.rb
ffi-gdal-1.0.0.beta9 lib/gdal/transformers/gcp_transformer.rb
ffi-gdal-1.0.0.beta8 lib/gdal/transformers/gcp_transformer.rb