lib/mageo/segment.rb in mageo-0.0.1 vs lib/mageo/segment.rb in mageo-0.0.2

- old
+ new

@@ -1,32 +1,30 @@ #! /usr/bin/env ruby # coding: utf-8 -require "mageo/vector3d.rb" - # 線分を表すクラス。 -class Segment +class Mageo::Segment attr_reader :endpoints class InitializeError < Exception; end class TypeError < Exception; end # 端点を2つ渡す。 def initialize(vector0, vector1) - raise InitializeError if vector0.class != Vector3D - raise InitializeError if vector1.class != Vector3D + raise InitializeError if vector0.class != Mageo::Vector3D + raise InitializeError if vector1.class != Mageo::Vector3D raise InitializeError if vector0 == vector1 @endpoints = [vector0, vector1] end # position で与えられた点が線分の中にある点か? # tolerance = 0.0 では計算誤差のためにほとんど真とならない。 - # position は Vector3D クラスインスタンスでなければならない。 + # position は Mageo::Vector3D クラスインスタンスでなければならない。 def include?(position, tolerance) - raise TypeError if position.class != Vector3D + raise TypeError if position.class != Mageo::Vector3D vec_self = @endpoints[1] - @endpoints[0] vec_other = position - @endpoints[0] # 両端の点は計算誤差で失敗しやすいので true にしておく。 @@ -54,26 +52,26 @@ #return false if ( ex_product[2].abs > tolerance ) end # endpoints で取り出せる座標2つのうち、最初のものから最後のものへのベクトルを表す - # Vector3D クラスインスタンスを返す。 + # Mageo::Vector3D クラスインスタンスを返す。 def to_v3d return @endpoints[1] - @endpoints[0] end # 等価チェック。 # uniq できるようにするため。 def eql?(other) - raise TypeError if other.class != Segment + raise TypeError if other.class != Mageo::Segment @endpoints.each do |point| return false unless other.endpoints.include?(point) end return true end def ==(other) - raise TypeError if other.class != Segment + raise TypeError if other.class != Mageo::Segment @endpoints.size.times do |i| return false unless other.endpoints[i] == @endpoints[i] end return true end