wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wPlot2D::LineEntity Class Reference

Entity representing a straight line segment with optional arrowhead. More...

#include <wLineEntity.hpp>

Inheritance diagram for wPlot2D::LineEntity:
Inheritance graph

Public Member Functions

 LineEntity (const sf::Vector2f &origin, const sf::Vector2f &scale, const sf::Vector2f &start, const sf::Vector2f &end, bool withArrow=false)
 Construct a line entity between two points.
virtual ~LineEntity ()=default
 Virtual destructor.
void setColor (sf::Color color)
 Sets the color of the line and arrowhead.
void setThickness (float thickness)
 Sets the thickness of the line.
float getThickness () const
 Returns the current thickness of the line.
void setLineStyle (wEngine::LineStyleComponent::LineStyle style)
 Sets the visual style of the line.
void setDashLength (float dashLength)
 Sets the dash length for dashed lines.
void setGapLength (float gapLength)
 Sets the gap length between dashes or dots.
sf::Vector2f getStartPoint () const
 Returns the starting point of the line.
sf::Vector2f getEndPoint () const
 Returns the ending point of the line.
bool hasArrow () const
 Checks if the line has an arrowhead.
float getArrowSize () const
 Returns the arrowhead size factor.
void setArrowSize (float arrowSize)
 Sets the arrowhead size factor.
void render (sf::RenderWindow &window)
 Renders the line (and optional arrowhead).
Public Member Functions inherited from wEngine::Entity
 Entity ()
virtual ~Entity ()
unsigned int getEntityID () const
 Returns the unique ID associated with this entity.
void clearComponents ()
 Removes all components currently attached to the entity.
template<typename T, typename... Args>
std::shared_ptr< T > addComponent (Args &&... args)
 Adds a new component of type T to the entity.
template<typename T>
void removeComponent ()
 Removes the component of type T from the entity.
template<typename T>
bool hasComponent () const noexcept
 Checks whether the entity has a component of type T.
template<typename T>
std::shared_ptr< T > getComponent () const
 Retrieves the component of type T attached to the entity.
template<typename T>
std::shared_ptr< T > requireComponent (const std::string &context="") const
 Retrieves the component of type T and throws if it's missing.
template<typename Interface>
std::shared_ptr< Interface > getInterfaceComponent () const
 Returns the first component that implements the specified interface.

Additional Inherited Members

Static Public Member Functions inherited from wEngine::Entity
static void resetEntityIDCounter ()
 Resets the global entity ID counter to zero.

Detailed Description

Entity representing a straight line segment with optional arrowhead.

This entity provides configurable line rendering within the plot area:

  • Supports Solid, Dashed, and Dotted styles (via LineStyleComponent).
  • Customizable color, thickness, dash length, and gap length.
  • Optional arrowhead at the end (useful for axes or vectors).

Coordinates are expressed in logical units and transformed by the entity’s origin and scale before being rendered.

See also
wEngine::LineDrawer for the rendering implementation
wEngine::LineStyleComponent for style configuration
Author
Wilfried Koch

Constructor & Destructor Documentation

◆ LineEntity()

wPlot2D::LineEntity::LineEntity ( const sf::Vector2f & origin,
const sf::Vector2f & scale,
const sf::Vector2f & start,
const sf::Vector2f & end,
bool withArrow = false )

Construct a line entity between two points.

Parameters
originOrigin of the plot (reference point).
scaleScaling factor to convert logical coordinates into pixels.
startLine starting point (logical coordinates).
endLine ending point (logical coordinates).
withArrowWhether to draw an arrowhead at the end.

◆ ~LineEntity()

virtual wPlot2D::LineEntity::~LineEntity ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ setColor()

void wPlot2D::LineEntity::setColor ( sf::Color color)

Sets the color of the line and arrowhead.

Parameters
colorNew color to apply.

◆ setThickness()

void wPlot2D::LineEntity::setThickness ( float thickness)

Sets the thickness of the line.

Parameters
thicknessThickness in pixels.

◆ getThickness()

float wPlot2D::LineEntity::getThickness ( ) const
nodiscard

Returns the current thickness of the line.

Returns
Thickness in pixels.

◆ setLineStyle()

void wPlot2D::LineEntity::setLineStyle ( wEngine::LineStyleComponent::LineStyle style)

Sets the visual style of the line.

Parameters
styleSolid, Dashed, or Dotted.

◆ setDashLength()

void wPlot2D::LineEntity::setDashLength ( float dashLength)

Sets the dash length for dashed lines.

Parameters
dashLengthLength of each dash in pixels.

◆ setGapLength()

void wPlot2D::LineEntity::setGapLength ( float gapLength)

Sets the gap length between dashes or dots.

Parameters
gapLengthLength of the gap in pixels.

◆ getStartPoint()

sf::Vector2f wPlot2D::LineEntity::getStartPoint ( ) const
nodiscard

Returns the starting point of the line.

Returns
Start point in logical coordinates.

◆ getEndPoint()

sf::Vector2f wPlot2D::LineEntity::getEndPoint ( ) const
nodiscard

Returns the ending point of the line.

Returns
End point in logical coordinates.

◆ hasArrow()

bool wPlot2D::LineEntity::hasArrow ( ) const
nodiscard

Checks if the line has an arrowhead.

Returns
True if an arrowhead is drawn, false otherwise.

◆ getArrowSize()

float wPlot2D::LineEntity::getArrowSize ( ) const
nodiscard

Returns the arrowhead size factor.

Returns
Arrow size relative to line thickness.

◆ setArrowSize()

void wPlot2D::LineEntity::setArrowSize ( float arrowSize)

Sets the arrowhead size factor.

Parameters
arrowSizeArrow size relative to line thickness.

◆ render()

void wPlot2D::LineEntity::render ( sf::RenderWindow & window)

Renders the line (and optional arrowhead).

Parameters
windowTarget render window.

The documentation for this class was generated from the following files: