本文整理汇总了C++中Span类的典型用法代码示例。如果您正苦于以下问题:C++ Span类的具体用法?C++ Span怎么用?C++ Span使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Span类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tmps
/// Locate a span in the state.
/// \param s The span we are locating.
/// \return Those ItemTokens that the span comprises.
const ItemTokens State::locate_span(const Span& s) const {
Span tmps(_frontier);
assert(tmps.left() <= s.left());
assert(tmps.right() >= s.right());
ItemTokens is;
ItemTokens::const_iterator i;
for (i = _frontier.begin(); i != _frontier.end(); i++) {
if ((*i)->span().left() == s.left())
break;
assert((*i)->span().left() < s.left());
}
assert((*i)->span().left() == s.left());
for (; i != _frontier.end(); i++) {
is.push_back(*i);
if ((*i)->span().right() == s.right())
break;
assert((*i)->span().right() < s.right());
}
assert((*i)->span().right() == s.right());
assert(!is.empty());
return is;
}
示例2: ArcArcIntof
int ArcArcIntof(const Span& arc0, const Span& arc1, Point& pLeft, Point& pRight) {
// Intof 2 arcs
int numInts = Intof(Circle(arc0.pc, arc0.radius), Circle(arc1.pc, arc1.radius), pLeft, pRight);
if(numInts == 0) {
pLeft = arc0.p1;
pLeft.ok = false;
return 0;
}
int nLeft = arc0.OnSpan(pLeft) && arc1.OnSpan(pLeft);
int nRight = (numInts == 2)?arc0.OnSpan(pRight) && arc1.OnSpan(pRight) : 0;
if(nLeft == 0 && nRight) pLeft = pRight;
return nLeft + nRight;
}
示例3: testRuntimeSpan
void testRuntimeSpan(Span sp)
{
ASSERT_NOEXCEPT(std::as_bytes(sp));
auto spBytes = std::as_bytes(sp);
using SB = decltype(spBytes);
ASSERT_SAME_TYPE(const std::byte, typename SB::element_type);
if (sp.extent == std::dynamic_extent)
assert(spBytes.extent == std::dynamic_extent);
else
assert(spBytes.extent == sizeof(typename Span::element_type) * sp.extent);
assert((void *) spBytes.data() == (void *) sp.data());
assert(spBytes.size() == sp.size_bytes());
}
示例4: ParseFromStream
already_AddRefed<nsIDocument>
DOMParser::ParseFromBuffer(Span<const uint8_t> aBuf, SupportedType aType,
ErrorResult& aRv)
{
// The new stream holds a reference to the buffer
nsCOMPtr<nsIInputStream> stream;
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
reinterpret_cast<const char *>(aBuf.Elements()),
aBuf.Length(), NS_ASSIGNMENT_DEPEND);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
return ParseFromStream(stream, VoidString(), aBuf.Length(), aType, aRv);
}
示例5: SpanIntersections
void CArea::SpanIntersections(const Span& span, std::list<Point> &pts)const
{
// this returns all the intersections of this area with the given span, ordered along the span
// get all points where this area's curves intersect the span
std::list<Point> pts2;
for(std::list<CCurve>::const_iterator It = m_curves.begin(); It != m_curves.end(); It++)
{
const CCurve &c = *It;
c.SpanIntersections(span, pts2);
}
// order them along the span
std::multimap<double, Point> ordered_points;
for(std::list<Point>::iterator It = pts2.begin(); It != pts2.end(); It++)
{
Point &p = *It;
double t;
if(span.On(p, &t))
{
ordered_points.insert(std::make_pair(t, p));
}
}
// add them to the given list of points
for(std::multimap<double, Point>::iterator It = ordered_points.begin(); It != ordered_points.end(); It++)
{
Point p = It->second;
pts.push_back(p);
}
}
示例6: main
int main()
{
std::srand(time(0));
Span sp = Span(10000);
try
{
while (1)
sp.addNumber(rand());
}
catch(std::exception &e)
{
std::cout << e.what() << std::endl;
}
std::cout << sp.shortestSpan() << std::endl;
std::cout << sp.longestSpan() << std::endl;
}
示例7: testRuntimeSpan
void testRuntimeSpan(Span sp)
{
LIBCPP_ASSERT((noexcept(sp.template first<Count>())));
LIBCPP_ASSERT((noexcept(sp.first(Count))));
auto s1 = sp.template first<Count>();
auto s2 = sp.first(Count);
using S1 = decltype(s1);
using S2 = decltype(s2);
ASSERT_SAME_TYPE(typename Span::value_type, typename S1::value_type);
ASSERT_SAME_TYPE(typename Span::value_type, typename S2::value_type);
static_assert(S1::extent == Count, "");
static_assert(S2::extent == std::dynamic_extent, "");
assert(s1.data() == s2.data());
assert(s1.size() == s2.size());
assert(std::equal(s1.begin(), s1.end(), sp.begin()));
}
示例8: NearestPointToSpan
Point Span::NearestPointToSpan(const Span& p, double &d)const
{
Point midpoint = MidParam(0.5);
Point np = p.NearestPoint(m_p);
Point best_point = m_p;
double dist = np.dist(m_p);
if(p.m_start_span)dist -= (CArea::m_accuracy * 2); // give start of curve most priority
Point npm = p.NearestPoint(midpoint);
double dm = npm.dist(midpoint) - CArea::m_accuracy; // lie about midpoint distance to give midpoints priority
if(dm < dist){dist = dm; best_point = midpoint;}
Point np2 = p.NearestPoint(m_v.m_p);
double dp2 = np2.dist(m_v.m_p);
if(dp2 < dist){dist = dp2; best_point = m_v.m_p;}
d = dist;
return best_point;
}
示例9: DoesIntersInterfere
static bool DoesIntersInterfere(const Point& pInt, const Kurve& k, double offset) {
// check that intersections don't interfere with the original kurve
Span sp;
Point dummy;
int kCheckVertex = 0;
k.Get(kCheckVertex++, sp.p0, sp.pc);
offset = fabs(offset) - geoff_geometry::TOLERANCE;
while(kCheckVertex <= k.nSpans()) {
sp.dir = k.Get(kCheckVertex++, sp.p1, sp.pc);
sp.SetProperties(true);
// check for interference
if(Dist(sp, pInt, dummy) < offset) return true;
sp.p0 = sp.p1;
}
return false; // intersection is ok
}
示例10: testConstexprSpan
constexpr bool testConstexprSpan(Span sp)
{
LIBCPP_ASSERT((noexcept(sp.template subspan<Offset>())));
LIBCPP_ASSERT((noexcept(sp.subspan(Offset))));
auto s1 = sp.template subspan<Offset>();
auto s2 = sp.subspan(Offset);
using S1 = decltype(s1);
using S2 = decltype(s2);
ASSERT_SAME_TYPE(typename Span::value_type, typename S1::value_type);
ASSERT_SAME_TYPE(typename Span::value_type, typename S2::value_type);
static_assert(S1::extent == (Span::extent == std::dynamic_extent ? std::dynamic_extent : Span::extent - Offset), "");
static_assert(S2::extent == std::dynamic_extent, "");
return
s1.data() == s2.data()
&& s1.size() == s2.size()
&& std::equal(s1.begin(), s1.end(), sp.begin() + Offset, sp.end());
}
示例11: main
int main()
{
Span sp = Span(5);
Span sp1 = Span(10000);
Span sp2 = Span(10000);
Span sp3 = Span(10);
Span sp4 = Span(1);
srand(time(NULL));
sp.addNumber(5);
sp.addNumber(3);
sp.addNumber(17);
sp.addNumber(9);
sp.addNumber(11);
std::cout << sp.shortestSpan() << std::endl;
std::cout << sp.longestSpan() << std::endl;
sp1.RandInterval(9000);
std::cout << sp1.shortestSpan() << std::endl;
std::cout << sp1.longestSpan() << std::endl;
sp2.Interval(42, 9000);
std::cout << sp2.shortestSpan() << std::endl;
std::cout << sp2.longestSpan() << std::endl;
sp3.RandInterval(9000);
std::cout << sp3.shortestSpan() << std::endl;
std::cout << sp3.longestSpan() << std::endl;
sp4.addNumber(5);
sp4.addNumber(6);
std::cout << sp4.shortestSpan() << std::endl;
std::cout << sp4.longestSpan() << std::endl;
return (0);
}
示例12: main
int main()
{
srand(std::time(0));
try
{
Span sp = Span(5);
sp.addNumber(5);
sp.addNumber(3);
sp.addNumber(17);
sp.addNumber(9);
sp.addNumber(11);
std::cout << sp.shortestSpan() << std::endl;
std::cout << sp.longestSpan() << std::endl;
Span big(10000);
big.initAll(randNumber);
std::cout << big.shortestSpan() << std::endl;
std::cout << big.longestSpan() << std::endl;
Span sp2(1);
std::cout << sp2.shortestSpan() << std::endl;
}
catch (std::exception & e)
{
std::cout << e.what() << std::endl;
}
}
示例13: set_uri
void URI::set_uri(
uri_identifier_code_t id,
const Span<const uint8_t> &uri_field
)
{
delete[] _uri;
if (uri_field.empty()) {
_uri = NULL;
_uri_size = 0;
return;
}
_uri = new uint8_t[uri_id_code_size + uri_field.size()];
_uri_size = uri_id_code_size + uri_field.size();
_uri[uri_id_index] = id;
memcpy(_uri + uri_field_index, uri_field.data(), uri_field.size());
}
示例14: parseVar
static void parseVar (Lexer& lex, SigPtr sig)
{
std::string name;
TyPtr ty;
Span sp;
parseVar(lex, name, ty, sp);
for (auto& a : sig->args)
if (a.first == name)
{
std::ostringstream ss;
ss << "variable '" << name << "' already declared in signature";
throw sp.die(ss.str());
}
sig->args.push_back(Sig::Arg { name, ty });
sig->span = sig->span + sp;
}
示例15: getNextPixCenter
void TriRasterizer::drawSpansBetweenEdges(const Edge &longEdge, const Edge &shortEdge)
{
if(shortEdge.m_V1.m_Y == shortEdge.m_V2.m_Y) return; // horizontal edge, return
// snap current y-axis val to next pixel center
// using short edge as the reference top
float currY = getNextPixCenter(shortEdge.m_V1.m_Y);
float topY = shortEdge.m_V2.m_Y;
// get current colors
Color currLongColor;
Color currShortColor;
// get inverse slopes
float shortInvSlope = (shortEdge.m_V2.m_X == shortEdge.m_V1.m_X) ? 0.f :
(shortEdge.m_V2.m_X-shortEdge.m_V1.m_X)/(shortEdge.m_V2.m_Y-shortEdge.m_V1.m_Y);
float longInvSlope = (longEdge.m_V2.m_X == longEdge.m_V1.m_X) ? 0.f :
(longEdge.m_V2.m_X-longEdge.m_V1.m_X)/(longEdge.m_V2.m_Y-longEdge.m_V1.m_Y);
// get current x-axis vals
float currLongX = longEdge.m_V1.m_X + (currY-longEdge.m_V1.m_Y) * longInvSlope;
float currShortX = shortEdge.m_V1.m_X + (currY-shortEdge.m_V1.m_Y) * shortInvSlope;
// move along edges
Span span;
while (currY < topY)
{
// TODO: only calc interpolatants once
interpolateColor(currY, shortEdge.m_V1.m_Y, shortEdge.m_V2.m_Y,
shortEdge.m_V1.m_Color, shortEdge.m_V2.m_Color, currShortColor);
interpolateColor(currY, longEdge.m_V1.m_Y, longEdge.m_V2.m_Y,
longEdge.m_V1.m_Color, longEdge.m_V2.m_Color, currLongColor);
// set & draw span
span.setSpan(currShortColor, currLongColor, currShortX, currLongX, currY);
drawSpan(span);
currY += 1.f;
currShortX += shortInvSlope;
currLongX += longInvSlope;
}
}