In Files

Parent

LineDescriptor

Author

Manuela Ruiz (mruiz@lcc.uma.es)

This class represents a Line Descriptor, used to describe the ‘mother line’ of a set of segments

Attributes

sine[R]

The sine of the angle

intercept[R]
Intercept

the point in which the line intercepts the y-axis. In case it is vertical, the x-axis

Public Class Methods

new(sine, intercept) click to toggle source
sine

the sine of the angle of the line.

intercept

the point in which the line intercepts the y-axis. In case it is vertical, the x-axis

 Initializes the line
     # File lib/geometry.rb, line 213
213:         def initialize(sine, intercept)

214:                 @sine, @intercept = sine, intercept

215:         end

Public Instance Methods

<(other_line_descriptor) click to toggle source
other_line_descriptor

another LineDescriptor object

returns

true iff this LineDescriptor is lesser than other_line_descriptor, w.r.t. a lexicographic order of (sine, intercept)

     # File lib/geometry.rb, line 239
239:         def < (other_line_descriptor)

240:                 #It works because the angles of the lines are always on the first and fourth quadrant. The growth of the sine 

241:                 #in these quadrants is identical to the tangent growth.

242:                 

243:                 result = false

244:                 if other_line_descriptor.kind_of? LineDescriptor

245:                         dif_sine = (@sine-other_line_descriptor.sine)

246:                         abs_sine = dif_sine.abs

247:                         if (dif_sine < 0) && (abs_sine > Constants::EPSILON)

248:                                 result = true

249:                         elsif abs_sine < Constants::EPSILON

250:                                 dif_intercept =(@intercept-other_line_descriptor.intercept)

251:                                 abs_intercept = dif_intercept.abs

252:                                 if (dif_intercept < 0) && (abs_intercept > Constants::EPSILON)

253:                                         result = true

254:                                 end

255:                         end

256:                 end

257:                 return result

258: 

259:         end
==(other_line_descriptor) click to toggle source
other_line_descriptor

another LineDescriptor object

returns

true iff this LineDescriptor is equal than other_line_descriptor

     # File lib/geometry.rb, line 264
264:         def == (other_line_descriptor)

265:                 

266:                 result = false

267:                 if other_line_descriptor.kind_of? LineDescriptor

268:                         dif_sine = (@sine-other_line_descriptor.sine).abs

269:                         dif_intercept = (@intercept-other_line_descriptor.intercept).abs

270:                         result = ((dif_sine < Constants::EPSILON) && (dif_intercept < Constants::EPSILON))

271:                 end

272:                 return result

273:         end
clone() click to toggle source
returns

a new LineDescriptor, identical to this one

     # File lib/geometry.rb, line 276
276:         def clone()

277:                 return LineDescriptor.new(@sine, @intercept)

278:         end
hash() click to toggle source
returns

the hash code for this line_descriptor

     # File lib/geometry.rb, line 281
281:         def hash

282:                 return [@sine.hash, @intercept.hash].hash

283:         end
satisfied?(point) click to toggle source
point

an OrderedPoint

returns

true iff the point satisfies the line ecuation

     # File lib/geometry.rb, line 220
220:         def satisfied? (point)

221:                 result = false

222:                 

223:                 cosine = Math.sqrt(1-(@sine**2))

224:                 if cosine == 0 #Vertical

225:                         result = (point.x == @intercept)

226:                 elsif @sine == 0 #Horizontal

227:                         result = (point.y== @intercept)

228:                 else #General case

229:                         slope = @sine /cosine

230:                         result = (point.y == (point.x * slope + @intercept))

231:                 end

232:                 

233:                 return result

234:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.