MCPcopy Create free account
hub / github.com/WheretIB/nullc / CanvasDrawLineNoAA

Function CanvasDrawLineNoAA

NULLC/includes/canvas.cpp:133–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131 }
132
133 void CanvasDrawLineNoAA(int x0, int y0, int x1, int y1, Canvas* ptr)
134 {
135 if(!ptr)
136 {
137 nullcThrowError("ERROR: Canvas object is nullptr");
138 return;
139 }
140 bool steep = abs(y1 - y0) > abs(x1 - x0);
141 if(steep)
142 {
143 swap(x0, y0);
144 swap(x1, y1);
145 }
146 if(x0 > x1)
147 {
148 swap(x0, x1);
149 swap(y0, y1);
150 }
151 int deltax = x1 - x0;
152 int deltay = abs(y1 - y0);
153 int error = deltax / 2;
154 int ystep = y0 < y1 ? 1 : -1;
155 int y = y0;
156 if(x0 < 0)
157 {
158 double l = double(-x0) / (x1 - x0);
159 x0 = 0;
160 y = int(y0 * (1.0 - l) + y1 * l);
161 }
162 if(x0 > (steep ? ptr->height : ptr->width))
163 return;
164 if(x1 > (steep ? ptr->height : ptr->width))
165 x1 = steep ? ptr->height : ptr->width;
166 if(steep)
167 {
168 for(int x = x0; x <= x1; x++)
169 {
170 if((unsigned)y < (unsigned)ptr->width && (unsigned)x < (unsigned)ptr->height)
171 CanvasDrawPointInternal(y, x, 1.0, ptr);
172 error -= deltay;
173 if(error < 0)
174 {
175 y += ystep;
176 error += deltax;
177 }
178 }
179 }else{
180 for(int x = x0; x <= x1; x++)
181 {
182 if((unsigned)x < (unsigned)ptr->width && (unsigned)y < (unsigned)ptr->height)
183 CanvasDrawPointInternal(x, y, 1.0, ptr);
184 error -= deltay;
185 if(error < 0)
186 {
187 y += ystep;
188 error += deltax;
189 }
190 }

Callers 1

CanvasDrawLineFunction · 0.85

Calls 4

CanvasDrawPointInternalFunction · 0.85
absFunction · 0.70
swapFunction · 0.70
nullcThrowErrorFunction · 0.50

Tested by

no test coverage detected