aboutsummaryrefslogtreecommitdiffstats
path: root/lib/percept/src/egd_render.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/percept/src/egd_render.erl')
-rw-r--r--lib/percept/src/egd_render.erl67
1 files changed, 65 insertions, 2 deletions
diff --git a/lib/percept/src/egd_render.erl b/lib/percept/src/egd_render.erl
index 05059b526e..a97bb05cac 100644
--- a/lib/percept/src/egd_render.erl
+++ b/lib/percept/src/egd_render.erl
@@ -27,6 +27,9 @@
-export([eps/1]).
-compile(inline).
+-export([line_to_linespans/3]).
+-export([line_ls/2]).
+
-include("egd.hrl").
-define('DummyC',0).
@@ -315,8 +318,8 @@ precompile(#image{objects = Os}=I) ->
I#image{objects = precompile_objects(Os)}.
precompile_objects([]) -> [];
-precompile_objects([#image_object{type=line, points=[P0,P1]}=O|Os]) ->
- [O#image_object{intervals = linespans_to_map(line_ls(P0,P1))}|precompile_objects(Os)];
+precompile_objects([#image_object{type=line, internals=W, points=[P0,P1]}=O|Os]) ->
+ [O#image_object{intervals = linespans_to_map(line_to_linespans(P0,P1,W))}|precompile_objects(Os)];
precompile_objects([#image_object{type=filled_triangle, points=[P0,P1,P2]}=O|Os]) ->
[O#image_object{intervals = triangle_ls(P0,P1,P2)}|precompile_objects(Os)];
precompile_objects([#image_object{type=polygon, points=Pts}=O|Os]) ->
@@ -568,6 +571,66 @@ line_ls_step(X, X1, Y, Dx, Dy, Ys, E, X0, true = Steep, LSs) when X =< X1 ->
line_ls_step(_X,_,_Y,_Dx,_Dy,_Ys,_E,_X0,_,LSs) ->
LSs.
+
+
+%% line_to_linespans
+%% Anti-aliased thick line
+%% Do it CPS style
+%% In:
+%% P1 :: point()
+%% P2 :: point()
+%% Out:
+%% [{Y,Xl,Xr}]
+%%
+line_to_linespans({X0,Y0},{X1,Y1},Wd) ->
+ Dx = abs(X1-X0),
+ Dy = abs(Y1-Y0),
+ Sx = if X0 < X1 -> 1; true -> -1 end,
+ Sy = if Y0 < Y1 -> 1; true -> -1 end,
+ E0 =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