Class: When::Coordinates::Spatial::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/when_exe/spatial.rb

Overview

イベント管理用範囲オブジェクト

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first, last) ⇒ Range

イベント管理用範囲オブジェクトの生成

Parameters:



596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/when_exe/spatial.rb', line 596

def initialize(first, last)
  @first  = first.kind_of?(Range) ? first.first : first
  @last   = last.kind_of?(Range)  ? last.last   : last
  @west   = @first.long
  @south  = @first.lat
  @bottom = @first.alt
  @east   = @last.long
  @north  = @last.lat
  @top    = @last.alt
  @long   = ::Range.new(@west,   @east,  false)
  @lat    = ::Range.new(@south,  @north, false)
  @alt    = ::Range.new(@bottom, @top,   false)
end

Instance Attribute Details

#alt::Range (readonly)

上下の範囲

Returns:

  • (::Range)


535
536
537
# File 'lib/when_exe/spatial.rb', line 535

def alt
  @alt
end

#bottomNumeric (readonly)

下の境界

Returns:



493
494
495
# File 'lib/when_exe/spatial.rb', line 493

def bottom
  @bottom
end

#eastNumeric (readonly)

東の境界

Returns:



505
506
507
# File 'lib/when_exe/spatial.rb', line 505

def east
  @east
end

#firstWhen::Coordinates::Spatial (readonly)

西南下の境界



475
476
477
# File 'lib/when_exe/spatial.rb', line 475

def first
  @first
end

#lastWhen::Coordinates::Spatial (readonly)

東北上の境界



499
500
501
# File 'lib/when_exe/spatial.rb', line 499

def last
  @last
end

#lat::Range (readonly)

南北の範囲

Returns:

  • (::Range)


529
530
531
# File 'lib/when_exe/spatial.rb', line 529

def lat
  @lat
end

#long::Range (readonly)

東西の範囲

Returns:

  • (::Range)


523
524
525
# File 'lib/when_exe/spatial.rb', line 523

def long
  @long
end

#northNumeric (readonly)

北の境界

Returns:



511
512
513
# File 'lib/when_exe/spatial.rb', line 511

def north
  @north
end

#southNumeric (readonly)

南の境界

Returns:



487
488
489
# File 'lib/when_exe/spatial.rb', line 487

def south
  @south
end

#topNumeric (readonly)

上の境界

Returns:



517
518
519
# File 'lib/when_exe/spatial.rb', line 517

def top
  @top
end

#westNumeric (readonly)

西の境界

Returns:



481
482
483
# File 'lib/when_exe/spatial.rb', line 481

def west
  @west
end

Class Method Details

.[](name) ⇒ When::Coordinates::Spatial Also known as: _instance

地名を空間座標化する

Parameters:

  • name (String)

    地名または座標

Returns:



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/when_exe/spatial.rb', line 401

def [](name)
  source = name.strip
  case source
  when /\A(.+)\.\.(.+)\z/                       ; return self.new(_instance($1), _instance($2))
  when /\A([\d.]+)([SN])([\d.]+)([WE])([-+\d.]+)?\z/i ; lat,  sn, long, we, alt = $~[1..5]
  when /\A([\d.]+)([WE])([\d.]+)([SN])([-+\d.]+)?\z/i,
       /\A([-+\d.]+)(_)([-+\d.]+)(_)?([-+\d.]+)?\z/   ; long, we, lat,  sn, alt = $~[1..5]
  end
  locations =
    if long
      [[
        When::Coordinates.to_deg_225("#{long}#{we}", 'EW', 1),
        When::Coordinates.to_deg_225("#{lat }#{sn}", 'NS', 1),
        (alt || 0).to_f
      ]]
    else
      t = When::Coordinates::LocationTable
      keys = [source]
      keys.concat(name.names.values) if name.kind_of?(When::BasicTypes::M17n)
      keys_to_location(keys, t)
    end
  return locations unless locations.kind_of?(Array)
  locations = locations.map {|location|
    When::Coordinates::Spatial.new({'long'=>location[0], 'lat'=>location[1], 'alt'=>location[2], 'degree'=>1})
  }
  locations = locations.size > 1 ? self.new(*locations) : locations.first
  if t
    keys.each do |key|
      t[0][key] = locations
    end
  end
  locations
end

.[]=(name, locations) ⇒ Object

地名に空間座標を設定する

Parameters:



441
442
443
444
445
446
447
# File 'lib/when_exe/spatial.rb', line 441

def []=(name, locations)
  keys = [source]
  keys.concat(name.names.values) if name.kind_of?(When::BasicTypes::M17n)
  keys.each do |key|
    When::Coordinates::LocationTable[0][key] = locations
  end
end

Instance Method Details

#exclude_end?Boolean

終端を除外するか?(ダミー)

Returns:

  • (Boolean)

    false - 除外しない



549
550
551
# File 'lib/when_exe/spatial.rb', line 549

def exclude_end?
  false
end

#include?(target) ⇒ Boolean

指定オブジェクトが範囲内か?

Parameters:

  • target (Object)

    判定するオブジェクト

Returns:

  • (Boolean)

    true - 範囲内のオブジェクトあり, false - 範囲内のオブジェクトなし



559
560
561
562
563
564
565
566
567
568
569
# File 'lib/when_exe/spatial.rb', line 559

def include?(target)
  case target
  when When::Coordinates::Spatial
    @long.include?(target.long) && @lat.include?(target.lat) && @alt.include?(target.alt)
  when Range
    @long.include?(target.west) && @lat.include?(target.south) && @alt.include?(target.bottom) &&
    @long.include?(target.east) && @lat.include?(target.north) && @alt.include?(target.top)
  else
    false
  end
end

#is_complex?Boolean

範囲の重なりの判断が複雑になるか?(ダミー)

Returns:

  • (Boolean)

    false - 単純



541
542
543
# File 'lib/when_exe/spatial.rb', line 541

def is_complex?
  false
end

#is_overlaped?(range) ⇒ Boolean

範囲の重なりの判断

Parameters:

  • range (Range)

    確認対象の単純範囲オブジェクト

Returns:

  • (Boolean)

    true - 重なる, false - 重ならない



578
579
580
581
582
583
584
585
586
587
588
# File 'lib/when_exe/spatial.rb', line 578

def is_overlaped?(range)
  case target
  when When::Coordinates::Spatial
    @long.include?(target.long) && @lat.include?(target.lat) && @alt.include?(target.alt)
  when Range
    @west >= target.east && @north >= target.south && @top >= target.bottom &&
    @east <= target.west && @south <= target.north && @bottom <= target.top
  else
    false
  end
end