Module: Geom2D

Defined in:
lib/geom2d.rb,
lib/geom2d/point.rb,
lib/geom2d/utils.rb,
lib/geom2d/polygon.rb,
lib/geom2d/segment.rb,
lib/geom2d/version.rb,
lib/geom2d/rectangle.rb,
lib/geom2d/algorithms.rb,
lib/geom2d/polygon_set.rb,
lib/geom2d/bounding_box.rb,
lib/geom2d/utils/sorted_list.rb,
lib/geom2d/algorithms/polygon_operation.rb

Overview

– geom2d - 2D Geometric Objects and Algorithms Copyright © 2018-2023 Thomas Leitner <[email protected]>

This software may be modified and distributed under the terms of the MIT license. See the LICENSE file for details. ++

Defined Under Namespace

Modules: Algorithms, Utils Classes: BoundingBox, Point, Polygon, PolygonSet, Rectangle, Segment

Constant Summary collapse

VERSION =

The version of Geom2D

'0.4.1'

Class Method Summary collapse

Class Method Details

.Point(x, y = nil) ⇒ Object

Creates a new Point object from the given coordinates.

See: Point.new



33
34
35
36
37
38
39
40
41
# File 'lib/geom2d.rb', line 33

def self.Point(x, y = nil)
  if x.kind_of?(Point)
    x
  elsif y
    Point.new(x, y)
  else
    Point.new(*x)
  end
end

.Polygon(*vertices) ⇒ Object

Creates a new Polygon object from the given vertices.

See: Polygon.new



60
61
62
# File 'lib/geom2d.rb', line 60

def self.Polygon(*vertices)
  Polygon.new(vertices)
end

.PolygonSet(*polygons) ⇒ Object

Creates a PolygonSet from the given array of Polygon instances.

See: PolygonSet.new



67
68
69
# File 'lib/geom2d.rb', line 67

def self.PolygonSet(*polygons)
  PolygonSet.new(polygons)
end

.Rectangle(x, y, width, height) ⇒ Object

Creates a Rectangle from the given bottom-left point (x, y) and the provided width and height.

See: Rectangle.new



75
76
77
# File 'lib/geom2d.rb', line 75

def self.Rectangle(x, y, width, height)
  Rectangle.new(x, y, width, height)
end

.Segment(start_point, end_point = nil, vector: nil) ⇒ Object

Creates a new Segment from start_point to end_point or, if vector is given, from start_point to start_point + vector.

See: Segment.new



47
48
49
50
51
52
53
54
55
# File 'lib/geom2d.rb', line 47

def self.Segment(start_point, end_point = nil, vector: nil)
  if end_point
    Segment.new(start_point, end_point)
  elsif vector
    Segment.new(start_point, start_point + vector)
  else
    raise ArgumentError, "Either end_point or a vector must be given"
  end
end