#include "src/pathops/SkAddIntersections.h"
#include "include/core/SkPoint.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkDebug.h"
#include "src/pathops/SkIntersectionHelper.h"
#include "src/pathops/SkIntersections.h"
#include "src/pathops/SkOpCoincidence.h"
#include "src/pathops/SkOpContour.h"
#include "src/pathops/SkOpSegment.h"
#include "src/pathops/SkOpSpan.h"
#include "src/pathops/SkPathOpsBounds.h"
#include "src/pathops/SkPathOpsConic.h"
#include "src/pathops/SkPathOpsCubic.h"
#include "src/pathops/SkPathOpsPoint.h"
#include "src/pathops/SkPathOpsQuad.h"
#include "src/pathops/SkPathOpsTypes.h"
#include <cmath>
#include <utility>
#if DEBUG_ADD_INTERSECTING_TS
static void debugShowLineIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " LINE_DEBUG_STR " " LINE_DEBUG_STR "\n",
__FUNCTION__, LINE_DEBUG_DATA(wt.pts()), LINE_DEBUG_DATA(wn.pts()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " LINE_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], LINE_DEBUG_DATA(wt.pts()), PT_DEBUG_DATA(i, 0));
if (pts == 2) {
SkDebugf(" " T_DEBUG_STR(wtTs, 1) " " PT_DEBUG_STR, i[0][1], PT_DEBUG_DATA(i, 1));
}
SkDebugf(" wnTs[0]=%g " LINE_DEBUG_STR, i[1][0], LINE_DEBUG_DATA(wn.pts()));
if (pts == 2) {
SkDebugf(" " T_DEBUG_STR(wnTs, 1), i[1][1]);
}
SkDebugf("\n");
}
static void debugShowQuadLineIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn,
const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " QUAD_DEBUG_STR " " LINE_DEBUG_STR "\n",
__FUNCTION__, QUAD_DEBUG_DATA(wt.pts()), LINE_DEBUG_DATA(wn.pts()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " QUAD_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], QUAD_DEBUG_DATA(wt.pts()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " LINE_DEBUG_STR, i[1][0], LINE_DEBUG_DATA(wn.pts()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
static void debugShowQuadIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " QUAD_DEBUG_STR " " QUAD_DEBUG_STR "\n",
__FUNCTION__, QUAD_DEBUG_DATA(wt.pts()), QUAD_DEBUG_DATA(wn.pts()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " QUAD_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], QUAD_DEBUG_DATA(wt.pts()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " QUAD_DEBUG_STR, i[1][0], QUAD_DEBUG_DATA(wn.pts()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
static void debugShowConicLineIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " CONIC_DEBUG_STR " " LINE_DEBUG_STR "\n",
__FUNCTION__, CONIC_DEBUG_DATA(wt.pts(), wt.weight()), LINE_DEBUG_DATA(wn.pts()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " CONIC_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], CONIC_DEBUG_DATA(wt.pts(), wt.weight()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " LINE_DEBUG_STR, i[1][0], LINE_DEBUG_DATA(wn.pts()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
static void debugShowConicQuadIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " CONIC_DEBUG_STR " " QUAD_DEBUG_STR "\n",
__FUNCTION__, CONIC_DEBUG_DATA(wt.pts(), wt.weight()), QUAD_DEBUG_DATA(wn.pts()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " CONIC_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], CONIC_DEBUG_DATA(wt.pts(), wt.weight()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " QUAD_DEBUG_STR, i[1][0], QUAD_DEBUG_DATA(wn.pts()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
static void debugShowConicIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " CONIC_DEBUG_STR " " CONIC_DEBUG_STR "\n",
__FUNCTION__, CONIC_DEBUG_DATA(wt.pts(), wt.weight()),
CONIC_DEBUG_DATA(wn.pts(), wn.weight()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " CONIC_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], CONIC_DEBUG_DATA(wt.pts(), wt.weight()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " CONIC_DEBUG_STR, i[1][0], CONIC_DEBUG_DATA(wn.pts(), wn.weight()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
static void debugShowCubicLineIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " CUBIC_DEBUG_STR " " LINE_DEBUG_STR "\n",
__FUNCTION__, CUBIC_DEBUG_DATA(wt.pts()), LINE_DEBUG_DATA(wn.pts()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " CUBIC_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], CUBIC_DEBUG_DATA(wt.pts()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " LINE_DEBUG_STR, i[1][0], LINE_DEBUG_DATA(wn.pts()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
static void debugShowCubicQuadIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " CUBIC_DEBUG_STR " " QUAD_DEBUG_STR "\n",
__FUNCTION__, CUBIC_DEBUG_DATA(wt.pts()), QUAD_DEBUG_DATA(wn.pts()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " CUBIC_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], CUBIC_DEBUG_DATA(wt.pts()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " QUAD_DEBUG_STR, i[1][0], QUAD_DEBUG_DATA(wn.pts()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
static void debugShowCubicConicIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " CUBIC_DEBUG_STR " " CONIC_DEBUG_STR "\n",
__FUNCTION__, CUBIC_DEBUG_DATA(wt.pts()), CONIC_DEBUG_DATA(wn.pts(), wn.weight()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " CUBIC_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], CUBIC_DEBUG_DATA(wt.pts()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " CONIC_DEBUG_STR, i[1][0], CONIC_DEBUG_DATA(wn.pts(), wn.weight()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
static void debugShowCubicIntersection(int pts, const SkIntersectionHelper& wt,
const SkIntersectionHelper& wn, const SkIntersections& i) {
SkASSERT(i.used() == pts);
if (!pts) {
SkDebugf("%s no intersect " CUBIC_DEBUG_STR " " CUBIC_DEBUG_STR "\n",
__FUNCTION__, CUBIC_DEBUG_DATA(wt.pts()), CUBIC_DEBUG_DATA(wn.pts()));
return;
}
SkDebugf("%s " T_DEBUG_STR(wtTs, 0) " " CUBIC_DEBUG_STR " " PT_DEBUG_STR, __FUNCTION__,
i[0][0], CUBIC_DEBUG_DATA(wt.pts()), PT_DEBUG_DATA(i, 0));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wtTs) " " PT_DEBUG_STR, n, i[0][n], PT_DEBUG_DATA(i, n));
}
SkDebugf(" wnTs[0]=%g " CUBIC_DEBUG_STR, i[1][0], CUBIC_DEBUG_DATA(wn.pts()));
for (int n = 1; n < pts; ++n) {
SkDebugf(" " TX_DEBUG_STR(wnTs), n, i[1][n]);
}
SkDebugf("\n");
}
#else
static void debugShowLineIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowQuadLineIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowQuadIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowConicLineIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowConicQuadIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowConicIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowCubicLineIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowCubicQuadIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowCubicConicIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
static void debugShowCubicIntersection(int , const SkIntersectionHelper& ,
const SkIntersectionHelper& , const SkIntersections& ) { … }
#endif
bool AddIntersectTs(SkOpContour* test, SkOpContour* next, SkOpCoincidence* coincidence) { … }