Debian Codegraph @

texmf-dist/tex/latex/tkz-euclide/tkz-draw-eu-lines.tex

raw
1 % tkz-obj-eu-draw-lines.tex
2 % Copyright 2011-2026 Alain Matthes
3 % SPDX-License-Identifier: LPPL-1.3c
4 % Maintainer: Alain Matthes
5
6 \typeout{2026/01/25 5.13c tkz-obj-eu-draw-lines.tex}
7 \makeatletter
8
9 %<--------------------------------------------------------------------------–>
10 % Setup Line
11 %<--------------------------------------------------------------------------–>
12 \pgfkeys{%
13 tkzsuline/.cd,
14 line width/.code = \def\tkz@line@width{#1},
15 color/.code = \def\tkz@line@color{#1},
16 style/.code = \def\tkz@line@style{#1},
17 add/.code args = {#1 and #2} {\def\tkz@line@left{#1}
18 \def\tkz@line@right{#2}},
19 /tkzsuline/.search also = {/tikz}
20 }
21 %<--------------------------------------------------------------------------–>
22 \def\tkzSetUpLine{\pgfutil@ifnextchar[{\tkz@SetUpLine}{\tkz@SetUpLine[]}}
23 \def\tkz@SetUpLine[#1]{%
24 \pgfkeys{%
25 tkzsuline/.cd,
26 line width = \tkz@euc@linewidth,
27 color = \tkz@euc@linecolor,
28 style = \tkz@euc@linestyle,
29 add = {\tkz@euc@lineleft} and {\tkz@euc@lineright}}
30 \pgfqkeys{/tkzsuline}{#1}
31 \tikzset{%
32 line style/.append style ={%
33 line width = \tkz@line@width,
34 color = \tkz@line@color,
35 style = \tkz@line@style,
36 add = {\tkz@line@left} and {\tkz@line@right},
37 line cap = round,
38 #1}
39 }
40 }% end setup
41 %<--------------------------------------------------------------------------–>
42 % Drawing a line
43 %<--------------------------------------------------------------------------–>
44 %<--------------------------------------------------------------------------–>
45
46 \def\tkzDrawLine{\pgfutil@ifnextchar[{\tkz@DrawLine}{\tkz@DrawLine[]}}
47 \def\tkz@DrawLine[#1](#2,#3){%
48 \begingroup
49 \draw[line style,#1] (#2) to (#3);
50 \endgroup
51 }
52 %<-------------------------------------------------------------------------–
53 % tkzDrawLines
54 %<-------------------------------------------------------------------------–
55 \def\tkz@@multiLines#1 #2\@nil{%
56 \protected@edef\tkz@temp{
57 \noexpand \tkzDrawLine[\tkz@optline](#1)}\tkz@temp%
58 \def\tkz@nextArg{#2}%
59 \ifx\tkzutil@empty\tkz@nextArg
60 \let\next\@gobble
61 \fi
62 \next#2\@nil
63 }
64 %<--------------------------------------------------------------------------–>
65 \def\tkzDrawLines{\pgfutil@ifnextchar[{\tkz@DrawLines}{\tkz@DrawLines[]}}
66 \def\tkz@DrawLines[#1](#2){%
67 \xdef\tkz@optline{#1}
68 \begingroup
69 \let\next\tkz@@multiLines
70 \next#2 \@nil %
71 \endgroup
72 }%
73 %<-------------------------------------------------------------------------–>
74 % Label
75 %<-------------------------------------------------------------------------–>
76 \def\tkzLabelLine{\pgfutil@ifnextchar[{\tkz@AddLabelLine}{\tkz@AddLabelLine[]}}
77 \def\tkz@AddLabelLine[#1](#2,#3)#4{\path (#2) to node[#1]{#4}(#3);}
78
79
80 %<--------------------------------------------------------------------------–>
81 % draw segment (s)
82 %<--------------------------------------------------------------------------–>
83 \pgfkeys{/tkzdraws/.cd,
84 /tkzdraws/.search also={/tikz},
85 }
86 \def\tkzDrawSegment{\pgfutil@ifnextchar[{\tkz@DrawSegment}{%
87 \tkz@DrawSegment[]}}
88 \def\tkz@DrawSegment[#1](#2,#3){%
89 \scope
90 \pgfqkeys{/tkzdraws}{#1}
91 \draw[line style,add=0 and 0,#1] (#2) to (#3);
92 \endscope
93 }%
94
95 \def\tkz@multiDrawSeg#1 #2\@nil{%
96 \protected@edef\tkz@temp{
97 \noexpand \tkzDrawSegment[\tkz@optseg](#1)}\tkz@temp%
98 \def\tkz@nextArg{#2}%
99 \ifx\tkzutil@empty\tkz@nextArg
100 \let\next\@gobble
101 \fi
102 \next#2\@nil
103 }
104 \def\tkzDrawSegments{\pgfutil@ifnextchar[{\tkz@DrawSegments}{%
105 \tkz@DrawSegments[]}}
106 \def\tkz@DrawSegments[#1](#2){%
107 \def\tkz@optseg{#1}
108 \begingroup
109 \let\next\tkz@multiDrawSeg
110 \next#2 \@nil %
111 \endgroup
112 }
113 %<--------------------------------------------------------------------------–>
114 % Mark Segment
115 %<--------------------------------------------------------------------------–>
116 \pgfkeys{
117 /@tkzmarkoptions/.cd,
118 pos/.store in = \tkz@mkpos,
119 color/.store in = \tkz@mkcolor,
120 mark/.store in = \tkz@markseg,
121 size/.store in = \tkz@mksize,
122 size = 4pt,
123 color = \tkz@mk@color,
124 pos = .5,
125 mark = |,
126 /@tkzmarkoptions/.search also={/tikz},
127 }
128 \def\tkzMarkSegment{\pgfutil@ifnextchar[{\tkz@MarkSegment}{\tkz@MarkSegment[]}}
129 \def\tkz@MarkSegment[#1](#2,#3){%
130 \begingroup
131 \pgfqkeys{/@tkzmarkoptions}{#1}
132 \def\tkz@mymark{\pgfsetplotmarksize{\tkz@mksize}\pgfuseplotmark{\tkz@markseg}}
133 \begin{scope}
134 [decoration={markings,mark=at position \tkz@mkpos with {\tkz@mymark}}]
135 \path [\tkz@mkcolor,/@tkzmarkoptions/.cd,#1,postaction={decorate}] (#2) -- (#3);
136 \end{scope}
137 \endgroup
138 }
139 %<--------------------------------------------------------------------------–>
140 % multiple
141 \def\tkz@multiMS#1 #2\@nil{%
142 \protected@edef\tkz@temp{
143 \noexpand \tkzMarkSegment[\tkz@optsg](#1)}\tkz@temp%
144 \def\tkz@nextArg{#2}%
145 \ifx\tkzutil@empty\tkz@nextArg
146 \let\next\@gobble
147 \fi
148 \next#2\@nil
149 }
150 %<--------------------------------------------------------------------------–>
151 \def\tkzMarkSegments{\pgfutil@ifnextchar[{\tkz@MarkSegments}{\tkz@MarkSegments[]}}
152 \def\tkz@MarkSegments[#1](#2){%
153 \def\tkz@optsg{#1}
154 \begingroup
155 \let\next\tkz@multiMS
156 \next#2 \@nil %
157 \endgroup
158 }
159 %<-------------------------------------------------------------------------–>
160 % Label on segment
161 %<-------------------------------------------------------------------------–>
162 \def\tkzLabelSegment{\pgfutil@ifnextchar[{\tkz@LabelSegment}%
163 {\tkz@LabelSegment[]}}
164 \def\tkz@LabelSegment[#1](#2,#3)#4{%
165 \begingroup
166 \path (#2) to node[label style,#1]{#4} (#3) ;
167 \endgroup
168 }
169 %<--------------------------------------------------------------------------–>
170 % multiple
171 \def\tkz@multiLS#1 #2\@nil{%
172 \protected@edef\tkz@temp{
173 \noexpand \tkzLabelSegment[\tkz@optls](#1){\tkz@labelseg}}\tkz@temp%
174 \def\tkz@nextArg{#2}%
175 \ifx\tkzutil@empty\tkz@nextArg
176 \let\next\@gobble
177 \fi
178 \next#2\@nil
179 }
180 %<--------------------------------------------------------------------------–>
181 \def\tkzLabelSegments{\pgfutil@ifnextchar[{\tkz@LabelSegments}{\tkz@LabelSegments[]}}
182 \def\tkz@LabelSegments[#1](#2)#3{%
183 \def\tkz@optls{#1}
184 \def\tkz@labelseg{#3}
185 \begingroup
186 \let\next\tkz@multiLS
187 \next#2 \@nil %
188 \endgroup
189 }
190 %<--------------------------------------------------------------------------–>
191 % PolySeg
192 %<--------------------------------------------------------------------------–>
193 \def\tkzDrawPolySeg{\pgfutil@ifnextchar[{\tkz@DrawPolySeg}{\tkz@DrawPolySeg[]}}
194 \def\tkz@DrawPolySeg[#1](#2,#3){%
195 \begingroup
196 \draw[line style,#1] (#2)
197 \foreach \pt in {#2,#3}{--(\pt)};%
198 \endgroup
199 }
200
201
202 %<--------------------------------------------------------------------------–>
203 % add dim
204 % \draw[dim={5,7pt,}] (A) -- (B);
205 % \draw[dim={7,10pt,transform shape}] (B) -- (C);
206 % \draw[dim={X,,}] (A) -- (C);
207 %<--------------------------------------------------------------------------–>
208 % new code from muzimuzhi Z
209 %https://tex.stackexchange.com/questions/553430/change-color-and-style-of-dimension-lines-in-tkz-euclide/553441
210
211 \pgfkeys{/pgf/decoration/.cd, distance/.initial = 10pt}
212
213 \pgfdeclaredecoration{add dim}{final}{
214 \state{final}{%
215 \pgfmathsetmacro{\dist}{\pgfkeysvalueof{/pgf/decoration/distance}}
216 \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
217 \pgfpathlineto{\pgfpoint{0pt}{1.2*\dist}}
218 \pgfpathmoveto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
219 \pgfpathlineto{\pgfpoint{(\pgfdecoratedpathlength}{1.2*\dist}}
220 % start of patch
221 \pgfusepath{stroke}
222 \pgfsetarrowsstart{latex}
223 \pgfsetarrowsend{latex}
224 \expandafter\pgfsetdash\tkz@dim@dashpattern
225 \pgfsetstrokecolor{\tkz@dim@color}
226 % end of patch
227 \pgfpathmoveto{\pgfpoint{0pt}{\dist}}
228 \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{\dist}}
229 \pgfusepath{stroke}
230 \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
231 \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
232 }}
233
234
235 \tikzset{
236 dim/.style args={#1,#2,#3}{%
237 postaction={
238 decoration={
239 show path construction,
240 lineto code={
241 % dim fence
242 \draw[dim fence style/.try]
243 (\tikzinputsegmentfirst) --
244 ($ (\tikzinputsegmentfirst)!1.2*(#2)!90:(\tikzinputsegmentlast) $)
245 (\tikzinputsegmentlast) --
246 ($ (\tikzinputsegmentlast)!1.2*(#2)!-90:(\tikzinputsegmentfirst) $);
247 % dim
248 \draw[dim style/.try]
249 ($ (\tikzinputsegmentfirst)!#2!90:(\tikzinputsegmentlast) $) --
250 node[inner sep=0pt, font=\footnotesize, fill=\tkz@fillcolor, pos=.5, #3] {#1}
251 ($ (\tikzinputsegmentlast)!#2!-90:(\tikzinputsegmentfirst) $);
252 }
253 },
254 decorate,
255 }
256 },
257 dim/.default={,0pt,},
258 dim style/.style={
259 latex-latex,
260 },
261 }
262
263 %<--------------------------- style line --------------------------------->
264 \tikzset{add/.style args={#1 and #2}{to path={%
265 ($(\tikztostart)!-#1!(\tikztotarget)$)--($(\tikztotarget)!-#2!(\tikztostart)$)%
266 \tikztonodes}}
267 }
268 \makeatother
269 \endinput