Example #1
0
        /// <summary>
        /// Sets the handle tip to the provided coordinate.
        /// </summary>
        /// <param name="handleTip">The handle tip.</param>
        public void SetHandleTip(CartesianCoordinate handleTip)
        {
            CartesianOffset offset = handleTip.OffsetFrom(ControlPoint);

            Radius   = offset.Length();
            Rotation = offset.SlopeAngle();
        }
Example #2
0
        public static void ToOffset()
        {
            CartesianOffset offset         = RangeWithLimits.ToOffset();
            CartesianOffset offsetExpected = new CartesianOffset(new CartesianCoordinate(-0.5, -1.5), new CartesianCoordinate(2, 1), Tolerance);

            Assert.AreEqual(offsetExpected, offset);
        }
Example #3
0
        public static void Length_Returns_Linear_Distance_Between_Offset_Points(double xI, double yI, double xJ, double yJ, double distance)
        {
            CartesianOffset offset = new CartesianOffset(
                new CartesianCoordinate(xI, yI),
                new CartesianCoordinate(xJ, yJ));

            Assert.AreEqual(distance, offset.Length(), Tolerance);
        }
Example #4
0
        public static void Implicit_Conversion_Between_Cartesian_And_Polar_Offsets()
        {
            CartesianOffset cartesian     = new CartesianOffset(1, 1.73205081, Tolerance);
            PolarOffset     polar         = cartesian;
            PolarOffset     polarExpected = new PolarOffset(new PolarCoordinate(0, 0), new PolarCoordinate(2, Angle.CreateFromDegree(60)), Tolerance);

            Assert.AreEqual(polarExpected, polar);
        }
        public static void ToCartesian_Converts_Polar_Offset_to_Cartesian_Offset()
        {
            PolarOffset     polar             = new PolarOffset(new PolarCoordinate(0, 0), new PolarCoordinate(2, Angle.CreateFromDegree(60)), Tolerance);
            CartesianOffset cartesian         = polar.ToCartesian();
            CartesianOffset cartesianExpected = new CartesianOffset(1, 1.73205081, Tolerance);

            Assert.AreEqual(cartesianExpected, cartesian);
        }
Example #6
0
        public static void DivideOverride_Throws_Exception_when_Dividing_by_Zero()
        {
            CartesianOffset offset = new CartesianOffset(
                new CartesianCoordinate(1, 2),
                new CartesianCoordinate(-2, 3));

            Assert.Throws <DivideByZeroException>(() => { CartesianOffset offsetNew = offset / 0; });
        }
Example #7
0
        public static void ToPolar_Converts_Cartesian_Offset_to_Polar_Offset()
        {
            CartesianOffset cartesian     = new CartesianOffset(1, 1.73205081, Tolerance);
            PolarOffset     polar         = cartesian.ToPolar();
            PolarOffset     polarExpected = new PolarOffset(new PolarCoordinate(0, 0), new PolarCoordinate(2, Angle.CreateFromDegree(60)), Tolerance);

            Assert.AreEqual(polarExpected, polar);
        }
Example #8
0
        public static void X_Returns_X_Coordinates_Difference(double xI, double xJ, double xDifference)
        {
            CartesianOffset offset = new CartesianOffset(
                new CartesianCoordinate(xI, 0),
                new CartesianCoordinate(xJ, 0));

            Assert.AreEqual(xDifference, offset.X(), Tolerance);
        }
