summaryrefslogtreecommitdiffstats
path: root/src/livarot/int-line.h
blob: 576cfcff965a54fb81ab2e1c0c40dbdf7fb970df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * TODO: insert short description here
 *//*
 * Authors: see git history
 *
 * Copyright (C) 2018 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
#ifndef INKSCAPE_LIVAROT_INT_LINE_H
#define INKSCAPE_LIVAROT_INT_LINE_H

#include "livarot/LivarotDefs.h"
#include "object/object-set.h"   // For BooleanOp

/** \file
 * Coverage with integer boundaries.
 */

class BitLigne;
class FloatLigne;

/// A run with integer boundaries.
struct int_ligne_run {
    int st;
    int en;
    float vst;
    float ven;
};

/// Integer boundary.
struct int_ligne_bord {
    int pos;
    bool start;
    float val;
    int other;
    int prev;
    int next;
};

/**
 * Coverage with integer boundaries.
 *
 * This is what we want for actual rasterization. It contains the same 
 * stuff as FloatLigne, but technically only the Copy() functions are used.
 */
class IntLigne {
public:
    
    int nbBord;
    int maxBord;
    int_ligne_bord* bords;

    int nbRun;
    int maxRun;
    int_ligne_run* runs;

    int firstAc;
    int lastAc;

    IntLigne();
    virtual ~IntLigne();

    void Reset();
    int AddBord(int spos, float sval, int epos, float eval);

    void Flatten();

    void Affiche();

    int AddRun(int st, int en, float vst, float ven);

    void Booleen(IntLigne* a, IntLigne* b, BooleanOp mod);

    void Copy(IntLigne* a);
    void Copy(FloatLigne* a);
    void Copy(BitLigne* a);
    void Copy(int nbSub,BitLigne **a); 

    void Enqueue(int no);
    void Dequeue(int no);
    float RemainingValAt(int at);

    static int CmpBord(void const *p1, void const *p2) {
        int_ligne_bord const *d1 = reinterpret_cast<int_ligne_bord const *>(p1);
        int_ligne_bord const *d2 = reinterpret_cast<int_ligne_bord const *>(p2);
        
        if ( d1->pos == d2->pos ) {
            if ( d1->start && !(d2->start) ) {
                return 1;
            }
            if ( !(d1->start) && d2->start ) {
                return -1;
            }
            return 0;
        }
        return (( d1->pos < d2->pos ) ? -1 : 1);
    };

    inline float ValAt(int at, int ps, int pe, float vs, float ve) {
        return ((at - ps) * ve + (pe - at) * vs) / (pe - ps);
    };

    void Raster(raster_info &dest, void *color, RasterInRunFunc worker);
};


#endif

/*
  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:fileencoding=utf-8:textwidth=99 :