Sha256: 54ff7093ab0e76c63c714e5335cdf1ca1976aefaaef9c57535108e2be1d1d8f7
Contents?: true
Size: 1.23 KB
Versions: 15
Compression:
Stored size: 1.23 KB
Contents
module Torque module PostgreSQL class Line < Struct.new(:slope, :intercept) alias c intercept alias c= intercept= def a=(value) self.slope = vertical? \ ? Float::INFINITY \ : Rational(value, b) end def a slope.numerator end def b=(value) self.slope = value.zero? \ ? Float::INFINITY \ : Rational(a, value) end def b vertical? ? 0 : slope.denominator end def horizontal? slope.zero? end def vertical? !slope.try(:infinite?).eql?(nil) end end config.geometry.line_class ||= ::ActiveRecord.const_set('Line', Class.new(Line)) module Adapter module OID class Line < Torque::PostgreSQL::GeometryBuilder PIECES = %i[a b c].freeze FORMATION = '{%s,%s,%s}'.freeze protected def build_klass(*args) return nil if args.empty? check_invalid_format!(args) a, b, c = args.try(:first, pieces.size)&.map(&:to_f) slope = b.zero? ? Float::INFINITY : Rational(a, b) config_class.new(slope, c) end end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems