Krita Source Code Documentation
Loading...
Searching...
No Matches
KisLazyFillGraph::EdgeIndexBin Struct Reference

#include <kis_lazy_fill_graph.h>

Public Member Functions

bool contains (const edge_descriptor &edge) const
 
bool contains (edges_size_type index) const
 
edge_descriptor edgeAt (edges_size_type index) const
 
 EdgeIndexBin ()
 
 EdgeIndexBin (const EdgeIndexBin &putAfter, const QRect &_rect, EdgeIndexBinId _binId)
 
 EdgeIndexBin (edges_size_type _start, const QRect &_rect, EdgeIndexBinId _binId)
 
edges_size_type indexOf (const edge_descriptor &edge) const
 
edges_size_type last () const
 

Public Attributes

EdgeIndexBinId binId {HORIZONTAL}
 
bool isReversed {false}
 
QRect rect
 
edges_size_type size {0}
 
edges_size_type start {0}
 
edges_size_type stride {0}
 
edges_size_type xOffset {0}
 
edges_size_type yOffset {0}
 

Detailed Description

Definition at line 410 of file kis_lazy_fill_graph.h.

Constructor & Destructor Documentation

◆ EdgeIndexBin() [1/3]

KisLazyFillGraph::EdgeIndexBin::EdgeIndexBin ( )
inline

Definition at line 411 of file kis_lazy_fill_graph.h.

◆ EdgeIndexBin() [2/3]

KisLazyFillGraph::EdgeIndexBin::EdgeIndexBin ( edges_size_type _start,
const QRect & _rect,
EdgeIndexBinId _binId )
inline

Definition at line 414 of file kis_lazy_fill_graph.h.

417 : start(_start),
418 stride(_rect.width()),
419 size(_rect.width() * _rect.height()),
420 xOffset(_rect.x()),
421 yOffset(_rect.y()),
422 binId(_binId),
423 isReversed(int(_binId) & 0x1),
424 rect(_rect) {}

◆ EdgeIndexBin() [3/3]

KisLazyFillGraph::EdgeIndexBin::EdgeIndexBin ( const EdgeIndexBin & putAfter,
const QRect & _rect,
EdgeIndexBinId _binId )
inline

Definition at line 426 of file kis_lazy_fill_graph.h.

429 : start(putAfter.last() + 1),
430 stride(_rect.width()),
431 size(_rect.width() * _rect.height()),
432 xOffset(_rect.x()),
433 yOffset(_rect.y()),
434 binId(_binId),
435 isReversed(int(_binId) & 0x1),
436 rect(_rect) {}

Member Function Documentation

◆ contains() [1/2]

bool KisLazyFillGraph::EdgeIndexBin::contains ( const edge_descriptor & edge) const
inline

Definition at line 447 of file kis_lazy_fill_graph.h.

447 {
448 return indexOf(edge) >= 0;
449 }
friend std::pair< typename type::edge_descriptor, bool > edge(typename type::vertex_descriptor source_vertex, typename type::vertex_descriptor destination_vertex, const type &graph)
edges_size_type indexOf(const edge_descriptor &edge) const

References KisLazyFillGraph::edge, and indexOf().

◆ contains() [2/2]

bool KisLazyFillGraph::EdgeIndexBin::contains ( edges_size_type index) const
inline

Definition at line 442 of file kis_lazy_fill_graph.h.

442 {
443 index -= start;
444 return index >= 0 && index < size;
445 }

References size, and start.

◆ edgeAt()

edge_descriptor KisLazyFillGraph::EdgeIndexBin::edgeAt ( edges_size_type index) const
inline

Definition at line 522 of file kis_lazy_fill_graph.h.

