Class Ext
- Namespace
- SearchAThing.Sci
- Assembly
- netcore-sci.dll
netcore-sci extension methods
public static class Ext
- Inheritance
-
Ext
- Inherited Members
Methods
Abs(Vector3)
return abs of given Vector3
public static Vector3 Abs(this Vector3 v)
Parameters
vVector3
Returns
AddEntities(DxfObject, IEnumerable<EntityObject>, Layer?)
add entity to the given dxf object ( it can be Dxfdocument or Block ) optionally set layer
public static void AddEntities(this DxfObject dxfObj, IEnumerable<EntityObject> ents, Layer? layer = null)
Parameters
dxfObjDxfObjectentsIEnumerable<EntityObject>layerLayer
AddEntity(DxfObject, EntityObject, Layer?)
add entity to the given dxf object ( it can be Dxfdocument or Block ) optionally set layer
public static EntityObject AddEntity(this DxfObject dxfObj, EntityObject eo, Layer? layer = null)
Parameters
dxfObjDxfObjecteoEntityObjectlayerLayer
Returns
- EntityObject
Angle(double, double, bool)
retrieve angle between from and to given; angles will subjected to normalization [0,2pi) and angle from can be greather than to
public static double Angle(this double angleFrom, double angleTo, bool normalizeAngles = true)
Parameters
angleFromdoubleangle from
angleTodoubleangle to
normalizeAnglesboolactuate [0,2PI) angle normalization
Returns
AngleInRange(double, double, double, double)
states if given angle is contained in from, to angle range; multiturn angles are supported because test will normalize to [0,2pi) automatically.
public static bool AngleInRange(this double pt_angle, double angle_from, double angle_to, double radTol = 1E-10)
Parameters
pt_angledoubleangle(rad) to test
angle_fromdoubleangle(rad) from
angle_todoubleangle(rad) to
radToldoubleoptional rad tolerance
Returns
AutoIntersect(IEnumerable<Line3D>, double, bool, IEnumerable<Vector3D>?)
autointersect given list of segments ( duplicates and overlapping are removed )
TODO: dummy function, optimize
public static IReadOnlyList<Line3D> AutoIntersect(this IEnumerable<Line3D> _segs, double tol, bool mergeColinearSegments = true, IEnumerable<Vector3D>? addictionalSplitPoints = null)
Parameters
_segsIEnumerable<Line3D>toldoublemergeColinearSegmentsbooladdictionalSplitPointsIEnumerable<Vector3D>
Returns
AutoTrimExtends(IEnumerable<Edge>, double)
automatically trim or extends consecutive edges intersections
public static IEnumerable<Edge> AutoTrimExtends(this IEnumerable<Edge> edges, double tol)
Parameters
edgesIEnumerable<Edge>toldouble
Returns
AutoZoom(DxfDocument, BBox3D)
tries to zoom dxf viewport on the given bbox
public static void AutoZoom(this DxfDocument dxf, BBox3D bbox)
Parameters
dxfDxfDocumentbboxBBox3D
BBox(IEnumerable<Geometry>, double)
bbox that cover all given geometries
public static BBox3D BBox(this IEnumerable<Geometry> geometry_block, double tol)
Parameters
geometry_blockIEnumerable<Geometry>toldoublelength tolerance
Returns
BBox(IEnumerable<Vector3D>)
construct a bbox from given enumerable set of points
public static BBox3D BBox(this IEnumerable<Vector3D> pts)
Parameters
ptsIEnumerable<Vector3D>points to build bbox
Returns
- BBox3D
bbox from given enumerable set of points
BBox(IEnumerable<EntityObject>, double)
construct a bbox from given set of dxf entity objects
public static BBox3D BBox(this IEnumerable<EntityObject> ents, double tol)
Parameters
entsIEnumerable<EntityObject>enumerable of dxf entity object
toldoubletolerance for comparision length tests
Returns
- BBox3D
new bbox containing given set of dxf entity objects
BBox(EntityObject, double)
construct a bbox from given dxf EntityObject
public static BBox3D BBox(this EntityObject eo, double tol)
Parameters
eoEntityObjectdxf entity object
toldoubletolerance for comparision length tests
Returns
- BBox3D
new bbox that contains given dxf entity object
Remarks
Currently Text, MText width not evaluated ( only insertion point is considered ). Arc is considered only From, MidPoint, To. Circle is considered only 4 points on circumference.
BBox3D(DxfDocument)
public static BBox3D BBox3D(this DxfDocument dxf)
Parameters
dxfDxfDocument
Returns
BestFittingPlane(IEnumerable<Line3D>, double)
detect best fitting plane from the set of given lines. precondition: lines must coplanar
public static Plane3D BestFittingPlane(this IEnumerable<Line3D> lines, double tol)
Parameters
linesIEnumerable<Line3D>toldouble
Returns
BestFittingPlane(IEnumerable<Vector3D>, double)
detect best fitting plane for given set of coplanar points
public static Plane3D BestFittingPlane(this IEnumerable<Vector3D> pts, double tol)
Parameters
ptsIEnumerable<Vector3D>toldouble
Returns
Boolean(IEnumerable<Vector3D>, double, IEnumerable<Vector3D>, ClipType, bool)
can generate a Int64MapExceptionRange exception if double values can't fit into a In64 representation. In that case try with tolerances not too small. It is suggested to use a lenTol/10 to avoid lost of precision during domain conversions. Altenatively use Loop to find exact intersection between planar poly supporting lines and arcs. ( this implementation uses Int64Map and clipper library )
public static IEnumerable<IEnumerable<Vector3D>> Boolean(this IEnumerable<Vector3D> polyA, double tol, IEnumerable<Vector3D> polyB, ClipType type, bool selfCheckInt64MapTolerance = true)
Parameters
polyAIEnumerable<Vector3D>toldoublepolyBIEnumerable<Vector3D>typeClipTypeselfCheckInt64MapTolerancebool
Returns
CS(EntityObject)
public static CoordinateSystem3D CS(this EntityObject eo)
Parameters
eoEntityObject
Returns
CadScript(Face3D)
public static string CadScript(this Face3D face)
Parameters
faceFace3D
Returns
CadScriptPoint(IEnumerable<Vector3D>)
create script that draw a point foreach of point set
public static string CadScriptPoint(this IEnumerable<Vector3D> points)
Parameters
pointsIEnumerable<Vector3D>points
Returns
- string
cadscript
CadScriptPolyline(IEnumerable<Vector3D>)
create a 3dpolyline cadscript from given set of points
public static string CadScriptPolyline(this IEnumerable<Vector3D> points)
Parameters
pointsIEnumerable<Vector3D>point set
Returns
- string
cad script
CheckSense(IEnumerable<Edge>, double)
From given set of edges returns the same set eventually toggling sense of edges to make them glue so that SGeomTo of previous equals SGeomFrom of current. It can raise exception if there isn't availability to glue edges regardless toggling their sense. first element will toggled to match second one, then other elements will follow the sense matching established.
public static IEnumerable<Edge> CheckSense(this IEnumerable<Edge> edges, double tol)
Parameters
edgesIEnumerable<Edge>input edges list
toldoublelength tolerance
Returns
CheckSort(IEnumerable<Edge>, double)
Allow to sort edges when a not consequential set is given to allow subsequent CheckSense. It can raise exception if there isn't a possible sequence continuity between given edges.
public static IEnumerable<Edge> CheckSort(this IEnumerable<Edge> edges, double tol)
Parameters
edgesIEnumerable<Edge>input edges list
toldoublelength tolerance
Returns
- IEnumerable<Edge>
edges in sequence ( sense not yet checked )
CircleBy3Points(IEnumerable<Vector3D>)
build circle3d by given set of 3 points
public static Circle3D CircleBy3Points(this IEnumerable<Vector3D> _pts)
Parameters
_ptsIEnumerable<Vector3D>
Returns
Clamp(Vector3, Vector3, Vector3)
return clamped Vector3 between [min,max] interval
public static Vector3 Clamp(this Vector3 v, Vector3 min, Vector3 max)
Parameters
Returns
- Vector3
given vector with xyz components clamped to corresponding min,max components
CompareToTol(double, double, double)
compare a, b using given tol
public static int CompareToTol(this double a, double tol, double b)
Parameters
Returns
- int
-1 if a less than b ; 0 if a equals tol b ; +1 if a greather than b
ContainsPoint(IEnumerable<Vector3D>, double, Vector3D, LoopContainsPointMode)
states if given point is in polygon
public static bool ContainsPoint(this IEnumerable<Vector3D> _pts, double tol, Vector3D pt, LoopContainsPointMode mode = LoopContainsPointMode.InsideOrPerimeter)
Parameters
_ptsIEnumerable<Vector3D>polygon point ( must ordered )
toldoublelength tolerance
ptVector3Dpoint to test
modeLoopContainsPointModeallow to specify contains test type
Returns
ConvexHull2D(IEnumerable<Vector3D>)
compute convex hull using LoycCore https://github.com/qwertie/LoycCore
public static IEnumerable<Vector3D> ConvexHull2D(this IEnumerable<Vector3D> pts)
Parameters
ptsIEnumerable<Vector3D>
Returns
CoordTransform(DxfDocument, Func<Vector3D, Vector3D>)
public static IEnumerable<EntityObject> CoordTransform(this DxfDocument dxf, Func<Vector3D, Vector3D> transform)
Parameters
Returns
- IEnumerable<EntityObject>
CoordTransform(EntityObject, Func<Vector3D, Vector3D>, Vector3D?)
build a clone of the given entity with coord transformed accordingly given function.
public static EntityObject CoordTransform(this EntityObject eo, Func<Vector3D, Vector3D> transform, Vector3D? origin = null)
Parameters
Returns
- EntityObject
Debug(Vector3, string)
debug to console with optional prefix
public static Vector3 Debug(this Vector3 v, string prefix = "")
Parameters
Returns
- Vector3
vector
Debug(Vector4, string)
debug to console with optional prefix
public static Vector4 Debug(this Vector4 v, string prefix = "")
Parameters
Returns
- Vector4
vector
Decompose(Matrix4x4)
decompose given 4x4 matrix into scale, rotation, translation
public static (Vector3 translation, Quaternion rotation, Vector3 scale, bool success) Decompose(this Matrix4x4 m)
Parameters
Returns
DetectPlane(IEnumerable<Edge>, double)
public static Plane3D DetectPlane(this IEnumerable<Edge> edges, double tol)
Parameters
edgesIEnumerable<Edge>toldouble
Returns
DistinctKeepOrder(IEnumerable<Vector3D>, Vector3DEqualityComparer)
retrieve distinct of given vector set ensuring to maintain given order
public static IEnumerable<Vector3D> DistinctKeepOrder(this IEnumerable<Vector3D> vectors, Vector3DEqualityComparer cmp)
Parameters
vectorsIEnumerable<Vector3D>cmpVector3DEqualityComparer
Returns
DrawCube(DxfObject, Vector3D, double, Layer?)
Creates and add dxf entities for a 6 faces of a cube
public static IEnumerable<EntityObject> DrawCube(this DxfObject dxfObj, Vector3D center, double L, Layer? layer = null)
Parameters
Returns
- IEnumerable<EntityObject>
DrawCuboid(DxfObject, Vector3D, Vector3D, Layer?)
Creates and add dxf entities for 6 faces of a cuboid
public static IEnumerable<EntityObject> DrawCuboid(this DxfObject dxfObj, Vector3D center, Vector3D size, Layer? layer = null)
Parameters
Returns
- IEnumerable<EntityObject>
DrawStar(DxfObject, Vector3D, double, Layer?)
Creates and add dxf entities for a 3 axis of given length centered in given center point.
public static IEnumerable<EntityObject> DrawStar(this DxfObject dxfObj, Vector3D center, double L, Layer? layer = null)
Parameters
Returns
- IEnumerable<EntityObject>
DrawTimeline(DxfObject, List<(DateTime from, DateTime to)>, double, double, double, double, Func<DateTime, string>?)
public static IEnumerable<EntityObject> DrawTimeline(this DxfObject dxf, List<(DateTime from, DateTime to)> timeline, double textHeight = 2, double circleRadius = 1.5, double maxWidth = 180, double stopDays = 60, Func<DateTime, string>? dtStr = null)
Parameters
dxfDxfObjecttimelineList<(DateTime from, DateTime to)>textHeightdoublecircleRadiusdoublemaxWidthdoublestopDaysdoubledtStrFunc<DateTime, string>
Returns
- IEnumerable<EntityObject>
Entities(DxfDocument)
public static IEnumerable<EntityObject> Entities(this DxfDocument dxf)
Parameters
dxfDxfDocument
Returns
- IEnumerable<EntityObject>
EqualsTol(IEnumerable<Vector3D>, double, IEnumerable<Vector3D>)
checks two list of vectors are equals and with same order of elements
public static bool EqualsTol(this IEnumerable<Vector3D> lst, double tol, IEnumerable<Vector3D> other)
Parameters
lstIEnumerable<Vector3D>toldoubleotherIEnumerable<Vector3D>
Returns
EqualsTol(IEnumerable<(double, double)>, IEnumerable<(double, double)>, double, double)
compares two list tuples
public static bool EqualsTol(this IEnumerable<(double, double)> tuple_list1, IEnumerable<(double, double)> tuple_list2, double tol1, double tol2)
Parameters
tuple_list1IEnumerable<(double, double)>tuple_list2IEnumerable<(double, double)>tol1doubletol2double
Returns
EqualsTol(Vector3, double, Vector3)
public static bool EqualsTol(this Vector3 v, double tol, Vector3 other)
Parameters
Returns
EqualsTol(Vector3, double, Vector3)
public static bool EqualsTol(this Vector3 v, double tol, Vector3 other)
Parameters
vVector3toldoubleotherVector3
Returns
Explode(Insert)
public static IEnumerable<EntityObject> Explode(this Insert ins)
Parameters
insInsert
Returns
- IEnumerable<EntityObject>
Fmt(double, int, int)
format number with given decimals and total length aligning right
public static string Fmt(this double n, int dec, int size)
Parameters
Returns
- string
string representing given number formatted with given decimals and total length aligning right
Fmt(Matrix4x4, int, int)
matrix4x4 formatted print suitable for monospace font or terminal display
public static string Fmt(this Matrix4x4 m, int dec, int width = 10)
Parameters
Returns
- string
formatted text representation of given matrix
Fmt(float, int, int)
format number with given decimals and total length aligning right
public static string Fmt(this float n, int dec, int size)
Parameters
Returns
- string
string representing given number formatted with given decimals and total length aligning right
GetItem(Matrix4x4, int, int)
retrieve item at given row(0..3), col(0..3) of the matrix4x4
public static float GetItem(this Matrix4x4 m, int rowIdx, int colIdx)
Parameters
Returns
- float
matrix item
Intersect(IEnumerable<Geometry>, double, IEnumerable<Geometry>, GeomSegmentMode, GeomSegmentMode)
find intersection geometries resulting from all this geometries with all given geom2
public static IEnumerable<(Geometry intersectGeom, Geometry g1, Geometry g2)> Intersect(this IEnumerable<Geometry> _geom1, double tol, IEnumerable<Geometry> _geom2, GeomSegmentMode geom1SegmentMode = GeomSegmentMode.FromTo, GeomSegmentMode geom2SegmentMode = GeomSegmentMode.FromTo)
Parameters
_geom1IEnumerable<Geometry>toldoublelength tolerance
_geom2IEnumerable<Geometry>geom1SegmentModeGeomSegmentModeif geom1 item is Line3D specifies how to consider it
geom2SegmentModeGeomSegmentModeif geom2 item is Line3D specifies how to consider it
Returns
Intersect(IEnumerable<Line3D>, double, Line3D, GeomSegmentMode)
Find intersection points (0,1,2) of the given line with the given polygon TODO unit test
public static IEnumerable<Vector3D> Intersect(this IEnumerable<Line3D> polygonSegments, double tol, Line3D line, GeomSegmentMode segmentMode)
Parameters
polygonSegmentsIEnumerable<Line3D>toldoublelineLine3DsegmentModeGeomSegmentMode
Returns
Inverse(Matrix4x4)
retrieve inverse of given matrix
public static Matrix4x4 Inverse(this Matrix4x4 m)
Parameters
mMatrix4x44x4 matrix
Returns
- Matrix4x4
inverse of given matrix
Remarks
can gen exception
IsAClosedPoly(IEnumerable<Line3D>, double)
Preprocess segs with SortPoly if needed. Return the ordered segments poly or null if not a closed poly.
public static IEnumerable<Line3D>? IsAClosedPoly(this IEnumerable<Line3D> segs, double tol)
Parameters
segsIEnumerable<Line3D>toldouble
Returns
IsLinearIndependent(IEnumerable<Vector3D>)
states if given 3 vectors are linearly independent
public static bool IsLinearIndependent(this IEnumerable<Vector3D> vectors)
Parameters
vectorsIEnumerable<Vector3D>
Returns
- bool
true if given vector are linearly independent
Remarks
Length(IEnumerable<Vector3D>)
compute length of polyline from given seq_pts
public static double Length(this IEnumerable<Vector3D> seq_pts)
Parameters
seq_ptsIEnumerable<Vector3D>
Returns
MakeVertexToEdges(IEnumerable<Edge>, double)
public static Dictionary<Vector3D, List<Edge>> MakeVertexToEdges(this IEnumerable<Edge> edges, double tol)
Parameters
edgesIEnumerable<Edge>toldouble
Returns
Mean(IEnumerable<Vector3D>, bool)
mean of given vetor3d list note: if used to compute poly center enable skipFirstAtEnd
public static Vector3D Mean(this IEnumerable<Vector3D> lst, bool skipFirstAtEnd = false)
Parameters
lstIEnumerable<Vector3D>skipFirstAtEndbool
Returns
MergeColinearSegments(IEnumerable<Line3D>, double)
merge colinear overlapped segments into single result segments direction and order is not ensured pre: segs must colinear
public static IEnumerable<Line3D> MergeColinearSegments(this IEnumerable<Line3D> _segs, double tol)
Parameters
_segsIEnumerable<Line3D>toldouble
Returns
MidPoint(Polyline2D)
get the midpoint of the 3d polyline distance is computed over all segments
public static Vector3D? MidPoint(this Polyline2D poly)
Parameters
polyPolyline2D
Returns
MinDistance(IEnumerable<double>)
Return the min distance between two adiacent number given from all of the given ordered set of numbers.
public static double MinDistance(this IEnumerable<double> orderedNumbers)
Parameters
orderedNumbersIEnumerable<double>
Returns
- double
0 if empty set or 1 element. min distance otherwise.
MinMax(IEnumerable<double>)
retrieve min,max w/single sweep
public static (double min, double max) MinMax(this IEnumerable<double> input)
Parameters
inputIEnumerable<double>
Returns
ModelSpace(DxfDocument)
public static Block ModelSpace(this DxfDocument dxf)
Parameters
dxfDxfDocument
Returns
- Block
NormalizeAngle(double, double, double)
Normalize given angle(rad) into [maxRad-2PI,maxRad) range.
public static double NormalizeAngle(this double angle_rad, double maxRadExcluded = 6.283185307179586, double radTol = 1E-10)
Parameters
angle_raddoubleangle(rad) to normalize
maxRadExcludeddoublenormalization range (excluded) max value ( minimum will computed as max-2PI )
radToldoubleoverride rad tolerance
Returns
- double
angle normalized
Remarks
Normalized(Vector3)
normalize given vector
public static Vector3 Normalized(this Vector3 v)
Parameters
vVector3vector
Returns
- Vector3
normalized vector
Normalized(Vector4)
public static Vector4 Normalized(this Vector4 v)
Parameters
vVector4
Returns
Offset(IEnumerable<Vector3D>, double, double)
increase of decrease polygon points offseting ( this implementation uses Int64Map and clipper library )
public static IEnumerable<Vector3D> Offset(this IEnumerable<Vector3D> pts, double tol, double offset)
Parameters
ptsIEnumerable<Vector3D>toldoubleoffsetdouble
Returns
Offset(Polyline2D, double, Vector3D, double)
public static Polyline2D Offset(this Polyline2D lwp, double tol, Vector3D sideRefPt, double amount)
Parameters
Returns
- Polyline2D
OffsetGeoms(Polyline2D, double, Vector3D, double)
create offseted polygon from this one by offset of given offset amount toward given sideRefPt.
public static IEnumerable<Edge> OffsetGeoms(this Polyline2D lwp, double tol, Vector3D sideRefPt, double offset)
Parameters
lwpPolyline2Dthis polyline
toldoublelength tolerance
sideRefPtVector3Doffseted polygon will the one on the side nearest to this ref pt. The offseted polygon doesn't need to contains this point, its only used to disambiguate the side choose.
offsetdoubleoffset amount from this actual polyline toward offseted one.
Returns
- IEnumerable<Edge>
offseted polygon
Points(EntityObject)
public static IEnumerable<Vector3D> Points(this EntityObject eo)
Parameters
eoEntityObject
Returns
PolyPoints(IEnumerable<Line3D>)
retrieve s[0].from, s[1].from, ... s[n-1].from, s[n-1].to points
public static IEnumerable<Vector3D> PolyPoints(this IEnumerable<Line3D> segs)
Parameters
segsIEnumerable<Line3D>
Returns
PolyPoints(IEnumerable<Vector3D>, double, bool)
given a set of polygon pts, returns the enumeation of all pts so that the last not attach to the first ( if makeClosed = false ). Elsewhere it returns a last point equals the first ( makeClosed = true ).
public static IEnumerable<Vector3D> PolyPoints(this IEnumerable<Vector3D> pts, double tol, bool makeClosed = false)
Parameters
ptsIEnumerable<Vector3D>toldoublemakeClosedbool
Returns
PolygonSegments(IEnumerable<Vector3D>, double)
yields an ienumerable of polygon segments corresponding to the given polygon pts ( z is not considered ) works even last point not equals the first one
public static IEnumerable<Line3D> PolygonSegments(this IEnumerable<Vector3D> pts, double tol)
Parameters
ptsIEnumerable<Vector3D>toldouble
Returns
QCadScript(IEnumerable<Edge>, bool)
qcad script from edge enumerable
public static string QCadScript(this IEnumerable<Edge> edges, bool final = true)
Parameters
edgesIEnumerable<Edge>finalboolif true adds QQ
Returns
QCadScript(IEnumerable<Geometry>)
qcad script from geoms
public static string QCadScript(this IEnumerable<Geometry> geoms)
Parameters
geomsIEnumerable<Geometry>
Returns
QCadScript(Polyline2D, double)
qcad script from lwp
public static string QCadScript(this Polyline2D lwp, double tol)
Parameters
lwpPolyline2Dtoldouble
Returns
RadTol(double, double)
compute angle rad tolerance by given arc length tolerance as (lenTol / radius)
public static double RadTol(this double lenTol, double radius)
Parameters
Returns
RepeatFirstAtEnd(IEnumerable<Vector3D>, double)
given points a,b,c it will return a,b,c,a ( first is repeated at end ) it avoid to repeat first at end when latest point already equals the first one
public static IEnumerable<Vector3D> RepeatFirstAtEnd(this IEnumerable<Vector3D> pts, double tol)
Parameters
ptsIEnumerable<Vector3D>toldouble
Returns
Reversed(IEnumerable<Vector3D>)
retrieve reversed version of given point set ( used to convert ccw, cw )
public static IList<Vector3D> Reversed(this IEnumerable<Vector3D> pts)
Parameters
ptsIEnumerable<Vector3D>
Returns
Reversed(IList<Vector3D>)
retrieve reversed version of given point set ( used to convert ccw, cw )
public static IEnumerable<Vector3D> Reversed(this IList<Vector3D> pts)
Parameters
Returns
Segments(IEnumerable<Geometry>, double)
segments representation of given geometries if arc found a segment between endpoints returns
public static IEnumerable<Line3D> Segments(this IEnumerable<Geometry> geometry_block, double tol)
Parameters
geometry_blockIEnumerable<Geometry>toldoublelength tolerance
Returns
Set(Hatch, HatchSetterDelegate)
set hatch and boundary entities with given action
public static Hatch Set(this Hatch hatch, Ext.HatchSetterDelegate setter)
Parameters
hatchHatchsetterExt.HatchSetterDelegate
Returns
- Hatch
SetColor(EntityObject, AciColor)
public static EntityObject SetColor(this EntityObject eo, AciColor color)
Parameters
eoEntityObjectcolorAciColor
Returns
- EntityObject
SetLayer(IEnumerable<EntityObject>, Layer)
Set layer of given set of dxf entities
public static IEnumerable<EntityObject> SetLayer(this IEnumerable<EntityObject> ents, Layer layer)
Parameters
entsIEnumerable<EntityObject>layerLayer
Returns
- IEnumerable<EntityObject>
SetLayer(EntityObject, Layer)
public static EntityObject SetLayer(this EntityObject eo, Layer layer)
Parameters
eoEntityObjectlayerLayer
Returns
- EntityObject
SetX(Vector3, float)
create new Vector3 with given x overriden, others yz unchanged
public static Vector3 SetX(this Vector3 v, float x)
Parameters
Returns
- Vector3
changed vector
SetY(Vector3, float)
create new Vector3 with given y overriden, others xz unchanged
public static Vector3 SetY(this Vector3 v, float y)
Parameters
Returns
- Vector3
changed vector
SetZ(Vector3, float)
create new Vector3 with given z overriden, others xy unchanged
public static Vector3 SetZ(this Vector3 v, float z)
Parameters
Returns
- Vector3
changed vector
Similarity(double, double)
Test two numbers for similarity; the factor of similarity f = (max(x,y)-min(x,y)) / min(abs(x), abs(y)). Special cases:
- if x=y=0 returns 0
- if x=0 xor y=0 returns max(abs(x),abs(y)))/2
- if sign(x) != sign(y) returns StDevP(x,y)
public static double Similarity(this double x, double y)
Parameters
Returns
- double
similarity factor
SortCCW(IEnumerable<Vector3D>, double, CoordinateSystem3D)
sort the set of points in ccw order;
note that first returned point could not match the first point in the sequence ( for that use RouteFirst() ext )
public static IEnumerable<Vector3D> SortCCW(this IEnumerable<Vector3D> pts, double tol, CoordinateSystem3D cs)
Parameters
ptsIEnumerable<Vector3D>points
toldoublelength tolerance
csCoordinateSystem3DCS used with origin as rotation center to sort ccw points and BaseZ used as reference rotation axis ( points plane normal right-hand rotate around )
Returns
- IEnumerable<Vector3D>
input set of points ccw sorted
SortCCW(IEnumerable<Vector3D>, double, Vector3D, Vector3D)
sort the set of points in ccw order;
note that first returned point could not match the first point in the sequence ( for that use RouteFirst() ext )
public static IEnumerable<Vector3D> SortCCW(this IEnumerable<Vector3D> pts, double tol, Vector3D center, Vector3D refAxis)
Parameters
ptsIEnumerable<Vector3D>points
toldoublelength tolerance
centerVector3Drotation center to sort ccw points ( can use Mean() or Centroid() ext for closed polygon )
refAxisVector3Dreference rotation axis ( points plane normal right-hand rotate around )
Returns
- IEnumerable<Vector3D>
input set of points ccw sorted
SortCCW<T>(IEnumerable<T>, double, Func<T, Vector3D>, CoordinateSystem3D)
sort the set of templated points in ccw order;
note that first returned point could not match the first point in the sequence ( for that use RouteFirst() ext )
public static IEnumerable<T> SortCCW<T>(this IEnumerable<T> _tpts, double tol, Func<T, Vector3D> getPoint, CoordinateSystem3D cs)
Parameters
_tptsIEnumerable<T>templated points
toldoublelength tolerance
getPointFunc<T, Vector3D>function to extract Vector3D point from templated point
csCoordinateSystem3DCS used with origin as rotation center to sort ccw points and BaseZ used as reference rotation axis ( points plane normal right-hand rotate around )
Returns
- IEnumerable<T>
input set of templated points ccw sorted
Type Parameters
T
SortCCW<T>(IEnumerable<T>, double, Func<T, Vector3D>, Vector3D, Vector3D)
sort the set of templated points in ccw order;
note that first returned point could not match the first point in the sequence ( for that use RouteFirst() ext )
public static IEnumerable<T> SortCCW<T>(this IEnumerable<T> tpts, double tol, Func<T, Vector3D> getPoint, Vector3D center, Vector3D refAxis)
Parameters
tptsIEnumerable<T>templated points
toldoublelength tolerance
getPointFunc<T, Vector3D>function to extract Vector3D point from templated point
centerVector3Drotation center to sort ccw points ( can use Mean() or Centroid() ext for closed polygon )
refAxisVector3Dreference rotation axis ( points plane normal right-hand rotate around )
Returns
- IEnumerable<T>
input set of templated points ccw sorted
Type Parameters
T
Sqrt(Vector3D)
compute (Sqrt(v.x), Sqrt(v.y), Sqrt(v.z))
public static Vector3D Sqrt(this Vector3D v)
Parameters
vVector3Dinput vector
Returns
- Vector3D
sqrt(v)
StatNfos(IEnumerable<double>)
Compute some stat info about given number set using LinqStatistics
public static NumbersStatNfo StatNfos(this IEnumerable<double> numbers)
Parameters
numbersIEnumerable<double>
Returns
- NumbersStatNfo
a tuple containing stat informations about given number set
StringRepresentation(IEnumerable<Vector3D>)
array invariant string vector3d representation "(x1,y1,z2);(x2,y2,z2)"; an array of Vector3D can be rebuilt from string using Vector3D.FromStringArray
public static string StringRepresentation(this IEnumerable<Vector3D> pts)
Parameters
ptsIEnumerable<Vector3D>
Returns
Sum(IEnumerable<Vector3D>)
retrieve the sum of given vector list
public static Vector3D Sum(this IEnumerable<Vector3D> lst)
Parameters
lstIEnumerable<Vector3D>vector list
Returns
- Vector3D
sum of given vector list
TakeUntilAdjacent(IEnumerable<Line3D>, double, bool)
Return the input set of segments until an adjacency between one and next is found. It can rectify the versus of line (by default) if needed. Note: returned set references can be different if rectifyVersus==true
public static IEnumerable<Line3D> TakeUntilAdjacent(this IEnumerable<Line3D> segs, double tol, bool rectifyVersus = true)
Parameters
segsIEnumerable<Line3D>toldoublerectifyVersusbool
Returns
Tessellate(IEnumerable<Vector3D>)
tessellate given pts list using 1 contour in clockwise ordering see used tessellation library ( https://github.com/speps/LibTessDotNet )
public static IEnumerable<Triangle3D> Tessellate(this IEnumerable<Vector3D> _pts)
Parameters
_ptsIEnumerable<Vector3D>pts to tessellate in triangles
Returns
- IEnumerable<Triangle3D>
list of triangles
Thin(IEnumerable<double>, double, bool, bool)
retrieve given input set ordered with only distinct values after comparing through tolerance in this case result set contains only values from the input set (default) or rounding to given tol if maintain_original_values is false; if keep_ends true (default) min and max already exists at begin/end of returned sequence
public static List<double> Thin(this IEnumerable<double> input, double tol, bool keep_ends = true, bool maintain_original_values = true)
Parameters
inputIEnumerable<double>toldoublekeep_endsboolmaintain_original_valuesbool
Returns
ToArc3D(Arc, Vector3D?, double)
construct arc3 from given dxf arc
public static Arc3D ToArc3D(this Arc dxf_arc, Vector3D? start_vertex = null, double start_vertex_tol = 0)
Parameters
dxf_arcArcstart_vertexVector3Doptional start vertex allow to inject edge sense (used when explode from lwpolyline)
start_vertex_toldoublewhen use start_vertex argument this is the tol for equality test
Returns
ToCSV(IEnumerable<object>)
exports to a csv string some known fields note: not really a csv its a tab separated values for debug purpose just copy and paste
public static string ToCSV(this IEnumerable<object> lst)
Parameters
lstIEnumerable<object>
Returns
ToCadScript(IEnumerable<Line3D>)
public static string ToCadScript(this IEnumerable<Line3D> lines)
Parameters
linesIEnumerable<Line3D>
Returns
ToCircle3D(Circle)
build circle3d by provided dxf circle
public static Circle3D ToCircle3D(this Circle dxf_circle)
Parameters
dxf_circleCircle
Returns
ToCoordSequence(IEnumerable<Vector3D>)
from a list of vector3d retrieve x1,y1,z1,x2,y2,z2,... coord sequence
public static IEnumerable<double> ToCoordSequence(this IEnumerable<Vector3D> pts)
Parameters
ptsIEnumerable<Vector3D>
Returns
ToCoordString2D(IEnumerable<Vector3D>)
produce a string with x1,y1,x2,y2, ...
public static string ToCoordString2D(this IEnumerable<Vector3D> points)
Parameters
pointsIEnumerable<Vector3D>
Returns
ToCoordString3D(IEnumerable<Vector3D>)
produce a string with x1,y1,z1,x2,y2,z2, ...
public static string ToCoordString3D(this IEnumerable<Vector3D> points)
Parameters
pointsIEnumerable<Vector3D>
Returns
ToDVector3(Vector3)
convert System.Numerics.Vector3 to netdxf.Vector3
public static Vector3 ToDVector3(this Vector3 v)
Parameters
vVector3
Returns
- Vector3
ToDeg(Vector3)
convert given vector to degrees
public static Vector3 ToDeg(this Vector3 v)
Parameters
vVector3vector source ( radians )
Returns
- Vector3
vector ( degrees )
ToDxfLine(Line3D)
public static Line ToDxfLine(this Line3D line)
Parameters
lineLine3D
Returns
- Line
ToEulerAngles(Matrix4x4)
extract xyz rotation angles from given rotation matrix. Reference: Extracting Euler Angles from a Rotation Matrix by Mike Day
public static Vector3 ToEulerAngles(this Matrix4x4 rotation)
Parameters
rotationMatrix4x4rotation matrix
Returns
- Vector3
Vector3 with rotation angles(rad) around wcs xyz axes
Remarks
ToFace(Loop)
build face with given outer loop
public static Face ToFace(this Loop loop)
Parameters
loopLoop
Returns
ToFace(IEnumerable<Polyline2D>, double)
build planar face with given loops ( first is the outer ); input loop can be unordered ( loop with greather area will be considered as outer loop ); precondition: loops must lie on same plane
public static Face ToFace(this IEnumerable<Polyline2D> lwpolyline, double tol)
Parameters
lwpolylineIEnumerable<Polyline2D>toldouble
Returns
ToGeometries(Polyline2D, double)
extracs Arc3D, Line3D from given lwpolyline
public static IEnumerable<Geometry> ToGeometries(this Polyline2D lwpolyline, double tol)
Parameters
lwpolylinePolyline2Dtoldoublelength tolerance
Returns
ToHatch(IEnumerable<Geometry>, HatchPattern, bool)
public static Hatch ToHatch(this IEnumerable<Geometry> _geom, HatchPattern pattern, bool associative = true)
Parameters
_geomIEnumerable<Geometry>patternHatchPatternassociativebool
Returns
- Hatch
ToHatch(Polyline2D, HatchPattern, bool)
public static Hatch ToHatch(this Polyline2D lw, HatchPattern pattern, bool associative = true)
Parameters
lwPolyline2DpatternHatchPatternassociativebool
Returns
- Hatch
ToLine3D(Line)
public static Line3D ToLine3D(this Line line)
Parameters
lineLine
Returns
ToLoop(Polyline2D, double)
public static Loop ToLoop(this Polyline2D lwpolyline, double tol)
Parameters
lwpolylinePolyline2Dtoldouble
Returns
ToLwPolyline(IEnumerable<Geometry>, double, CoordinateSystem3D, bool)
build 2d dxf polyline. precondition: geom vertex must lie on the same plane note: use RepeatFirstAtEnd extension to build a closed polyline
public static Polyline2D ToLwPolyline(this IEnumerable<Geometry> _geom, double tol, CoordinateSystem3D cs, bool closed)
Parameters
_geomIEnumerable<Geometry>toldoublelength tolerance
csCoordinateSystem3Dlw CS
closedbool
Returns
- Polyline2D
ToNVector3(Vector3)
convert netdxf.Vector3 to System.Numerics.Vector3 ( double cast to float )
public static Vector3 ToNVector3(this Vector3 v)
Parameters
vVector3
Returns
ToPlane(Polyline2D)
public static Plane3D ToPlane(this Polyline2D lwpolyline)
Parameters
lwpolylinePolyline2D
Returns
ToPolyline(IEnumerable<Vector3D>, bool)
build 3d dxf polyline note: use RepeatFirstAtEnd extension to build a closed polyline
public static Polyline3D ToPolyline(this IEnumerable<Vector3D> pts, bool isClosed = true)
Parameters
ptsIEnumerable<Vector3D>isClosedbool
Returns
- Polyline3D
ToRad(Vector3)
convert given vector to radians
public static Vector3 ToRad(this Vector3 v)
Parameters
vVector3vector source ( degrees )
Returns
- Vector3
vector ( radians )
ToTriangle3D(IEnumerable<Vector3D>)
public static Triangle3D ToTriangle3D(this IEnumerable<Vector3D> pts)
Parameters
ptsIEnumerable<Vector3D>
Returns
ToVector2(Vector4)
create vector2 from vector4 discarding z, w
public static Vector2 ToVector2(this Vector4 v)
Parameters
vVector4vector4 input
Returns
- Vector2
vector2
ToVector3(Vector4)
create vector3 from vector4 discarding w
public static Vector3 ToVector3(this Vector4 v)
Parameters
vVector4vector4 input
Returns
- Vector3
vector3
ToVector3D(Vector3)
convert given vector3 to vector3d
public static Vector3D ToVector3D(this Vector3 v)
Parameters
vVector3vector3
Returns
- Vector3D
vector3d
ToVector3D(Vector4)
convert given Vector4 to Vector3D ( discarding w )
public static Vector3D ToVector3D(this Vector4 v)
Parameters
vVector4Vector4
Returns
- Vector3D
Vector3D
Transform(Vector3, Matrix4x4)
public static Vector3 Transform(this Vector3 v, Matrix4x4 m)
Parameters
Returns
Transform(Vector4, Matrix4x4)
public static Vector4 Transform(this Vector4 v, Matrix4x4 m)
Parameters
Returns
Union(IEnumerable<BBox3D>)
union of bboxes
public static BBox3D Union(this IEnumerable<BBox3D> bboxes)
Parameters
bboxesIEnumerable<BBox3D>
Returns
Vector3DCoords(Polyline2D)
enumerate as Vector3D given dxf lwpolyline vertexes
public static IEnumerable<Vector3D> Vector3DCoords(this Polyline2D lwp)
Parameters
lwpPolyline2D
Returns
Vector3DCoords(Polyline3D)
enumerate as Vector3D given dxf polyline vertexes
public static IEnumerable<Vector3D> Vector3DCoords(this Polyline3D pl)
Parameters
plPolyline3D
Returns
Vertexes(IEnumerable<Geometry>, double)
vertexes from given set of geometries
public static IEnumerable<Vector3D> Vertexes(this IEnumerable<Geometry> _geometry_block, double tol)
Parameters
_geometry_blockIEnumerable<Geometry>toldoublelength tolerance
Returns
WeightedDistribution(IEnumerable<double>, int)
retrieve a list of N pairs (value,presence) with value between min and max of inputs and presence between 0..1 that represents the percent of presence of the value
examples:
inputs = ( 1, 2, 3 ), N = 3 results: ( (1, .33), (2, .33), (3, .33) )
inputs = ( 1, 2.49, 3), N = 3 results: ( (1, .33), (2, .169), (3, .497) )
inputs = ( 1, 2, 3), N = 4 results: ( (1, .33), (1.6, .16), (2.3, .16), (3, .33) )
public static (double off, double weight)[] WeightedDistribution(this IEnumerable<double> inputs, int N)
Parameters
inputsIEnumerable<double>Nint
Returns
XYArea(IEnumerable<Vector3D>, double)
(abs) Area of a polygon (does not consider z). note: points must ccw ordered. https://en.wikipedia.org/wiki/Centroid
public static double XYArea(this IEnumerable<Vector3D> pts, double tol)
Parameters
ptsIEnumerable<Vector3D>toldouble
Returns
XYCentroid(IEnumerable<Vector3D>, double)
Centroid of a polygon (does not consider z). note: points must ccw ordered. use overloaded method if signed area already computed. https://en.wikipedia.org/wiki/Centroid
public static Vector3D XYCentroid(this IEnumerable<Vector3D> pts, double tol)
Parameters
ptsIEnumerable<Vector3D>toldouble
Returns
XYCentroid(IEnumerable<Vector3D>, double, double)
Centroid of a polygon (does not consider z). note: points must ccw ordered. https://en.wikipedia.org/wiki/Centroid
public static Vector3D XYCentroid(this IEnumerable<Vector3D> _pts, double tol, double signed_area)
Parameters
_ptsIEnumerable<Vector3D>toldoublesigned_areadouble
Returns
XYClosedPolys(IEnumerable<Line3D>, double, int)
build polygons from given list of 2d segments by intersecting segments. (does not consider z)
public static IEnumerable<IReadOnlyList<Vector3D>> XYClosedPolys(this IEnumerable<Line3D> segs, double tol, int polyMaxPoints = 0)
Parameters
segsIEnumerable<Line3D>toldoublepolyMaxPointsint
Returns
XYSignedArea(IEnumerable<Vector3D>, double)
(signed) Area of a polygon (does not consider z); note: points must ccw ordered. https://en.wikipedia.org/wiki/Centroid
public static double XYSignedArea(this IEnumerable<Vector3D> _pts, double tol)
Parameters
_ptsIEnumerable<Vector3D>toldouble
Returns
ZapDuplicates(IEnumerable<Vector3D>, Vector3DEqualityComparer)
return pts (maintaining order) w/out duplicates
public static IEnumerable<Vector3D> ZapDuplicates(this IEnumerable<Vector3D> pts, Vector3DEqualityComparer cmp)
Parameters
ptsIEnumerable<Vector3D>cmpVector3DEqualityComparer
Returns
ZapDuplicates(IEnumerable<Vector3D>, double)
return pts (maintaining order) w/out duplicates use the other overloaded method if already have a vector 3d equality comparer
public static IEnumerable<Vector3D> ZapDuplicates(this IEnumerable<Vector3D> pts, double tol)
Parameters
ptsIEnumerable<Vector3D>toldouble