Sha256: 7ce084e976659cd78319594296090493eaa5da43f0e56543f5887529a1d0c3b9
Contents?: true
Size: 1.46 KB
Versions: 31
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true module Torque module PostgreSQL class Segment < Struct.new(:point0, :point1) def x1=(value) self.point0 = new_point(value, y1) end def x1 point0.x end def y1=(value) self.point0 = new_point(x1, value) end def y1 point0.y end def x2=(value) self.point1 = new_point(value, y2) end def x2 point1.x end def y2=(value) self.point1 = new_point(x2, value) end def y2 point1.y end private def new_point(x, y) Torque::PostgreSQL.config.geometry.point_class.new(x, y) end end config.geometry.segment_class ||= ::ActiveRecord.const_set('Segment', Class.new(Segment)) module Adapter module OID class Segment < Torque::PostgreSQL::GeometryBuilder PIECES = %i[x1 y1 x2 y2].freeze FORMATION = '((%s,%s),(%s,%s))'.freeze protected def point_class Torque::PostgreSQL.config.geometry.point_class end def build_klass(*args) return nil if args.empty? check_invalid_format!(args) x1, y1, x2, y2 = args.try(:first, pieces.size)&.map(&:to_f) config_class.new( point_class.new(x1, y1), point_class.new(x2, y2), ) end end end end end end
Version data entries
31 entries across 31 versions & 1 rubygems