Skip to content

Commit

Permalink
Merge pull request #35 from RegMeasures/end-shapes
Browse files Browse the repository at this point in the history
Flat end shape option
  • Loading branch information
mikemag authored Aug 20, 2016
2 parents ded90af + a879dc6 commit 75ecf7b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 9 deletions.
22 changes: 17 additions & 5 deletions cli/monkey-cam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,23 @@ namespace MonkeyCAM {
// @TODO: load more parts
std::unique_ptr<ShapeEndPart> loadEndPart(boost::property_tree::ptree& config) {
auto type = config.get<std::string>("type");
auto endHandle = config.get<double>("end handle");
auto transitionHandle = config.get<double>("transition handle");
assert(type == "Basic Bezier");
return std::unique_ptr<ShapeEndPart> {
new BasicBezier { endHandle, transitionHandle } };
assert(type == "Basic Bezier" || type == "Flat");
if (type == "Basic Bezier") {
auto endHandle = config.get<double>("end handle");
auto transitionHandle = config.get<double>("transition handle");


return std::unique_ptr<ShapeEndPart> {
new BasicBezier { endHandle, transitionHandle } };
}
else if (type == "Flat") {
auto flatWidth = config.get<double>("flat width");
auto endHandle = config.get<double>("end handle");
auto transitionHandle = config.get<double>("transition handle");

return std::unique_ptr<ShapeEndPart> {
new FlatBezier {flatWidth, endHandle, transitionHandle } };
}
}

// @TODO: load more parts
Expand Down
32 changes: 32 additions & 0 deletions core/shape-parts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,38 @@ const Path& BasicBezier::generate(Point endPoint, Point transitionPoint) {
return m_path;
}

const Path& FlatBezier::generate(Point endPoint, Point transitionPoint) {
MCFixed flatEndY = - m_flatWidth / 2;
// Note: flatEndY is negative because the 'bottom' half of the board is drawn
// first (i.e. in negative Y-space)
BOOST_ASSERT_MSG(flatEndY >= transitionPoint.Y,
"Error in generating \"Flat\" end: \"flat width\" is wider than nose/tail width");
if (endPoint.X < transitionPoint.X) {
// Nose
Path ep;
ep.push_back(endPoint);
m_path = BezierPath(Point(endPoint.X, flatEndY),
Point(endPoint.X, flatEndY +
(transitionPoint.Y - flatEndY) * m_endHandle),
Point(transitionPoint.X -
((transitionPoint.X - endPoint.X) *
m_transitionHandle), transitionPoint.Y),
transitionPoint);
ep.push_back_path(m_path);
m_path = ep;
} else {
// Tail
m_path = BezierPath(transitionPoint,
Point(transitionPoint.X +
((endPoint.X - transitionPoint.X) *
m_transitionHandle), transitionPoint.Y),
Point(endPoint.X, flatEndY +
(transitionPoint.Y - flatEndY) * m_endHandle),
Point(endPoint.X, flatEndY));
m_path.push_back(endPoint);
}
return m_path;
}
const Path& BasicArc::generate(Point nosePoint, Point waistPoint,
Point tailPoint) {
m_path = ArcPath { nosePoint, waistPoint, tailPoint, ArcPath::Clockwise };
Expand Down
15 changes: 15 additions & 0 deletions core/shape-parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ class BasicBezier : public ShapeEndPart {
double m_transitionHandle;
};

class FlatBezier : public ShapeEndPart {
public:
FlatBezier(double flatWidth, double endHandle, double transitionHandle)
: m_flatWidth(flatWidth)
, m_endHandle(endHandle)
, m_transitionHandle(transitionHandle)
{}

const Path& generate(Point endPoint, Point transitionPoint);

private:
double m_flatWidth;
double m_endHandle;
double m_transitionHandle;
};
//------------------------------------------------------------------------------
// Edge parts

Expand Down
7 changes: 4 additions & 3 deletions docs/Configuration_Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ of the nose.
}
```

The `type` may currently be only `"Basic Bezier"`, though other
options will be available in the future. This specifies a classic
The `type` may be `"Basic Bezier"` or `"Flat"`, other
options will be available in the future. `"Basic Bezier"` specifies a classic
Bezier curve with two control points for one half of the nose shape,
and this curve is mirrored to get the other half. The control points
and this curve is mirrored to get the other half. `"Flat"` is similar
but includes an additional flat section of specified width at the tip. The control points
are constrained to ensure that the Bezier curves join properly at the
nose and to the effective edge.

Expand Down
11 changes: 11 additions & 0 deletions example/RunMonkeyCamBoard.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

rem create directory to hold outputs
set OutputDir=..\Sample-output
mkdir %OutputDir%

rem call MonkeyCAM executable with relevant definition files
..\cli\MonkeyCAM.exe --board board-def.json --machine machine-tool-def.json --outdir %OutputDir%
pause

rem display overview html
%OutputDir%\Sample-snowboard-overview.html
11 changes: 11 additions & 0 deletions example/RunMonkeyCamSki.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

rem create directory to hold outputs
set OutputDir=..\Sample-output
mkdir %OutputDir%

rem call MonkeyCAM executable with relevant definition files
..\cli\MonkeyCAM.exe --board ski-def.json --machine machine-tool-def.json --outdir %OutputDir%
pause

rem display overview html
%OutputDir%\Sample-ski-overview.html
3 changes: 2 additions & 1 deletion example/ski-def.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"tail shape":
{
"type": "Basic Bezier",
"type": "Flat",
"flat width": 8.0,
"end handle": 0.50,
"transition handle": 0.75
},
Expand Down

0 comments on commit 75ecf7b

Please sign in to comment.