/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{multiplyOpacity as e}from"../../../core/colorUtils.js";import{destroyHandle as i}from"../../../core/handleUtils.js";import{lerp as n}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as t}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{projectVectorToVector as o}from"../../../geometry/projection/projectVectorToVector.js";import{onTheGroundElevationInfo as r,absoluteHeightElevationInfo as l}from"../../../support/elevationInfoUtils.js";import{vectorToRender as a}from"./support/viewUtils.js";import{ExtendedLineVisualElement as s}from"./visualElements/ExtendedLineVisualElement.js";import{ParallelLineVisualElement as c}from"./visualElements/ParallelLineVisualElement.js";import{PointVisualElement as d}from"./visualElements/PointVisualElement.js";import{RightAngleQuadVisualElement as p}from"./visualElements/RightAngleQuadVisualElement.js";import{toDehydratedPoint as u,isTarget as m,withSelfSnappingZ as f}from"../../interactive/sketch/normalizedPoint.js";import{defaults as g}from"../../interactive/snapping/Settings.js";import{SnappingVisualizer as v}from"../../interactive/snapping/SnappingVisualizer.js";import{LineSnappingHint as h}from"../../interactive/snapping/hints/LineSnappingHint.js";class C extends v{sortUniqueHints(e){return e.sort((e,i)=>(i instanceof h?i.length:0)-(e instanceof h?e.length:0))}visualizeIntersectionPoint(e,n){const{spatialReference:t,view:o}=n,a=w(n);return i(new d({view:o,primitive:"circle",geometry:u(e.intersectionPoint,t),elevationInfo:e.isDraped?r:l,size:20,outlineSize:2,color:a.intersectionPointColor,outlineColor:a.intersectionPointOutlineColor,pixelSnappingEnabled:!1,isDecoration:!0,attached:!0}))}visualizePoint(e,n){const{view:t,spatialReference:o}=n,r=w(n),l=x(e.point,e.domain,n);return i(new d({view:t,primitive:"circle",geometry:u(l,o),elevationInfo:E(e),size:20,outlineSize:2,color:r.pointColor,outlineColor:r.pointOutlineColor,pixelSnappingEnabled:!1,isDecoration:!0,attached:!0}))}visualizeLine(e,n){const{view:t,spatialReference:o}=n,r=w(n),l=x(e.lineStart,e.domain,n),a=x(e.lineEnd,e.domain,n);return i(j(e.type,l,a,o,E(e),t,r,e.isDraped,e.fadeLeft,e.fadeRight))}visualizeParallelSign(e,t){const{view:o,spatialReference:r}=t,l=w(t),{isDraped:a}=e,s=E(e),d=x(e.lineStart,e.domain,t),p=x(e.lineEnd,e.domain,t),u=D(d,r,s,o,a),m=D(p,r,s,o,a),f=n(m,u,m,.5),v=new c({view:o,attached:!1,offset:g.parallelLineHintOffset,length:g.parallelLineHintLength,width:g.parallelLineHintWidth,color:l.parallelSignColor,location:f,renderOccluded:a?4:16,isDraped:a,renderGroup:3,isDecoration:!0});return v.setDirectionFromPoints(u,f),v.attached=!0,i(v)}visualizeRightAngleQuad(e,n){const{view:t,spatialReference:o}=n,r=w(n),l=E(e),{isDraped:a}=e,s=x(e.previousVertex,e.domain,n),c=x(e.centerVertex,e.domain,n),d=x(e.nextVertex,e.domain,n),u=D(s,o,l,t,a),m=D(c,o,l,t,a),f=D(d,o,l,t,a);return i(new p({view:t,attached:!0,color:a?r.rightAngleColorDraped:r.rightAngleColor,renderOccluded:a?4:2,outlineRenderOccluded:a?4:16,outlineColor:r.rightAngleOutlineColor,outlineSize:g.rightAngleHintOutlineSize,size:g.rightAngleHintSize,isDraped:a,geometry:{previous:u,center:m,next:f},renderGroup:3,isDecoration:!0}))}}function w(i){const{effectiveTheme:n}=i.view,t=n.accentColor.toUnitRGBA(),o=[0,0,0,0];return{intersectionPointColor:o,intersectionPointOutlineColor:t,pointColor:o,pointOutlineColor:t,lineColor:t,lineOutlineColor:void 0,parallelSignColor:t,rightAngleColor:t,rightAngleColorDraped:e(n.accentColor,.5).toUnitRGBA(),rightAngleOutlineColor:t}}function x(e,i,{selfSnappingZ:n,view:t,spatialReference:o}){return 2&i&&m(e)&&null!=n?f(e,n,t,o):e}function E(e){return e.isDraped?r:l}function j(e,i,n,t,o,r,l,a=!1,c=!0,d=!0){const p=D(i,t,o,r,a),u=D(n,t,o,r,a),m=new s({view:r,extensionType:3,start:p,end:u,isDraped:a,color:l.lineColor,renderOccluded:a?4:16,renderGroup:3,isDecoration:!0});switch(e){case 0:m.width=g.lineHintWidthTarget,m.fadedExtensions={start:0,end:g.lineHintFadedExtensions};break;case 2:m.width=g.lineHintWidthReference,m.fadedExtensions={start:0,end:0};break;case 1:m.width=g.lineHintWidthReference,m.fadedExtensions={start:c?g.lineHintFadedExtensions:0,end:d?g.lineHintFadedExtensions:0}}return m.attached=!0,m}function D(e,i,n,r,l){const s=t();if(l){const n=r.overlayManager.spatialReference;o(e,i,s,n)}else a(e,i,n,r,s);return s}export{C as SnappingVisualizer3D};
