Class: Sevgi::Geometry::LengthAngle

Inherits:
Data
  • Object
show all
Defined in:
lib/sevgi/geometry/segment.rb,
lib/sevgi/geometry/segment.rb

Overview

Immutable length/angle constraint used when a full segment is not implied.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length:, angle:) ⇒ void

Creates a target-measure constraint.

Parameters:

  • length (Numeric)

    finite non-negative target width or height

  • angle (Numeric)

    finite direction in degrees

Raises:



182
183
184
185
186
187
# File 'lib/sevgi/geometry/segment.rb', line 182

def initialize(length:, angle:)
  length = Real[:length, length]
  Error.("LengthAngle length cannot be negative") if length.negative?

  super(length:, angle: Real[:angle, angle])
end

Instance Attribute Details

#angleFloat (readonly)

Returns direction used to derive a segment.

Returns:

  • (Float)

    direction used to derive a segment



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/sevgi/geometry/segment.rb', line 176

LengthAngle = Data.define(:length, :angle) do
  # Creates a target-measure constraint.
  # @param length [Numeric] finite non-negative target width or height
  # @param angle [Numeric] finite direction in degrees
  # @return [void]
  # @raise [Sevgi::Geometry::Error] when a component is not finite or length is negative
  def initialize(length:, angle:)
    length = Real[:length, length]
    Error.("LengthAngle length cannot be negative") if length.negative?

    super(length:, angle: Real[:angle, angle])
  end
end

#lengthFloat (readonly)

Returns non-negative target measure.

Returns:

  • (Float)

    non-negative target measure



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/sevgi/geometry/segment.rb', line 176

LengthAngle = Data.define(:length, :angle) do
  # Creates a target-measure constraint.
  # @param length [Numeric] finite non-negative target width or height
  # @param angle [Numeric] finite direction in degrees
  # @return [void]
  # @raise [Sevgi::Geometry::Error] when a component is not finite or length is negative
  def initialize(length:, angle:)
    length = Real[:length, length]
    Error.("LengthAngle length cannot be negative") if length.negative?

    super(length:, angle: Real[:angle, angle])
  end
end

Class Method Details

.[](length, angle) ⇒ Sevgi::Geometry::LengthAngle

Creates a length-and-angle constraint.

Examples:

Create a constraint with mathematical notation

Sevgi::Geometry::LengthAngle[3, 90]

Parameters:

  • length (Numeric)

    finite non-negative target width or height

  • angle (Numeric)

    finite direction in degrees

Returns:

Raises:



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/sevgi/geometry/segment.rb', line 176

LengthAngle = Data.define(:length, :angle) do
  # Creates a target-measure constraint.
  # @param length [Numeric] finite non-negative target width or height
  # @param angle [Numeric] finite direction in degrees
  # @return [void]
  # @raise [Sevgi::Geometry::Error] when a component is not finite or length is negative
  def initialize(length:, angle:)
    length = Real[:length, length]
    Error.("LengthAngle length cannot be negative") if length.negative?

    super(length:, angle: Real[:angle, angle])
  end
end