pathoutlineprovider.cpp revision 32ab31c0b8c01f984760f9885f2e134617dab089
#include "pathoutlineprovider.h"
namespace Geom
{
/**
* Refer to: Weisstein, Eric W. "Circle-Circle Intersection."
From MathWorld--A Wolfram Web Resource.
*
* @return 0 if no intersection
* @return 1 if one circle is contained in the other
* @return 2 if intersections are found (they are written to p0 and p1)
*/
{
/* dx and dy are the vertical and horizontal distances between
* the circle centers.
*/
/* Determine the straight-line distance between the centers. */
double d = L2(D);
/* Check for solvability. */
{
/* no solution. circles do not intersect. */
return 0;
}
{
/* no solution. one circle is contained in the other */
return 1;
}
/* 'point 2' is the point where the line through the circle
* intersection points crosses the line between the circle
* centers.
*/
/* Determine the distance from point 0 to point 2. */
/* Determine the coordinates of point 2. */
/* Determine the distance from point 2 to either of the
* intersection points.
*/
/* Now determine the offsets of the intersection points from
* point 2.
*/
/* Determine the absolute intersection points. */
return 2;
}
/**
* Find circle that touches inside of the curve, with radius matching the curvature, at time value \c t.
* Because this method internally uses unitTangentAt, t should be smaller than 1.0 (see unitTangentAt).
*/
{
}
}
double curv = k(t); // note that this value is signed
}
{
{
}
return out;
}
{
}
static boost::optional<Geom::Point> intersection_point( Geom::Point const & origin_a, Geom::Point const & vector_a,
{
}
}
}
namespace Outline
{
{
using namespace Geom;
//cast it
if (cbc) return 3;
if (qbc) return 2;
if (lbc) return 1;
return 0;
}
//returns true if the angle formed by the curves and their handles
//is >180 clockwise, otherwise false.
{
//assert(cbc1.finalPoint() == cbc2.initialPoint());
return false;
}
switch (order)
{
case 3:
//major league b***f***ing
}
break;
case 2:
//this never happens
break;
case 1:
default:
}
switch (order)
{
case 3:
}
break;
case 2:
break;
case 1:
default:
}
//got our three points, now let's see what their clockwise angle is
//Much credit to Wikipedia for the following ( http://en.wikipedia.org/wiki/Graham_scan )
/********************************************************************
# Three points are a counter-clockwise turn if ccw > 0, clockwise if
# ccw < 0, and collinear if ccw = 0 because ccw is a determinant that
# gives the signed area of the triangle formed by p1, p2 and p3.
function ccw(p1, p2, p3):
return (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x)
*********************************************************************/
if (ccw > 0) return true;
return false;
}
void extrapolate_curves(Geom::Path& path_builder, Geom::Curve* cbc1, Geom::Curve* cbc2, Geom::Point endPt, double miter_limit, bool outside = false)
{
bool lineProblem = (dynamic_cast<Geom::BezierCurveN<1u> *>(cbc1)) || (dynamic_cast<Geom::BezierCurveN<1u> *>(cbc2));
if ( outside && !lineProblem ) {
if (solutions == 2) {
// points[0] is bad, choose points[1]
// points[1] is bad, choose points[0]
} else {
// both points are good, choose nearest
}
Geom::EllipticalArc *arc0 = circle1.arc(cbc1->finalPoint(), 0.5*(cbc1->finalPoint()+sol), sol, true);
if (arc0) {
delete arc0;
}
if (arc1) {
delete arc1;
}
} else {
if (p)
{
}
}
}
if ( outside && lineProblem ) {
if (p)
{
}
}
if ( !outside ) {
}
}
void reflect_curves(Geom::Path& path_builder, Geom::Curve* cbc1, Geom::Curve* cbc2, Geom::Point endPt, double miter_limit, bool outside = false)
{
//the most important work for the reflected join is done here
//determine where we are in the path. If we're on the inside, ignore
//and just lineTo. On the outside, we'll do a little reflection magic :)
if (outside) {
//reflect curves along the bevel
cbc1->finalPoint() );
cbc2->initialPoint() );
//curves didn't cross; default to miter
if (p)
{
}
//bevel
} else {
//join
//@TODO joins have a strange tendency to cross themselves twice. Check this.
//sections commented out are for general stability
path_builder.appendNew <Geom::CubicBezier> (sub1.first[1], sub1.first[2], /*sub1.first[3]*/ sub2.second[0] );
path_builder.appendNew <Geom::CubicBezier> (sub2.second[1], sub2.second[2], /*sub2.second[3]*/ endPt );
}
} else { // cross.empty()
//probably on the inside of the corner
}
}
/** @brief Converts a path to one half of an outline.
* path_in: The input path to use. (To create the other side use path_in.reverse() )
* line_width: the line width to use (usually you want to divide this by 2)
* miter_limit: the miter parameter
* extrapolate: whether the join should be extrapolated instead of reflected
*/
Geom::Path doAdvHalfOutline(const Geom::Path& path_in, double line_width, double miter_limit, bool extrapolate = false)
{
// NOTE: it is important to notice the distinction between a Geom::Path and a livarot Path here!
// if you do not see "Geom::" there is a different function set!
for (unsigned u = 0; u < k; u+=2)
{
to_outline = Path();
outlined_result = Path();
//now a curve has been outside outlined and loaded into outlined_result
//get the Geom::Path
//thing to do on the first run through
if (u == 0) {
//I could use the pv->operator[] (0) notation but that looks terrible
} else {
//get the curves ready for the operation
//do the reflection/extrapolation:
if (extrapolate) { extrapolate_curves(path_builder, cbc1, cbc2, (*path_vec)[0].initialPoint(), miter_limit,
}
//outline the next segment, but don't store it yet
if (u < k - 1) {
outlined_result = Path();
to_outline = Path();
//get the curves ready for the operation
//do the reflection/extrapolation:
if (extrapolate) { extrapolate_curves(path_builder, cbc1, cbc2, (*path_vec)[0].initialPoint(), miter_limit,
//Now we can store it.
}
}
return path_builder;
}
{
for (unsigned i = 0; i < pv_size; i++) {
//since you've made it this far, hopefully all this is obvious :P
//add in the...do I really need to say this?
//add in our line caps
switch (butt) {
case butt_straight:
break;
case butt_round:
break;
case butt_pointy:
//I have ZERO idea what to do here.
break;
case butt_square:
break;
}
} else {
}
//cap (if necessary)
switch (butt) {
case butt_straight:
break;
case butt_round:
break;
case butt_pointy:
//I have ZERO idea what to do here.
break;
case butt_square:
break;
}
}
}
} else {
//somewhat hack-ish
}
}
return path_out;
}
Geom::PathVector PathVectorOutline(Geom::PathVector const & path_in, double line_width, ButtType linecap_type,
{
return path_out;
}
}
//magic!
if (linejoin_type <= 2) {
//fix memory leak
delete pv_p;
} else if (linejoin_type == 3) {
//reflected arc join
linecap_type , miter_lim, false);
} else if (linejoin_type == 4) {
//extrapolated arc join
}
return path_out;
}
Geom::Path PathOutsideOutline(Geom::Path const & path_in, double line_width, LineJoinType linejoin_type, double miter_limit)
{
path_outline.OutsideOutline(&path_tangent, line_width / 2, static_cast<join_typ>(linejoin_type), butt_straight, miter_lim);
delete pathvec;
return path_out;
} else if (linejoin_type == LINEJOIN_REFLECTED) {
//reflected half outline
return path_out;
} else if (linejoin_type == LINEJOIN_EXTRAPOLATED) {
//what the hell do you think this is? :P
return path_out;
}
return path_out;
}
} // namespace Outline
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :