Class: Sunniesnow::Tools::SvgPath::Arc

Inherits:
PathSegment show all
Includes:
Curve
Defined in:
lib/sscharter/tools/svg_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Curve

#at_length, #length

Methods inherited from PathSegment

#at_length, #length

Constructor Details

#initialize(begin_point, radius, rotation, large_arc, sweep_positive, end_point, segments: 8) ⇒ Arc

Returns a new instance of Arc.

Parameters:

  • begin_point (Vector2D)
  • radius (Vector2D)
  • rotation (Numeric)
  • large_arc (Boolean)
  • sweep_positive (Boolean)
  • end_point (Vector2D)
  • segments (Integer) (defaults to: 8)


268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/sscharter/tools/svg_path.rb', line 268

def initialize begin_point, radius, rotation, large_arc, sweep_positive, end_point, segments: 8
	@begin = begin_point
	@radius = radius
	@rotation = rotation
	@large_arc = large_arc
	@sweep_positive = sweep_positive
	@end = end_point
	raise GeometryError.new 'Radius must be positive' if @radius.x <= 0 || @radius.y <= 0
	raise GeometryError.new 'Cannot draw arc with same begin and end point' if @begin == @end
	solve_center
	make_segments segments
end

Instance Attribute Details

#beginVector2D (readonly)

Returns:



244
245
246
# File 'lib/sscharter/tools/svg_path.rb', line 244

def begin
  @begin
end

#endVector2D (readonly)

Returns:



259
260
261
# File 'lib/sscharter/tools/svg_path.rb', line 259

def end
  @end
end

#large_arcBoolean (readonly)

Returns:

  • (Boolean)


253
254
255
# File 'lib/sscharter/tools/svg_path.rb', line 253

def large_arc
  @large_arc
end

#radiusNumeric (readonly)

Returns:

  • (Numeric)


247
248
249
# File 'lib/sscharter/tools/svg_path.rb', line 247

def radius
  @radius
end

#rotationNumeric (readonly)

Returns:

  • (Numeric)


250
251
252
# File 'lib/sscharter/tools/svg_path.rb', line 250

def rotation
  @rotation
end

#sweep_positiveBoolean (readonly)

Returns:

  • (Boolean)


256
257
258
# File 'lib/sscharter/tools/svg_path.rb', line 256

def sweep_positive
  @sweep_positive
end

Instance Method Details

#at(t) ⇒ Vector2D

Parameters:

  • t (Float)

Returns:



283
284
285
# File 'lib/sscharter/tools/svg_path.rb', line 283

def at t
	@center + (Vector2D.from_polar(1, @angle1*(1-t) + @angle2*t) * @radius).rotate(@rotation)
end