Distribution of $Z=\left\{\begin{matrix} X+Y & \operatorname{if} & X+Y<1\\ X+Y-1 & \operatorname{if} & X+Y>1 \end{matrix}\right.$ Let $X\perp Y$ be two random variables with uniform distribution on $[0,1]$. How is it possible that $F_Z(z)=z$?
Initially I wrote $F_Z(z)=\mathbb{P}(Z\leq z)=\mathbb{P}(X+Y\leq z,X+Y<1)+\mathbb{P}(X+Y-1\leq z,X+Y>1)$, and I started to study the first probability. For the triangle with vertices $(0,0),(0,1),(1,0)$ and longest side bounded by the line $y=1-x$, I plotted the line $y=z-x$ and I tried to study the different cases ($0<z<\frac{1}{2}$ and $\frac{1}{2}<z<1$). I thought the my approach was correct, but when I saw $F_Z(z)=z$ my entire argument was lacking. Where was I wrong? Could you please give me any hints on how solve the problem?
Thanks in advance.
 A: For $z\in\left(0,1\right)$ we find:
$$\begin{aligned}P\left(Z\leq z\right) & =P\left(Z\leq z,X+Y<1\right)+P\left(Z\leq z,X+Y>1\right)\\
 & =P\left(X+Y\leq z,X+Y<1\right)+P\left(X+Y-1\leq z,X+Y>1\right)\\
 & =P\left(X+Y<z\right)+P\left(1<X+Y<1+z\right)\\
 & =\frac{1}{2}z^{2}+\left[\frac{1}{2}-\frac{1}{2}\left(1-z\right)^{2}\right]=z
\end{aligned}
$$

Addendum:
To find the two probabilities it is handsome to make a picture and to find the areas that are involved.
Integration in order to find $P(1<X+Y<1+z)$ works like this:
$$\begin{aligned}P\left(1<X+Y<1+z\right) & =\int_{0}^{z}\int_{1-x}^{1}dydx+\int_{z}^{1}\int_{1-x}^{1-x+z}dydx\\
 & =\int_{0}^{z}xdx+\int_{z}^{1}zdx\\
 & =\frac{1}{2}z^{2}+z\left(1-z\right)\\
 & =z-\frac{1}{2}z^{2}
\end{aligned}
$$
Or - making use of the fact that $1-X\stackrel{d}{=}X$ and $1-Y\stackrel{d}{=}Y$
$$\begin{aligned}P\left(1<X+Y<1+z\right) & =P\left(1<X+Y\right)-P\left(1+z<X+Y\right)\\
 & =\frac{1}{2}-P\left(1-X+1-Y<1-z\right)\\
 & =\frac{1}{2}-\frac{1}{2}\left(1-z\right)^{2}\\
 & =z-\frac{1}{2}z^{2}
\end{aligned}
$$
A: Indeed. $$\mathsf P(Z\leq z)=\mathsf P(Z\leq z, X+Y\leq 1)+\mathsf P(Z\leq z, 1\lt X+Y)$$
Then, because $Z=(X+Y)\mathbf 1_{X+Y\leq 1}+(X+Y-1)\mathbf 1_{1<X+Y}$
$$\mathsf P(Z\leq z)=\mathsf P(X+Y\leq\min(z,1))+\mathsf P(1\lt X+Y\leq 1+z)$$
Now Letting $S=X+Y$: $$\begin{align}F_{\small Z}(z)&=F_{\small S}(\min(z,1))+F_{\small S}(1+z)-F_{\small S}(1)\\[3ex]f_{\small X,S}(x,s)&=f_{\small X}(x)\,f_{\small Y}(s-x)\\[1ex]&=\mathbf 1_{0\leq s\leq 2}\mathbf 1_{0\leq x\leq 1,0\leq s-x\leq 1}\\[1ex]&=\mathbf 1_{0\leq s\leq 2}\mathbf 1_{\max(0,s-1)\leq x\leq \min(1,s)}\\[1ex]&=\mathbf 1_{0\leq s< 1}\mathbf 1_{0\leq x\leq s}+\mathbf 1_{1\leq s\leq 2}\mathbf 1_{s-1\leq x\leq 1}\\[3ex]f_{\small S}(s)&=s\mathbf 1_{0\leq s<1}+(2-s)\mathbf 1_{1\leq s\leq 2}\\[2ex] F_{\small S}(s)&= \tfrac {s^2}2\mathbf 1_{0\leq s< 1}+\tfrac 12(-s^2+4s-2)\mathbf 1_{1\leq s\lt 2}+\mathbf 1_{2\leq s}\\[3ex]F_{\small Z}(z)&= F_{\small S}(\min(z,1))+F_{\small S}(1+z)-F_{\small S}(1)\\[1ex]&=(\tfrac{z^2}{2}+\tfrac 12(-(z+1)^2+4(z+1)-2)-\tfrac 12))\mathbf 1_{0\leq z\lt 1}+\mathbf 1_{1\leq z}\\[1ex]&=\tfrac 12(z^2-z^2-2z-1+4z+4-2-1)\mathbf 1_{0\leq z\leq 1}+\mathbf 1_{1\leq z}\\[1ex]&=z\mathbf 1_{0\leq z\lt 1}+\mathbf 1_{1\leq z}\end{align}$$

Alternatively because $Z= S\mathbf 1_{S\leq 1}+(S-1)\mathbf 1_{1<S}$ then the support for $S$, that is $[0,1)\cup[1,2]$, is folded onto $[0,1]$ to become the support for $Z$.
$$\begin{align}f_{\small Z}(z)&= (f_{\small S}(z)+f_{\small S}(z+1))\mathbf 1_{0\leq z\leq 1}\\&=(z+(2-(z+1)))\mathbf 1_{0\leq z\leq 1}\\&= \mathbf 1_{0\leq z\leq 1}\\[2ex] F_{\small Z}(z)&= z\mathbf 1_{0\leq z\lt 1}+\mathbf 1_{1\leq z}\end{align}$$
