Class: Geometry::Line

Inherits:
Object
  • Object
show all
Includes:
ClusterFactory
Defined in:
lib/geometry/line.rb

Overview

/# Line #/#

Direct Known Subclasses

PointSlopeLine, SlopeInterceptLine, TwoPointLine

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from ClusterFactory

included

Instance Attribute Details

#optionsObject



37
38
39
40
# File 'lib/geometry/line.rb', line 37

def options
	@options = {} if !@options
	@options
end

Class Method Details

.[](Array, Array) ⇒ TwoPointLine .[](Point, Point) ⇒ TwoPointLine .[](Vector, Vector) ⇒ TwoPointLine .[](y-intercept, slope) ⇒ SlopeInterceptLine .[](point, slope) ⇒ PointSlopeLine

Overloads:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/geometry/line.rb', line 52

def self.[](*args)
	if( 2 == args.size )
		args.map! {|x| x.is_a?(Array) ? Point[*x] : x}
		
		# If both args are Points, create a TwoPointLine
		return TwoPointLine.new(*args) if args.all? {|x| x.is_a?(Vector)}
		
		# If only the first arg is a Point, create a PointSlopeLine
		return PointSlopeLine.new(*args) if args.first.is_a?(Vector)
		
		# Otherise, create a SlopeInterceptLine
		return SlopeInterceptLine.new(*args)
	else
		nil
	end
end

.horizontal(y_intercept = 0) ⇒ Object



88
89
90
# File 'lib/geometry/line.rb', line 88

def self.horizontal(y_intercept=0)
    SlopeInterceptLine.new(0, y_intercept)
end

.new(from, to) ⇒ TwoPointLine .new(start, end) ⇒ TwoPointLine

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

Returns:



77
78
79
80
81
82
83
84
85
86
# File 'lib/geometry/line.rb', line 77

def self.new(options={})
	from = options[:from] || options[:start]
	to = options[:end] || options[:to]
	
	if from and to
		TwoPointLine.new(from, to)
	else
		raise ArgumentError, "Start and end Points must be provided"
    end
end

.vertical(x_intercept = 0) ⇒ Object



91
92
93
# File 'lib/geometry/line.rb', line 91

def self.vertical(x_intercept=0)
    SlopeInterceptLine.new(1/0.0, x_intercept)
end