/// <summary>Get the rectangle representation of the intersection between this rectangle and the passed rectangle /// </summary> /// <param name="rect">the rectangle to find the intersection with</param> /// <returns> /// the intersection rectangle if the passed rectangles intersects with this rectangle, /// a rectangle representing a line if the intersection is along an edge or /// a rectangle representing a point if the intersection is a single point, /// null otherwise /// </returns> public virtual iText.Kernel.Geom.Rectangle GetIntersection(iText.Kernel.Geom.Rectangle rect) { iText.Kernel.Geom.Rectangle result = null; //Calculate possible lower-left corner and upper-right corner float llx = Math.Max(x, rect.x); float lly = Math.Max(y, rect.y); float urx = Math.Min(GetRight(), rect.GetRight()); float ury = Math.Min(GetTop(), rect.GetTop()); //If width or height is non-negative, there is overlap and we can construct the intersection rectangle float width = urx - llx; float height = ury - lly; if (JavaUtil.FloatCompare(width, 0) >= 0 && JavaUtil.FloatCompare(height, 0) >= 0) { if (JavaUtil.FloatCompare(width, 0) < 0) { width = 0; } if (JavaUtil.FloatCompare(height, 0) < 0) { height = 0; } result = new iText.Kernel.Geom.Rectangle(llx, lly, width, height); } return(result); }
public override bool Equals(Object obj) { if (GetType() != obj.GetType()) { return(false); } iText.Layout.Properties.UnitValue other = (iText.Layout.Properties.UnitValue)obj; return(JavaUtil.IntegerCompare(unitType, other.unitType) == 0 && JavaUtil.FloatCompare(value, other.value) == 0); }
/// <summary>Apply a LineDashPattern along a Path</summary> /// <param name="path">input path</param> /// <param name="lineDashPattern">input LineDashPattern</param> /// <returns>a dashed Path</returns> public static Path ApplyDashPattern(Path path, LineDashPattern lineDashPattern) { ICollection <int> modifiedSubpaths = new HashSet <int>(path.ReplaceCloseWithLine()); Path dashedPath = new Path(); int currentSubpath = 0; foreach (Subpath subpath in path.GetSubpaths()) { IList <Point> subpathApprox = subpath.GetPiecewiseLinearApproximation(); if (subpathApprox.Count > 1) { dashedPath.MoveTo((float)subpathApprox[0].GetX(), (float)subpathApprox[0].GetY()); float remainingDist = 0; bool remainingIsGap = false; for (int i = 1; i < subpathApprox.Count; ++i) { Point nextPoint = null; if (remainingDist != 0) { nextPoint = GetNextPoint(subpathApprox[i - 1], subpathApprox[i], remainingDist); remainingDist = ApplyDash(dashedPath, subpathApprox[i - 1], subpathApprox[i], nextPoint, remainingIsGap); } while (JavaUtil.FloatCompare(remainingDist, 0) == 0 && !dashedPath.GetCurrentPoint().Equals(subpathApprox[ i])) { LineDashPattern.DashArrayElem currentElem = lineDashPattern.Next(); nextPoint = GetNextPoint(nextPoint != null ? nextPoint : subpathApprox[i - 1], subpathApprox[i], currentElem .GetVal()); remainingDist = ApplyDash(dashedPath, subpathApprox[i - 1], subpathApprox[i], nextPoint, currentElem.IsGap ()); remainingIsGap = currentElem.IsGap(); } } // If true, then the line closing the subpath was explicitly added (see Path.ReplaceCloseWithLine). // This causes a loss of a visual effect of line join style parameter, so in this clause // we simply add overlapping dash (or gap, no matter), which continues the last dash and equals to // the first dash (or gap) of the path. if (modifiedSubpaths.Contains(currentSubpath)) { lineDashPattern.Reset(); LineDashPattern.DashArrayElem currentElem = lineDashPattern.Next(); Point nextPoint = GetNextPoint(subpathApprox[0], subpathApprox[1], currentElem.GetVal()); ApplyDash(dashedPath, subpathApprox[0], subpathApprox[1], nextPoint, currentElem.IsGap()); } } // According to PDF spec. line dash pattern should be restarted for each new subpath. lineDashPattern.Reset(); ++currentSubpath; } return(dashedPath); }
/// <summary>Checks whether the dashed pattern is solid or not.</summary> /// <remarks> /// Checks whether the dashed pattern is solid or not. It's solid when the /// size of a dash array is even and sum of all the units off in the array /// is 0. /// For example: [3 0 4 0 5 0 6 0] (sum is 0), [3 0 4 0 5 1] (sum is 1). /// </remarks> /// <returns>is the dashed pattern solid or not</returns> public virtual bool IsSolid() { if (dashArray.Size() % 2 != 0) { return(false); } float unitsOffSum = 0; for (int i = 1; i < dashArray.Size(); i += 2) { unitsOffSum += dashArray.GetAsNumber(i).FloatValue(); } return(JavaUtil.FloatCompare(unitsOffSum, 0) == 0); }
public override bool Equals(Object o) { if (this == o) { return(true); } if (o == null || GetType() != o.GetType()) { return(false); } iText.Kernel.Colors.Gradients.GradientColorStop that = (iText.Kernel.Colors.Gradients.GradientColorStop)o; return(JavaUtil.FloatCompare(that.opacity, opacity) == 0 && JavaUtil.DoubleCompare(that.offset, offset) == 0 && JavaUtil.DoubleCompare(that.hintOffset, hintOffset) == 0 && JavaUtil.ArraysEquals(rgb, that.rgb) && offsetType == that.offsetType && hintOffsetType == that.hintOffsetType); }
public virtual int Compare(ITextChunkLocation first, ITextChunkLocation second) { if (first == second) { return(0); } // not really needed, but just in case int result; result = JavaUtil.IntegerCompare(first.OrientationMagnitude(), second.OrientationMagnitude()); if (result != 0) { return(result); } int distPerpendicularDiff = first.DistPerpendicular() - second.DistPerpendicular(); if (distPerpendicularDiff != 0) { return(distPerpendicularDiff); } return(leftToRight ? JavaUtil.FloatCompare(first.DistParallelStart(), second.DistParallelStart()) : -JavaUtil.FloatCompare (first.DistParallelEnd(), second.DistParallelEnd())); }
public virtual int Compare(LocationTextExtractionStrategy2.ITextChunkLocation first, LocationTextExtractionStrategy2.ITextChunkLocation second) { if (first == second) { return(0); } int num = JavaUtil.IntegerCompare(first.OrientationMagnitude(), second.OrientationMagnitude()); if (num != 0) { return(num); } int num2 = first.DistPerpendicular() - second.DistPerpendicular(); if (num2 != 0) { return(num2); } if (!this.leftToRight) { return(-JavaUtil.FloatCompare(first.DistParallelEnd(), second.DistParallelEnd())); } return(JavaUtil.FloatCompare(first.DistParallelStart(), second.DistParallelStart())); }
internal virtual bool Contains(Point point) { return(JavaUtil.FloatCompare(Math.Abs(A * (float)point.GetX() + B * (float)point.GetY() + C), 0.1f) < 0); }