Claim: Triangles PBA and DCP are congruent.
Angle BAP + angle BPA = 90 degrees (since the angles of a triangle sum
to 180, and one of the angles is 90)
Angle CPD + angle BPA = 90 degrees (since these two angles and right
angle APD sum to 180)
So angle BAP = angle CPD.
Angles DCP and ABP are right angles, by construction.
Sides AB and CP have length m, by construction.
So by the ASA triangle congruence theorem, triangle PBA is congruent
to triangle DCP, and all the other corresponding parts are congruent.
In particular, CD = BP = 1.
In computing slopes, the direction in which you subtract the points is important. In this picture,
(y coord of A - y coord of P) / (x coord of A - x coord of P) = m / 1giving a positive slope for L. On the other triangle,
(y coord of D - y coord of P) / (x coord of D - x coord of P) = 1 / (-m)giving a negative slope for M, which is the negative reciprocal of the slope of L.
If m is negative, the picture is just flipped vertically. (Or start with triangle DCP and construct triangle PBA.)
If the lines are horizontal and vertical, one has slope 0 and the other has slope 0 and the other has slope infinity. In some contexts (including this one), you can think of infinity as being 1/0 or -1/0, so the theorem still works in this case.