Skip to content

Commit

Permalink
more specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Jun 28, 2024
1 parent db80cf3 commit ec7b49f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public ArcToHostConverter(
public ACG.Polyline Convert(SOG.Arc target)
{
if (
target.plane.normal.x != 0 || target.plane.normal.y != 0 || target.plane.xdir.z != 0 || target.plane.ydir.z != 0
target.startPoint.z != target.midPoint.z || target.startPoint.z != target.endPoint.z
)
{
throw new ArgumentException("Only 2d-Arc shape is supported");
throw new ArgumentException("Only Arc in XY plane are supported");
}
ACG.MapPoint fromPt = _pointConverter.Convert(target.startPoint);
ACG.MapPoint toPt = _pointConverter.Convert(target.endPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ACG.Polyline Convert(SOG.Circle target)
target.plane.normal.x != 0 || target.plane.normal.y != 0 || target.plane.xdir.z != 0 || target.plane.ydir.z != 0
)
{
throw new ArgumentException("Only 2d-Circle shape is supported");
throw new ArgumentException("Only Circles in XY plane are supported");
}

// create a native ArcGIS circle segment
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,35 @@ public ACG.Polyline Convert(SOG.Ellipse target)
// dummy check
if (target.firstRadius == null || target.secondRadius == null)
{
throw new ArgumentException("Invalid Ellipse provided");
throw new ArgumentException("Ellipse is missing the first or second radius");
}
if (
target.plane.normal.x != 0 || target.plane.normal.y != 0 || target.plane.xdir.z != 0 || target.plane.ydir.z != 0
)
{
throw new ArgumentException("Only 2d-Ellipse shape is supported");
throw new ArgumentException("Only Ellipses in XY plane are supported");
}

ACG.MapPoint centerPt = _pointConverter.Convert(target.plane.origin);
double scaleFactor = Units.GetConversionFactor(target.units, _contextStack.Current.SpeckleUnits);

// set default values
double angle = Math.Atan2(target.plane.xdir.y, target.plane.xdir.x);
double majorAxeRadius = (double)target.firstRadius;
double minorAxisRatio = (double)target.secondRadius / majorAxeRadius;
double majorAxisRadius = (double)target.firstRadius;
double minorAxisRatio = (double)target.secondRadius / majorAxisRadius;

// adjust if needed
if (minorAxisRatio > 1)
{
majorAxeRadius = (double)target.secondRadius;
majorAxisRadius = (double)target.secondRadius;
minorAxisRatio = 1 / minorAxisRatio;
angle += Math.PI / 2;
}

ACG.EllipticArcSegment segment = ACG.EllipticArcBuilderEx.CreateEllipse(
new ACG.Coordinate2D(centerPt),
angle,
majorAxeRadius * scaleFactor,
majorAxisRadius * scaleFactor,
minorAxisRatio,
ACG.ArcOrientation.ArcCounterClockwise,
_contextStack.Current.Document.Map.SpatialReference
Expand Down

0 comments on commit ec7b49f

Please sign in to comment.