本文整理汇总了C++中Segment::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ Segment::contains方法的具体用法?C++ Segment::contains怎么用?C++ Segment::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Segment
的用法示例。
在下文中一共展示了Segment::contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: intersect
bool intersect(const Segment& s) const
{
auto d1 = D(A, B, s.A);
auto d2 = D(A, B, s.B);
if ((equals(d1, 0) && contains(s.A)) || (equals(d2, 0) && contains(s.B)))
return true;
auto d3 = D(s.A, s.B, A);
auto d4 = D(s.A, s.B, B);
if ((equals(d3, 0) && s.contains(A)) || (equals(d4, 0) && s.contains(B)))
return true;
return (d1 * d2 < 0) && (d3 * d4 < 0);
}
示例2: main
int main() {
int64_t n, x0, y0;
cin >> n >> x0 >> y0;
Point p = {x0, y0};
Segment ray = {p, {inf, y0 + 1}};
vector<Point> points(n);
for (int i = 0; i < n; i++) {
Point p;
cin >> p.x >> p.y;
points[i] = p;
}
int count = 0;
bool onBound = false;
for (int i = 0; i < n; i++) {
Segment s = {points[i], points[(i + 1) % n]};
if (s.contains(p)) {
onBound = true;
break;
}
if (ray.intersects(s)) {
count++;
}
}
cout << (onBound || count % 2 == 1 ? "YES" : "NO") << endl;
return 0;
}
示例3: ReplaceAt
bool HexDoc::ReplaceAt(uint64 ToReplaceIndex, uint32 ToReplaceLength, const uint8 *pReplaceWith, uint32 ReplaceWithLength)
{
if (!CanReplaceAt(ToReplaceIndex, ToReplaceLength, ReplaceWithLength))
return false;
if (ToReplaceLength > ReplaceWithLength)
{
//! is this a good idea?
RemoveAt(ToReplaceIndex + ReplaceWithLength, ToReplaceLength - ReplaceWithLength, SUPPRESS_UPDATE);
ToReplaceLength = ReplaceWithLength;
}
// Quick optimization:
// If affected range is entirely inside one writeable Segment and size doesn't change,
// just write data.
//! is this a good idea?
uint64 segmentStart;
Segment *ts = GetSegment(ToReplaceIndex, &segmentStart);
if (ts && ts->type == Segment::MEM && ToReplaceLength == ReplaceWithLength)
{
if (ts->contains(ToReplaceIndex, ToReplaceLength, segmentStart))
{
memcpy(&ts->pData[ToReplaceIndex - segmentStart], pReplaceWith, ToReplaceLength);
return true;
}
}
if (!RemoveAt(ToReplaceIndex, ToReplaceLength, SUPPRESS_UPDATE))
return false;
if (!InsertAt(ToReplaceIndex, pReplaceWith, ReplaceWithLength, 1, SUPPRESS_UPDATE))
return false;
/* THSIZE lengthDiff = (THSIZE)ToReplaceLength - (THSIZE)ReplaceWithLength; // overflow doesn't matter
for (size_t n = FindModified(ToReplaceIndex, true); n < modRanges.size(); n++)
{
ByteRange& tr = modRanges[n];
if (tr.start > ToReplaceIndex)
tr.start += lengthDiff;
tr.end += lengthDiff;
}*/
m_iChangeIndex++;
if (hw)
hw->OnDataChange(ToReplaceIndex, ToReplaceLength, ReplaceWithLength);
return true;
}
示例4: insertIntoSegment
static void insertIntoSegment(std::vector<Segment *> &seglist, size_t start,
size_t end, mtime_t time)
{
std::vector<Segment *>::iterator segIt;
for(segIt = seglist.begin(); segIt < seglist.end(); ++segIt)
{
Segment *segment = *segIt;
if(segment->getClassId() == Segment::CLASSID_SEGMENT &&
segment->contains(end + segment->getOffset()))
{
SubSegment *subsegment = new SubSegment(segment,
start + segment->getOffset(),
end + segment->getOffset());
segment->addSubSegment(subsegment);
segment->startTime.Set(time);
break;
}
}
}
示例5: RemoveAt
bool HexDoc::RemoveAt(uint64 nIndex, uint64 nSize, int flags /*= 0*/)
{
if (!(flags & SUPPRESS_UPDATE) && !CanReplaceAt(nIndex, nSize, 0))
return false;
m_curSeg = NULL;
if (nIndex == this->size)
return nSize == 0;
int n = FindSegment(nIndex), firstAffected = -1;
THSIZE base = bases[n];
const THSIZE removeSize = nSize; // nSize gets modified
while (nSize)
{
Segment* ts = segments[n];
if (ts->contains(nIndex - 1, base) && ts->contains(nIndex + nSize, base))
{ //---xxx---
n++;
Segment* ts2 = ts->RemoveMid(nIndex - base, nSize);
InsertSegment2(n, nIndex, ts2);
firstAffected = n + 1; // skip updating the newly inserted segment
break;
}
else if (ts->contains(nIndex - 1, base))
{ // ---xxx
nSize -= ts->size - (nIndex - base);
ts->RemoveRight(nIndex - base);
base += ts->size;
firstAffected = n;
n++;
}
else if (ts->contains(nIndex + nSize, base))
{ // xxx---
ts->RemoveLeft(nSize);
if (firstAffected == -1)
firstAffected = n + 1;
break;
}
else
{ // xxx
nSize -= ts->size;
delete ts;
RemoveSegment(n);
if (firstAffected == -1)
firstAffected = n;
}
}
m_iChangeIndex++;
if (hw && !(flags & SUPPRESS_UPDATE))
hw->OnDataChange(nIndex, removeSize, 0);
if (firstAffected == -1)
firstAffected = 0;
for (n = firstAffected; n < (int)bases.size(); n++)
bases[n] -= removeSize; //! this belongs somewhere else, or at least inside SUPPRESS_UPDATE check.
this->size -= removeSize;
return true;
}