522 {
523 edges_size_type localOffset = index - start;
524
525 if (localOffset < 0 || localOffset >= size) {
526 return edge_descriptor();
527 }
528
529 const edges_size_type x = localOffset % stride + xOffset;
530 const edges_size_type y = localOffset / stride + yOffset;
531
533 vertex_descriptor dst_vertex;
534
535 switch (binId) {
536 case HORIZONTAL:
538 dst_vertex.x = x + 1;
539 dst_vertex.y = y;
540 dst_vertex.type = vertex_descriptor::NORMAL;
541 break;
542 case VERTICAL:
544 dst_vertex.x = x;
545 dst_vertex.y = y + 1;
546 dst_vertex.type = vertex_descriptor::NORMAL;
547 break;
548 case LABEL_A:
549 case LABEL_A_REVERSED:
550 dst_vertex.type = vertex_descriptor::LABEL_A;
551 break;
552 case LABEL_B:
553 case LABEL_B_REVERSED:
554 dst_vertex.type = vertex_descriptor::LABEL_B;
555 break;
556 }
557
558 if (isReversed) {
559 std::swap(src_vertex, dst_vertex);
560 }
561
562 return std::make_pair(src_vertex, dst_vertex);
563 }
VertexDescriptor vertex_descriptor
std::pair< vertex_descriptor, vertex_descriptor > edge_descriptor

References binId, KisLazyFillGraph::HORIZONTAL, KisLazyFillGraph::HORIZONTAL_REVERSED, isReversed, KisLazyFillGraph::VertexDescriptor::LABEL_A, KisLazyFillGraph::LABEL_A, KisLazyFillGraph::LABEL_A_REVERSED, KisLazyFillGraph::VertexDescriptor::LABEL_B, KisLazyFillGraph::LABEL_B, KisLazyFillGraph::LABEL_B_REVERSED, KisLazyFillGraph::VertexDescriptor::NORMAL, size, start, stride, KisLazyFillGraph::VertexDescriptor::type, KisLazyFillGraph::VERTICAL, KisLazyFillGraph::VERTICAL_REVERSED, KisLazyFillGraph::VertexDescriptor::x, xOffset, KisLazyFillGraph::VertexDescriptor::y, and yOffset.

◆ indexOf()

edges_size_type KisLazyFillGraph::EdgeIndexBin::indexOf ( const edge_descriptor & edge) const
inline

Definition at line 451 of file kis_lazy_fill_graph.h.