Example #9
0
        public static void Y_Returns_Y_Coordinates_Difference(double yI, double yJ, double yDifference)
        {
            CartesianOffset offset = new CartesianOffset(
                new CartesianCoordinate(0, yI),
                new CartesianCoordinate(0, yJ));

            Assert.AreEqual(yDifference, offset.Y(), Tolerance);
        }
 /// <summary>
 /// Skews the specified shape to the skewing of a containing box.
 /// </summary>
 /// <param name="stationaryReferencePoint">The stationary reference point of the skew box.</param>
 /// <param name="skewingReferencePoint">The skewing reference point of the skew box.</param>
 /// <param name="magnitude">The magnitude to skew along the x-axis and y-axis.</param>
 /// <returns>IPathSegment.</returns>
 public Shape Skew(
     CartesianCoordinate stationaryReferencePoint,
     CartesianCoordinate skewingReferencePoint,
     CartesianOffset magnitude)
 {
     _polyline = new PolyLine(skew(stationaryReferencePoint, skewingReferencePoint, magnitude));
     return(this);
 }
 /// <summary>
 /// Skews the specified segment to the skewing of a containing box.
 /// </summary>
 /// <param name="stationaryReferencePoint">The stationary reference point of the skew box.</param>
 /// <param name="skewingReferencePoint">The skewing reference point of the skew box.</param>
 /// <param name="magnitude">The magnitude to skew along the x-axis and y-axis.</param>
 /// <returns>IPathSegment.</returns>
 public virtual IPathSegment Skew(
     CartesianCoordinate stationaryReferencePoint,
     CartesianCoordinate skewingReferencePoint,
     CartesianOffset magnitude)
 {
     return(new LineSegment(
                CartesianCoordinate.SkewWithinBox(I, stationaryReferencePoint, skewingReferencePoint, magnitude),
                CartesianCoordinate.SkewWithinBox(J, stationaryReferencePoint, skewingReferencePoint, magnitude)));
 }
        /// <summary>
        /// Scales the segment from the provided reference point.
        /// </summary>
        /// <param name="scale">The amount to scale relative to the reference point.</param>
        /// <param name="referencePoint">The reference point.</param>
        /// <returns>IPathSegment.</returns>
        public virtual IPathSegment ScaleFromPoint(double scale, CartesianCoordinate referencePoint)
        {
            CartesianOffset offsetJ = scale * (J.OffsetFrom(referencePoint));
            CartesianOffset offsetI = scale * (I.OffsetFrom(referencePoint));

            return(new LineSegment(
                       referencePoint + offsetI.ToCartesianCoordinate(),
                       referencePoint + offsetJ.ToCartesianCoordinate()));
        }
        /// <summary>
        /// The y-coordinates of a line intersecting a circle centered at 0,0.
        /// </summary>
        /// <param name="point1">First point forming the line.</param>
        /// <param name="point2">Second point forming the line.</param>
        /// <param name="radius">Radius of the circle centered at 0,0.</param>
        public static double[] CircleLineIntersectY(CartesianCoordinate point1, CartesianCoordinate point2, double radius)
        {
            CartesianOffset delta       = new CartesianOffset(point1, point2);
            double          determinant = point1.CrossProduct(point2);
            double          lineLength  = AlgebraLibrary.SRSS(delta.X(), delta.Y());
            double          incidence   = incidenceLineCircle(radius, lineLength, determinant);

            return(CircleLineIntersectY(radius, lineLength, incidence, determinant, delta));
        }
Example #14
0
        public static void Hashcode_Matches_for_Object_with_Identical_Coordinates()
        {
            CartesianCoordinate coordinate1 = new CartesianCoordinate(1, 2);
            CartesianCoordinate coordinate2 = new CartesianCoordinate(3, 4);
            double          tolerance       = 0.0002;
            CartesianOffset offset1         = new CartesianOffset(coordinate1, coordinate2, tolerance);
            CartesianOffset offset2         = new CartesianOffset(coordinate1, coordinate2, tolerance);

            Assert.AreEqual(offset1.GetHashCode(), offset2.GetHashCode());
        }
Example #15
0
        public static void SlopeAngle_Returns_Angle_of_Slope_Between_Offset_Points(
            double xI, double yI,
            double xJ, double yJ,
            double angleDegreesExpected)
        {
            CartesianOffset offset = new CartesianOffset(new CartesianCoordinate(xI, yI), new CartesianCoordinate(xJ, yJ));
            Angle           slope  = offset.SlopeAngle();

            Assert.AreEqual(angleDegreesExpected, slope.Degrees);
        }
        /// <summary>
        /// Translates the segments.
        /// </summary>
        /// <param name="translation">The amount to translate by.</param>
        /// <returns>IList&lt;IPathSegment&gt;.</returns>
        protected SegmentsBoundary translateSegments(CartesianOffset translation)
        {
            IList <IPathSegment> segments = new List <IPathSegment>();

            foreach (IPathSegment segment in _polyline)
            {
                segments.Add(segment.Translate(translation));
            }
            return(new SegmentsBoundary(segments));
        }
 /// <summary>
 /// The y-coordinates of a line intersecting a circle centered at 0,0.
 /// </summary>
 /// <param name="radius"></param>
 /// <param name="lineLength"></param>
 /// <param name="incidence"></param>
 /// <param name="determinant"></param>
 /// <param name="delta"></param>
 /// <returns></returns>
 public static double[] CircleLineIntersectY(
     double radius,
     double lineLength,
     double incidence,
     double determinant,
     CartesianOffset delta)
 {
     return((-determinant * delta.X() / lineLength.Squared()).PlusMinus(
                NMath.Abs(delta.Y()) * NMath.Sqrt(incidence) / lineLength.Squared()));
 }
