Skip to main content
added 4179 characters in body
Source Link
Malachi
  • 28.7k
  • 11
  • 86
  • 188

you also have some places among your if statement blocks that you should be adding new lines to keep them separate, it helps when you are reading through the code.

                    sp1 = camera.WorldToScreenPoint(lines[i].point1);
                    sp2 = camera.WorldToScreenPoint(lines[i].point2);
                    if (lines[i].lineParams.endPoint1Type == EndPointType.HollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness;
                        Vector3 diff = (sp2 - sp1).normalized * endpointRadius;
                        sp1 += diff;
                    }
                    else if (lines[i].lineParams.endPoint1Type == EndPointType.DoubleCircle || lines[i].lineParams.endPoint1Type == EndPointType.DoubleHollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness * doubleCircleRadiusRatio;
                        Vector3 diff = (sp2 - sp1).normalized * endpointRadius;
                        sp1 += diff;
                    }
                    if (lines[i].lineParams.endPoint2Type == EndPointType.HollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness;
                        Vector3 diff = (sp1 - sp2).normalized * endpointRadius;
                        sp2 += diff;
                    }
                    else if (lines[i].lineParams.endPoint2Type == EndPointType.DoubleCircle || lines[i].lineParams.endPoint2Type == EndPointType.DoubleHollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness * doubleCircleRadiusRatio; ;
                        Vector3 diff = (sp1 - sp2).normalized * endpointRadius;
                        sp2 += diff;
                    }
                    DrawLine(sp1, sp2, lines[i].lineParams.lineThickness, lines[i].lineParams.lineColor);

it should look like this

                    sp1 = camera.WorldToScreenPoint(lines[i].point1);
                    sp2 = camera.WorldToScreenPoint(lines[i].point2);

                    if (lines[i].lineParams.endPoint1Type == EndPointType.HollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness;
                        Vector3 diff = (sp2 - sp1).normalized * endpointRadius;
                        sp1 += diff;
                    }
                    else if (lines[i].lineParams.endPoint1Type == EndPointType.DoubleCircle || lines[i].lineParams.endPoint1Type == EndPointType.DoubleHollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness * doubleCircleRadiusRatio;
                        Vector3 diff = (sp2 - sp1).normalized * endpointRadius;
                        sp1 += diff;
                    }

                    if (lines[i].lineParams.endPoint2Type == EndPointType.HollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness;
                        Vector3 diff = (sp1 - sp2).normalized * endpointRadius;
                        sp2 += diff;
                    }
                    else if (lines[i].lineParams.endPoint2Type == EndPointType.DoubleCircle || lines[i].lineParams.endPoint2Type == EndPointType.DoubleHollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness * doubleCircleRadiusRatio; ;
                        Vector3 diff = (sp1 - sp2).normalized * endpointRadius;
                        sp2 += diff;
                    }
                    DrawLine(sp1, sp2, lines[i].lineParams.lineThickness, lines[i].lineParams.lineColor);

so you know that there are two separate if blocks here.


you also have some places among your if statement blocks that you should be adding new lines to keep them separate, it helps when you are reading through the code.

                    sp1 = camera.WorldToScreenPoint(lines[i].point1);
                    sp2 = camera.WorldToScreenPoint(lines[i].point2);
                    if (lines[i].lineParams.endPoint1Type == EndPointType.HollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness;
                        Vector3 diff = (sp2 - sp1).normalized * endpointRadius;
                        sp1 += diff;
                    }
                    else if (lines[i].lineParams.endPoint1Type == EndPointType.DoubleCircle || lines[i].lineParams.endPoint1Type == EndPointType.DoubleHollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness * doubleCircleRadiusRatio;
                        Vector3 diff = (sp2 - sp1).normalized * endpointRadius;
                        sp1 += diff;
                    }
                    if (lines[i].lineParams.endPoint2Type == EndPointType.HollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness;
                        Vector3 diff = (sp1 - sp2).normalized * endpointRadius;
                        sp2 += diff;
                    }
                    else if (lines[i].lineParams.endPoint2Type == EndPointType.DoubleCircle || lines[i].lineParams.endPoint2Type == EndPointType.DoubleHollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness * doubleCircleRadiusRatio; ;
                        Vector3 diff = (sp1 - sp2).normalized * endpointRadius;
                        sp2 += diff;
                    }
                    DrawLine(sp1, sp2, lines[i].lineParams.lineThickness, lines[i].lineParams.lineColor);

it should look like this

                    sp1 = camera.WorldToScreenPoint(lines[i].point1);
                    sp2 = camera.WorldToScreenPoint(lines[i].point2);

                    if (lines[i].lineParams.endPoint1Type == EndPointType.HollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness;
                        Vector3 diff = (sp2 - sp1).normalized * endpointRadius;
                        sp1 += diff;
                    }
                    else if (lines[i].lineParams.endPoint1Type == EndPointType.DoubleCircle || lines[i].lineParams.endPoint1Type == EndPointType.DoubleHollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness * doubleCircleRadiusRatio;
                        Vector3 diff = (sp2 - sp1).normalized * endpointRadius;
                        sp1 += diff;
                    }

                    if (lines[i].lineParams.endPoint2Type == EndPointType.HollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness;
                        Vector3 diff = (sp1 - sp2).normalized * endpointRadius;
                        sp2 += diff;
                    }
                    else if (lines[i].lineParams.endPoint2Type == EndPointType.DoubleCircle || lines[i].lineParams.endPoint2Type == EndPointType.DoubleHollowCircle)
                    {
                        float endpointRadius = lines[i].lineParams.pointThickness * doubleCircleRadiusRatio; ;
                        Vector3 diff = (sp1 - sp2).normalized * endpointRadius;
                        sp2 += diff;
                    }
                    DrawLine(sp1, sp2, lines[i].lineParams.lineThickness, lines[i].lineParams.lineColor);

so you know that there are two separate if blocks here.

Source Link
Malachi
  • 28.7k
  • 11
  • 86
  • 188

for this if statement that is nested

                //Point 3
                if (enableDrawingAngle && lines[i].elementType == ElementType.Angle)
                {
                    if (lines[i].lineParams.endPoint3Type == EndPointType.Arrow)
                    {
                        //Arrow end point
                        sp = camera.WorldToScreenPoint(lines[i].point2);
                        sp1 = camera.WorldToScreenPoint(lines[i].point3);
                        DrawArrows(sp1, sp, lines[i].lineParams.endPointColor, lines[i].lineParams.lineThickness);
                    }
                }

it would actually look better if you put all the conditions into the first if statement(it looks like you are not worried about too many conditions)

so you should write it like this

//Point 3
if (enableDrawingAngle && lines[i].elementType == ElementType.Angle
    && lines[i].lineParams.endPoint3Type == EndPointType.Arrow)
{
    //Arrow end point
    sp = camera.WorldToScreenPoint(lines[i].point2);
    sp1 = camera.WorldToScreenPoint(lines[i].point3);
    DrawArrows(sp1, sp, lines[i].lineParams.endPointColor, lines[i].lineParams.lineThickness);
}

less nesting always looks better especially when you have so many if statements to begin with.