Skip to content

Commit

Permalink
Add missing PathAdapter files
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Oct 28, 2024
1 parent 2e91503 commit d036c0b
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
63 changes: 63 additions & 0 deletions include/PathAdapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2024 Ultimaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef PATH_ADAPTER_H
#define PATH_ADAPTER_H

#include <stddef.h>

#include "geometry/Point2LL.h"
#include "utils/Coord_t.h"

namespace cura
{

/* Adapter class to allow extrusion-related functions to work with either an ExtrusionLine or a Polygon */
template<typename PathType>
class PathAdapter
{
public:
/*!
* \brief Base constructor
* \param path The actual stored path
* \param fixed_line_width The fixed line width in case the stored path doesn't handle information about a variable
* line width. Can be omitted otherwise.
*/
PathAdapter(const PathType& path, coord_t fixed_line_width = 0)
: path_(path)
, fixed_line_width_(fixed_line_width)
{
}

bool empty() const
{
return path_.empty();
}

size_t size() const
{
return path_.size();
}

coord_t length() const
{
return path_.length();
}

const Point2LL& pointAt(size_t index) const;

coord_t lineWidthAt(size_t index) const;

const PathType& getPath() const
{
return path_;
}

private:
const PathType& path_;
const coord_t fixed_line_width_;
};

} // namespace cura

#endif // PATH_ADAPTER_H
35 changes: 35 additions & 0 deletions src/PathAdapter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024 Ultimaker B.V.
// CuraEngine is released under the terms of the AGPLv3 or higher.

#include "PathAdapter.h"

#include "utils/ExtrusionLine.h"

namespace cura
{

template<>
const Point2LL& PathAdapter<ExtrusionLine>::pointAt(size_t index) const
{
return path_.junctions_.at(index).p_;
}

template<>
coord_t PathAdapter<ExtrusionLine>::lineWidthAt(size_t index) const
{
return path_.junctions_.at(index).w_;
}

template<>
const Point2LL& PathAdapter<Polygon>::pointAt(size_t index) const
{
return path_.at(index);
}

template<>
coord_t PathAdapter<Polygon>::lineWidthAt(size_t /*index*/) const
{
return fixed_line_width_;
}

} // namespace cura

0 comments on commit d036c0b

Please sign in to comment.