Example #18
0
        public static void NotEqualsOverride_Is_True_for_Object_with_Differing_MaxMin_Coordinates()
        {
            CartesianCoordinate coordinate1 = new CartesianCoordinate(1, 2);
            CartesianCoordinate coordinate2 = new CartesianCoordinate(3, 4);
            CartesianCoordinate coordinate3 = new CartesianCoordinate(3, 4);
            CartesianOffset     offset1     = new CartesianOffset(coordinate1, coordinate2);
            CartesianOffset     offsetDiffI = new CartesianOffset(coordinate3, coordinate2);

            Assert.IsTrue(offset1 != offsetDiffI);
        }
Example #19
0
        public static void CartesianOffset_Initialization_with_Offsets()
        {
            double          tolerance = 0.5;
            CartesianOffset offset    = new CartesianOffset(2, 3, tolerance);

            Assert.AreEqual(0, offset.I.X);
            Assert.AreEqual(0, offset.I.Y);
            Assert.AreEqual(2, offset.J.X);
            Assert.AreEqual(3, offset.J.Y);
            Assert.AreEqual(tolerance, offset.Tolerance);
        }
Example #20
0
        public static void EqualsOverride_Is_True_for_Object_with_Identical_Coordinates()
        {
            CartesianCoordinate coordinate1 = new CartesianCoordinate(1, 2);
            CartesianCoordinate coordinate2 = new CartesianCoordinate(3, 4);
            CartesianOffset     offset1     = new CartesianOffset(coordinate1, coordinate2);
            CartesianOffset     offset2     = new CartesianOffset(coordinate1, coordinate2);

            Assert.IsTrue(offset1.Equals(offset2));
            Assert.IsTrue(offset1.Equals((object)offset2));
            Assert.IsTrue(offset1 == offset2);
        }
        public static void Translate_Translates_Shape()
        {
            Polygon         polygon     = new Polygon(bowTieNonCrossingSegments);
            CartesianOffset translation = new CartesianOffset(1, -3);

            Polygon       polygonTranslated = polygon.Translate(translation) as Polygon;
            PointBoundary pointBoundary     = polygonTranslated.PointBoundary();

            Assert.AreEqual(1, pointBoundary[1].X);
            Assert.AreEqual(0, pointBoundary[1].Y);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CircularCurve" /> class.
 /// </summary>
 /// <param name="radius">The radius.</param>
 /// <param name="center">The center.</param>
 /// <param name="tolerance">Tolerance to apply to the curve.</param>
 public CircularCurve(
     double radius,
     CartesianCoordinate center,
     double tolerance = DEFAULT_TOLERANCE)
     : base(
         vertexMajor(radius, center),
         center,
         CartesianOffset.Separation(vertexMajor(radius, center), center),
         tolerance)
 {
 }
Example #23
0
        public static void CartesianOffset_InitializationWithDefaultTolerance()
        {
            CartesianCoordinate coordinate1 = new CartesianCoordinate(1, 2);
            CartesianCoordinate coordinate2 = new CartesianCoordinate(3, 4);
            CartesianOffset     offset      = new CartesianOffset(coordinate1, coordinate2);

            Assert.AreEqual(coordinate1.X, offset.I.X);
            Assert.AreEqual(coordinate1.Y, offset.I.Y);
            Assert.AreEqual(coordinate2.X, offset.J.X);
            Assert.AreEqual(coordinate2.Y, offset.J.Y);
            Assert.AreEqual(Numbers.ZeroTolerance, offset.Tolerance);
        }
        /// <summary>
        /// Skews the specified shape to the skewing of a containing box.
        /// </summary>
        /// <param name="stationaryReferencePoint">The stationary reference point of the skew box.</param>
        /// <param name="skewingReferencePoint">The skewing reference point of the skew box.</param>
        /// <param name="magnitude">The magnitude to skew along the x-axis and y-axis.</param>
        /// <returns>IList&lt;IPathSegment&gt;.</returns>
        protected SegmentsBoundary skew(
            CartesianCoordinate stationaryReferencePoint,
            CartesianCoordinate skewingReferencePoint,
            CartesianOffset magnitude)
        {
            IList <IPathSegment> segments = new List <IPathSegment>();

            foreach (IPathSegment segment in _polyline)
            {
                segments.Add(segment.Skew(stationaryReferencePoint, skewingReferencePoint, magnitude));
            }
            return(new SegmentsBoundary(segments));
        }
Example #25
0
        public static void CartesianOffset_Initialization_with_Coordinates()
        {
            CartesianCoordinate coordinate1 = new CartesianCoordinate(1, 2);
            CartesianCoordinate coordinate2 = new CartesianCoordinate(3, 4);
            double          tolerance       = 0.5;
            CartesianOffset offset          = new CartesianOffset(coordinate1, coordinate2, tolerance);

            Assert.AreEqual(coordinate1.X, offset.I.X);
            Assert.AreEqual(coordinate1.Y, offset.I.Y);
            Assert.AreEqual(coordinate2.X, offset.J.X);
            Assert.AreEqual(coordinate2.Y, offset.J.Y);
            Assert.AreEqual(tolerance, offset.Tolerance);
        }
Example #26
0
        public static void ToCartesianCoordinate_Returns_Cartesian_Coordinate_Offset_from_Orgin(
            double xI, double yI, double xJ, double yJ,
            double xNew, double yNew)
        {
            CartesianOffset offset = new CartesianOffset(
                new CartesianCoordinate(xI, yI),
                new CartesianCoordinate(xJ, yJ));

            CartesianCoordinate newCoordinate = offset.ToCartesianCoordinate();

            Assert.AreEqual(xNew, newCoordinate.X, Tolerance);
            Assert.AreEqual(yNew, newCoordinate.Y, Tolerance);
        }
        public static void Initialization_with_Coordinates_Results_in_Object_with_Immutable_Coordinates_Properties_List()
        {
            CartesianCoordinate localOriginInGlobal  = new CartesianCoordinate(3, 2);
            CartesianCoordinate localAxisXPtInGlobal = new CartesianCoordinate(5, 4);
            Transformations     transformations      = new Transformations(localOriginInGlobal, localAxisXPtInGlobal);

            AngularOffset   angularOffset = new AngularOffset(Numbers.Pi / 4);
            CartesianOffset offset        = localOriginInGlobal.OffsetFrom(CartesianCoordinate.Origin());

            Assert.AreEqual(localOriginInGlobal, transformations.LocalOrigin);
            Assert.AreEqual(localAxisXPtInGlobal, transformations.LocalAxisX);
            Assert.AreEqual(offset, transformations.Displacement);
            Assert.AreEqual(angularOffset.ToAngle().Degrees, transformations.Rotation.ToAngle().Degrees, Tolerance);
        }
Example #28
0
        public static void DivideOverride_Divides_Coordinate_by_a_Scaling_Factor(double a1, double a2, double factor,
                                                                                 double scaledIX, double scaledIY, double scaledJX, double scaledJY)
        {
            CartesianCoordinate coordinate1 = new CartesianCoordinate(a1, a2);
            CartesianCoordinate coordinate2 = new CartesianCoordinate(a2, a1);
            CartesianOffset     offset      = new CartesianOffset(coordinate1, coordinate2);

            CartesianOffset offsetNew = offset / factor;

            Assert.AreEqual(scaledIX, offsetNew.I.X, Tolerance);
            Assert.AreEqual(scaledIY, offsetNew.I.Y, Tolerance);
            Assert.AreEqual(scaledJX, offsetNew.J.X, Tolerance);
            Assert.AreEqual(scaledJY, offsetNew.J.Y, Tolerance);
        }
Example #29
0
            /// <summary>
            /// Initializes a new instance of the <see cref="IntersectionProperties"/> class.
            /// </summary>
            /// <param name="linearCurve">The linear curve.</param>
            /// <param name="circularCurve">The circular curve.</param>
            public IntersectionProperties(LinearCurve linearCurve, CircularCurve circularCurve)
            {
                Tolerance       = Generics.GetTolerance(linearCurve, circularCurve);
                Transformations = new Transformations(circularCurve.LocalOrigin, new CartesianCoordinate(circularCurve.LocalOrigin.X + 1, circularCurve.LocalOrigin.Y));
                LinearCurve linearCurveLocal = transformToLocal(linearCurve);

                D = Numbers.ValueAsZeroIfWithinAbsoluteTolerance(linearCurveLocal.ControlPointI.CrossProduct(linearCurveLocal.ControlPointJ), Tolerance);
                CartesianOffset offset = linearCurveLocal.Range.End.Limit.OffsetFrom(linearCurveLocal.Range.Start.Limit);

                dx = offset.X();
                dy = offset.Y();
                dr = AlgebraLibrary.SRSS(dx, dy);

                IncidenceDelta = Numbers.ValueAsZeroIfWithinAbsoluteTolerance((circularCurve.Radius * dr).Squared() - D.Squared(), Tolerance);
            }
Example #30
0
        public static void AddOverride_Adding_Coordinate_Returns_Coordinate_Added_by_Offset(
            double x, double y,
            double Xi2, double Yi2, double Xj2, double Yj2,
            double XResult, double YResult)
        {
            CartesianCoordinate coordinate = new CartesianCoordinate(x, y);

            CartesianOffset offset = new CartesianOffset(
                new CartesianCoordinate(Xi2, Yi2),
                new CartesianCoordinate(Xj2, Yj2));

            CartesianCoordinate offsetCoordinate = offset + coordinate;

            Assert.AreEqual(XResult, offsetCoordinate.X, Tolerance);
            Assert.AreEqual(YResult, offsetCoordinate.Y, Tolerance);
        }