//-------------------------------------------------------------------------------------------------- public bool ComputeParameters(out Parameters parameters) { if (FirstPoint.IsEqual(SecondPoint, 0.01)) { parameters = new(); return(false); } double scale = 1.0; // Dimension line direction var dimDir = new Vec2d(_FirstPoint, _SecondPoint).ToDir(); var dimMid = _FirstPoint.Lerped(_SecondPoint, 0.5); var dimWidth = _FirstPoint.Distance(_SecondPoint); scale = Math.Min(scale, dimWidth / (DrawingRenderHelper.GetArrowSize().Length * 3)); if (_AutoText) { Text = dimWidth.ToInvariantString("F1"); } var rotation = dimDir.Angle(Dir2d.DX); bool dimRightToLeft = false; if (rotation < -Maths.HalfPI) { rotation += Maths.PI; dimRightToLeft = true; } else if (rotation > Maths.HalfPI) { rotation -= Maths.PI; dimRightToLeft = true; } // Extension line var extDir = new Dir2d(dimDir.Y, -dimDir.X); if (dimDir.Angle(new Vec2d(dimMid, Position).ToDir()) > 0) { extDir.Reverse(); } var dimToPos = new gp_Lin2d(_FirstPoint, dimDir).Distance(Position); var extVector = extDir.ToVec(dimToPos + _ExtensionOverlength); var dimOffset = extDir.ToVec(dimToPos); // Text var textOrigin = _FirstPoint.Lerped(_SecondPoint, 0.5) .Translated(dimOffset); var textWidth = 1.0; var textHeight = 1.0; var textScale = scale; if (!Text.IsNullOrWhiteSpace()) { var fontStyle = DrawingRenderHelper.GetDefaultFontStyle(); var textSize = DrawingRenderHelper.MeasureText(Text, fontStyle); textScale = Math.Min(1.0, dimWidth * 0.90 / textSize.X); scale = Math.Min(scale, textScale); // Exact positioning on above dim line var textOffset = dimDir.Angle(extDir) > 0 ? 1.0 : -1.0; if (dimRightToLeft) { textOffset *= -1; } textOrigin.Translate(extDir.ToVec(textOffset)); // Center textOrigin.Translate(dimDir.ToVec((dimRightToLeft ? 1.0 : -1.0) * textSize.X / 2 * textScale)); textWidth = textSize.X * textScale; textHeight = textSize.Y * textScale; } parameters = new Parameters() { ExtensionVector = extVector, DimensionDirection = dimDir, DimensionOffset = dimOffset, DimensionRotation = rotation, TextOrigin = textOrigin, TextWidth = textWidth, TextHeight = textHeight, Scale = scale, TextScale = textScale }; return(true); }