Class: Sevgi::Geometry::Polygon

Inherits:
PolygonBase
  • Object
show all
Defined in:
lib/sevgi/geometry/elements/polygon.rb

Overview

Variable-size closed lined element with at least three vertices.

Examples:

Pair point notation with its English convenience

points = [[0, 0], [2, 0], [1, 1]]
segments = Sevgi::Geometry::Polygon.(*points).segments
Sevgi::Geometry::Polygon[*segments] == Sevgi::Geometry::Polygon.from_segments(*segments)
Sevgi::Geometry::Polygon.(*points) == Sevgi::Geometry::Polygon.from_points(*points)

Classify points against a closed boundary

polygon = Sevgi::Geometry::Polygon.([0, 0], [6, 0], [3, 4])
polygon.inside?([3, 2]) # => true
polygon.on?([3, 0])     # => true
polygon.outside?([7, 2]) # => true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](*segments, position: Origin) ⇒ Sevgi::Geometry::Polygon

Builds a polygon from boundary segments.

Parameters:

Returns:

Raises:



46
47
48
49
50
51
52
# File 'lib/sevgi/geometry/elements/polygon.rb', line 46

class Polygon < PolygonBase
  private

  def validate_geometry!
    Error.("Polygon requires at least three vertices") if points.size < 4
  end
end

.call(*points) ⇒ Sevgi::Geometry::Polygon

Builds a polygon from boundary points.

Parameters:

Returns:

Raises:



46
47
48
49
50
51
52
# File 'lib/sevgi/geometry/elements/polygon.rb', line 46

class Polygon < PolygonBase
  private

  def validate_geometry!
    Error.("Polygon requires at least three vertices") if points.size < 4
  end
end

.from_points(*points) ⇒ Sevgi::Geometry::Polygon

Builds a polygon from boundary points.

Parameters:

Returns:

Raises:



46
47
48
49
50
51
52
# File 'lib/sevgi/geometry/elements/polygon.rb', line 46

class Polygon < PolygonBase
  private

  def validate_geometry!
    Error.("Polygon requires at least three vertices") if points.size < 4
  end
end

.from_segments(*segments, position: Origin) ⇒ Sevgi::Geometry::Polygon

Builds a polygon from boundary segments.

Parameters:

Returns:

Raises:



46
47
48
49
50
51
52
# File 'lib/sevgi/geometry/elements/polygon.rb', line 46

class Polygon < PolygonBase
  private

  def validate_geometry!
    Error.("Polygon requires at least three vertices") if points.size < 4
  end
end

Instance Method Details

#perimeterFloat

Returns the closed path perimeter.

Returns:

  • (Float)


46
47
48
49
50
51
52
# File 'lib/sevgi/geometry/elements/polygon.rb', line 46

class Polygon < PolygonBase
  private

  def validate_geometry!
    Error.("Polygon requires at least three vertices") if points.size < 4
  end
end