451 {
452 vertex_descriptor src_vertex = source(edge, *this);
453 vertex_descriptor dst_vertex = target(edge, *this);
454
455 const bool srcColoredA = src_vertex.type == vertex_descriptor::LABEL_A;
456 const bool dstColoredA = dst_vertex.type == vertex_descriptor::LABEL_A;
457 const bool srcColoredB = src_vertex.type == vertex_descriptor::LABEL_B;
458 const bool dstColoredB = dst_vertex.type == vertex_descriptor::LABEL_B;
459
460 if (srcColoredA || dstColoredA) {
461 const bool edgeReversed = srcColoredA;
462
463 if (isReversed != edgeReversed ||
464 (binId != LABEL_A && binId != LABEL_A_REVERSED) ||
465 (srcColoredA && (dst_vertex.type != vertex_descriptor::NORMAL)) ||
466 (dstColoredA && (src_vertex.type != vertex_descriptor::NORMAL))) {
467
468 return -1;
469 }
470 } else if (srcColoredB || dstColoredB) {
471 const bool edgeReversed = srcColoredB;
472
473 if (isReversed != edgeReversed ||
474 (binId != LABEL_B && binId != LABEL_B_REVERSED) ||
475 (srcColoredB && (dst_vertex.type != vertex_descriptor::NORMAL)) ||
476 (dstColoredB && (src_vertex.type != vertex_descriptor::NORMAL))) {
477
478 return -1;
479 }
480 } else {
481 const vertices_size_type xDiff = dst_vertex.x - src_vertex.x;
482 const vertices_size_type yDiff = dst_vertex.y - src_vertex.y;
483 const vertices_size_type xAbsDiff = qAbs(xDiff);
484 const vertices_size_type yAbsDiff = qAbs(yDiff);
485 const bool edgeReversed = xDiff < 0 || yDiff < 0;
486
487 if (isReversed != edgeReversed ||
488 (xDiff && binId != HORIZONTAL && binId != HORIZONTAL_REVERSED) ||
489 (yDiff && binId != VERTICAL && binId != VERTICAL_REVERSED) ||
490 xAbsDiff > 1 ||
491 yAbsDiff > 1 ||
492 xAbsDiff == yAbsDiff) {
493
494 return -1;
495 }
496 }
497
498 if (isReversed) {
499 std::swap(src_vertex, dst_vertex);
500 }
501
502 // using direct QRect::contains makes the code 30% slower
503 const int x = src_vertex.x;
504 const int y = src_vertex.y;
505 if (x < rect.x() || x > rect.right() ||
506 y < rect.y() || y > rect.bottom()) {
507 return -1;
508 }
509
510 edges_size_type internalIndex =
511 (src_vertex.x - xOffset) +
512 (src_vertex.y - yOffset) * stride;
513
514 LF_SANITY_ASSERT_RECOVER(internalIndex >= 0 && internalIndex < size) {
515 return -1;
516 }
517
518 return internalIndex + start;
519 }
KisMagneticGraph::vertex_descriptor target(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
VertexIndex vertices_size_type
#define LF_SANITY_ASSERT_RECOVER(x)

References binId, KisLazyFillGraph::edge, KisLazyFillGraph::HORIZONTAL, KisLazyFillGraph::HORIZONTAL_REVERSED, isReversed, KisLazyFillGraph::VertexDescriptor::LABEL_A, KisLazyFillGraph::LABEL_A, KisLazyFillGraph::LABEL_A_REVERSED, KisLazyFillGraph::VertexDescriptor::LABEL_B, KisLazyFillGraph::LABEL_B, KisLazyFillGraph::LABEL_B_REVERSED, LF_SANITY_ASSERT_RECOVER, KisLazyFillGraph::VertexDescriptor::NORMAL, size, source(), start, stride, target(), KisLazyFillGraph::VertexDescriptor::type, KisLazyFillGraph::VERTICAL, KisLazyFillGraph::VERTICAL_REVERSED, KisLazyFillGraph::VertexDescriptor::x, xOffset, KisLazyFillGraph::VertexDescriptor::y, and yOffset.

◆ last()

edges_size_type KisLazyFillGraph::EdgeIndexBin::last ( ) const
inline

Definition at line 438 of file kis_lazy_fill_graph.h.

438 {
439 return start + size - 1;
440 }

References size, and start.

Member Data Documentation

◆ binId

EdgeIndexBinId KisLazyFillGraph::EdgeIndexBin::binId {HORIZONTAL}

Definition at line 570 of file kis_lazy_fill_graph.h.

570{HORIZONTAL};

◆ isReversed

bool KisLazyFillGraph::EdgeIndexBin::isReversed {false}

Definition at line 571 of file kis_lazy_fill_graph.h.

571{false};

◆ rect

QRect KisLazyFillGraph::EdgeIndexBin::rect

Definition at line 572 of file kis_lazy_fill_graph.h.

◆ size

edges_size_type KisLazyFillGraph::EdgeIndexBin::size {0}

Definition at line 567 of file kis_lazy_fill_graph.h.

567{0};

◆ start

edges_size_type KisLazyFillGraph::EdgeIndexBin::start {0}

Definition at line 565 of file kis_lazy_fill_graph.h.

565{0};

◆ stride

edges_size_type KisLazyFillGraph::EdgeIndexBin::stride {0}

Definition at line 566 of file kis_lazy_fill_graph.h.

566{0};

◆ xOffset

edges_size_type KisLazyFillGraph::EdgeIndexBin::xOffset {0}

Definition at line 568 of file kis_lazy_fill_graph.h.

568{0};

◆ yOffset

edges_size_type KisLazyFillGraph::EdgeIndexBin::yOffset {0}

Definition at line 569 of file kis_lazy_fill_graph.h.

569{0};

The documentation for this struct was generated from the following file: