Skip to content

Commit

Permalink
pre release review
Browse files Browse the repository at this point in the history
  • Loading branch information
stribor14 committed Mar 31, 2020
1 parent 52e5ba3 commit d2ef445
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 187 deletions.
36 changes: 18 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.1)
project(BezierCpp
project(Bezier
LANGUAGES CXX
VERSION 0.2.0)

Expand All @@ -8,16 +8,16 @@ add_compile_options(-std=c++11 -march=native -fPIC)
find_package(Eigen3 REQUIRED)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})

set(BezierCpp_SRC
set(Bezier_SRC
src/bezier.cpp
src/polycurve.cpp
)

set(BezierCpp_INC
include/BezierCpp/declarations.h
include/BezierCpp/legendre_gauss.h
include/BezierCpp/bezier.h
include/BezierCpp/polycurve.h
set(Bezier_INC
include/Bezier/declarations.h
include/Bezier/legendre_gauss.h
include/Bezier/bezier.h
include/Bezier/polycurve.h
)

# Options
Expand All @@ -32,23 +32,23 @@ option(BUILD_SHARED_LIBS "Build shared library (.so) instead of static one (/.a)
# build rules

if(BUILD_SHARED_LIBS)
add_library(BezierCpp SHARED ${BezierCpp_SRC})
add_library(bezier SHARED ${Bezier_SRC})
else()
add_library(BezierCpp STATIC ${BezierCpp_SRC})
add_library(bezier STATIC ${Bezier_SRC})
endif()

target_include_directories(BezierCpp PUBLIC
$<BUILD_INTERFACE:${BezierCpp_SOURCE_DIR}/include>
target_include_directories(bezier PUBLIC
$<BUILD_INTERFACE:${Bezier_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_compile_definitions(BezierCpp PRIVATE LEGENDRE_GAUSS_N=${LEGENDRE_GAUSS_PRECISION})
target_compile_definitions(bezier PRIVATE LEGENDRE_GAUSS_N=${LEGENDRE_GAUSS_PRECISION})

set_target_properties(BezierCpp PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(BezierCpp PROPERTIES PUBLIC_HEADER "${BezierCpp_INC}")
set_target_properties(bezier PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(bezier PROPERTIES PUBLIC_HEADER "${Bezier_INC}")

# install rules
install(TARGETS BezierCpp
EXPORT BezierCpp-export DESTINATION "lib"
PUBLIC_HEADER DESTINATION "include/BezierCpp")
install(EXPORT BezierCpp-export DESTINATION "lib/cmake/BezierCpp" FILE BezierCppConfig.cmake)
install(TARGETS bezier
EXPORT bezier-export DESTINATION "lib"
PUBLIC_HEADER DESTINATION "include/Bezier")
install(EXPORT bezier-export DESTINATION "lib/cmake/Bezier" FILE BezierConfig.cmake)
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bezier-Cpp
[![Build Status](https://travis-ci.com/stribor14/Bezier-cpp.svg?branch=master)](https://travis-ci.com/stribor14/Bezier-cpp)
![v0.2.0](https://img.shields.io/badge/version-0.2.0-blue.svg)
![v0.2](https://img.shields.io/badge/version-0.2-blue.svg)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/aceb46ce7de1407abd56cfc127dba5f1)](https://www.codacy.com/app/stribor14/Bezier-cpp?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=stribor14/Bezier-cpp&amp;utm_campaign=Badge_Grade)

Fast and lightweight class for using the Bezier curves of any order in C++
Expand All @@ -13,6 +13,12 @@ Fast and lightweight class for using the Bezier curves of any order in C++
- Dynamic manipulation
- Composite Bezier curves (polycurves)

CMake *find_package()* compatible!
```
find_package(Bezier)
target_link_libraries(target bezier)
```

## Implemented methods
- Get value, derivative, curvature, tangent and normal for parameter *t*
- Get t from projection any point onto a curve
Expand All @@ -25,28 +31,22 @@ Fast and lightweight class for using the Bezier curves of any order in C++
- Apply parametric and geometric continuities
- etc.

## In development
- <img src="https://img.shields.io/badge/v.0.2.1-planned-yellow.svg" alt="v0.2.1 indev" align="top"> Bezier polycurves
## Wish list
- [ ] Polycurve - oversee continuities between consecutive sub-curves
- [ ] Polycurve - propagation of sub-curve manipulation depending on continutiy
- [ ] Bezier shapes
- [ ] More sophisticated example
- <img src="https://img.shields.io/badge/v.0.3-planned-red.svg" alt="v0.3 planned" align="top"> Bezier shapes

## Dependencies
- c++11
- Eigen3

## Instalation
CMake *find_package()* compatible!
```
find_package(BezierCpp)
target_link_libraries(target BezierCpp)
```
### System-wide installation
```
git clone https://github.com/stribor14/Bezier-cpp
mkdir Bezicer-cpp/build
cd Bezicer-cpp/build
mkdir Bezier-cpp/build
cd Bezier-cpp/build
cmake ..
make
make install
Expand Down
8 changes: 4 additions & 4 deletions example/bezier_example.pro
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ HEADERS += \
customscene.h \
qcurve.h \
qpolycurve.h \
../include/BezierCpp/bezier.h \
../include/BezierCpp/polycurve.h \
../include/BezierCpp/declarations.h \
../include/BezierCpp/legendre_gauss.h \
../include/Bezier/bezier.h \
../include/Bezier/polycurve.h \
../include/Bezier/declarations.h \
../include/Bezier/legendre_gauss.h \

FORMS += \
mainwindow.ui
Expand Down
4 changes: 2 additions & 2 deletions example/customscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void CustomScene::drawForeground(QPainter* painter, const QRectF& rect)
painter->setPen(Qt::blue);
for (auto&& curve : items())
{
Bezier::BBox bbox;
Bezier::BoundingBox bbox;
if (is_curve)
bbox = c_curve->boundingBox(true);
if (is_poly)
Expand Down Expand Up @@ -359,7 +359,7 @@ Delete - delete curve/polycurve");
for (auto&& curve : selectedItems())
if (is_curve)
{
Bezier::CurvePtr ptr(c_curve);
std::shared_ptr<Bezier::Curve> ptr(c_curve);
if (new_poly)
new_poly->insertBack(ptr);
else
Expand Down
6 changes: 3 additions & 3 deletions example/qcurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <QGraphicsItem>

#include "BezierCpp/declarations.h"
#include "BezierCpp/bezier.h"
#include "Bezier/declarations.h"
#include "Bezier/bezier.h"

class qCurve : public QGraphicsItem, public Bezier::Curve
{
Expand All @@ -27,7 +27,7 @@ class qCurve : public QGraphicsItem, public Bezier::Curve
void setDraw_curvature_radious(bool value);
bool getDraw_control_points() const;
bool getDraw_curvature_radious() const;
Bezier::CurvePtr getSharedPtr();
std::shared_ptr<Bezier::Curve> getSharedPtr();
bool getLocked() const;
void setLocked(bool value);
};
Expand Down
26 changes: 3 additions & 23 deletions example/qpolycurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <QPainter>
#include <QPen>

#include "BezierCpp/bezier.h"
#include "Bezier/bezier.h"

bool qPolyCurve::getDraw_control_points() const { return draw_control_points; }

Expand All @@ -15,26 +15,6 @@ void qPolyCurve::setDraw_curvature_radious(bool value) { draw_curvature_radious

int qPolyCurve::type() const { return QGraphicsItem::UserType + 2; }

inline double kappaDerived(qPolyCurve* pcurve, double t)
{
auto det = [](Bezier::Vec2 a, Bezier::Vec2 b) { return a.x() * b.y() - a.y() * b.x(); };

uint idx = t;
t = t - idx;
if (idx == pcurve->size())
{
idx--;
t = 1;
}
auto curve = pcurve->curvePtr(idx);

auto d1 = curve->derivativeAt(t);
auto d2 = curve->derivativeAt(2, t);
auto d3 = curve->derivativeAt(3, t);

return (det(d1, d3) * d1.squaredNorm() - 3 * d1.dot(d2) * det(d1, d2)) / std::pow(d1.norm(), 5);
}

void qPolyCurve::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(option)
Expand Down Expand Up @@ -78,8 +58,8 @@ void qPolyCurve::paint(QPainter* painter, const QStyleOptionGraphicsItem* option
painter->setPen(QColor(static_cast<int>(std::fabs(255 * (0.5 - t / size()))),
static_cast<int>(255 * t / size()), static_cast<int>(255 * (1 - t / size()))));
auto p = valueAt(t);
auto n1 = p + normalAt(t, false) * kappaDerived(this, t);
auto n2 = p - normalAt(t, false) * kappaDerived(this, t);
auto n1 = p + normalAt(t, false) * curvatureDerivativeAt(t);
auto n2 = p - normalAt(t, false) * curvatureDerivativeAt(t);
painter->drawLine(QLineF(n1.x(), n1.y(), n2.x(), n2.y()));
}
}
Expand Down
8 changes: 4 additions & 4 deletions example/qpolycurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

#include <QGraphicsItem>

#include "BezierCpp/declarations.h"
#include "BezierCpp/polycurve.h"
#include "Bezier/declarations.h"
#include "Bezier/polycurve.h"

class qPolyCurve : public QGraphicsItem, public Bezier::PolyCurve
{
private:
bool draw_control_points = false;
bool draw_curvature_radious = false;
public:
qPolyCurve(std::vector<Bezier::CurvePtr>& curve_list) : QGraphicsItem(), Bezier::PolyCurve(curve_list) {}
qPolyCurve(Bezier::CurvePtr& curve) : QGraphicsItem(), Bezier::PolyCurve(curve) {}
qPolyCurve(std::vector<std::shared_ptr<Bezier::Curve>>& curve_list) : QGraphicsItem(), Bezier::PolyCurve(curve_list) {}
qPolyCurve(std::shared_ptr<Bezier::Curve>& curve) : QGraphicsItem(), Bezier::PolyCurve(curve) {}
int type() const Q_DECL_OVERRIDE;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) Q_DECL_OVERRIDE;
QRectF boundingRect() const Q_DECL_OVERRIDE;
Expand Down
Loading

0 comments on commit d2ef445

Please sign in to comment.