public static bool IsOutside(this Vector2 point, Polygon poly) { var p = new IntPoint(point.X, point.Y); return(Clipper.PointInPolygon(p, poly.ToClipperPath()) != 1); }
public bool IsOutside(Vector2 point) { var p = new IntPoint(point.X, point.Y); return(Clipper.PointInPolygon(p, ToClipperPath()) != 1); }
/// <summary> /// Determines whether the specified polyline is inside. /// </summary> /// <param name="polyline">The polyline.</param> /// <param name="point">The point.</param> /// <param name="pln">The PLN.</param> /// <param name="tolerance">The tolerance.</param> /// <returns></returns> public static int IsInside(this Polyline polyline, Point3d point, Plane pln, Double tolerance) { return(Clipper.PointInPolygon(point.ToIntPoint2D(pln, tolerance), polyline.ToPath2D(pln, tolerance))); }
public int PointInPolygon(Vector2 point) { var p = new IntPoint(point.X, point.Y); return(Clipper.PointInPolygon(p, ToClipperPath())); }
/// <summary> /// Checks if the point is outside of polygon /// </summary> /// <param name="val">Polygon to check</param> /// <param name="point">Point to check</param> /// <returns>true if point is outside of polygon</returns> public static bool IsOutside(this Geometry.Polygon val, Vector2 point) { var p = new IntPoint(point.X, point.Y); return(Clipper.PointInPolygon(p, val.ToClipperPath()) != 1); }
public static bool IsInsidePolygon(this Vector2 point, List <Vector2> points) { return(Clipper.PointInPolygon(new IntPoint(point.X, point.Y), points.ToClipperPath()) == 1); }
/// <summary> /// Gets the Isovist polygon. /// </summary> /// <param name="vantagePoint">The vantage point.</param> /// <param name="viewDepth">The view depth.</param> /// <param name="edges">The edges.</param> /// <returns>BarrierPolygons.</returns> public BarrierPolygon IsovistPolygon(UV vantagePoint, double viewDepth, HashSet <UVLine> edges) { /*first and expand and shrink operation is performed to merge the shadowing edges*/ double expandShrinkFactor = Math.Pow(10.0, this.PolygonalBooleanPrecision) * UnitConversion.Convert(0.075, Length_Unit_Types.FEET, UnitType); //offsetting the excluded area of each edge INTPolygons offsetedPolygons = new INTPolygons(); ClipperOffset clipperOffset = new ClipperOffset(); foreach (UVLine edgeItem in edges) { clipperOffset.AddPath(this.excludedArea(vantagePoint, viewDepth + 1, edgeItem), ClipperLib.JoinType.jtMiter, EndType.etClosedPolygon); INTPolygons plygns = new INTPolygons(); clipperOffset.Execute(ref plygns, expandShrinkFactor); offsetedPolygons.AddRange(plygns); clipperOffset.Clear(); } //Unioning the expanded exclusions INTPolygons offsetUnioned = new INTPolygons(); Clipper c = new Clipper(); c.AddPaths(offsetedPolygons, PolyType.ptSubject, true); c.Execute(ClipType.ctUnion, offsetUnioned, PolyFillType.pftNonZero, PolyFillType.pftNonZero); //shrink the polygons to retain their original size INTPolygons results = new INTPolygons(); clipperOffset.Clear(); clipperOffset.AddPaths(offsetUnioned, JoinType.jtMiter, EndType.etClosedPolygon); clipperOffset.Execute(ref results, -expandShrinkFactor); clipperOffset.Clear(); offsetUnioned.Clear(); /* * What ever is a hole in the resulting mereged polygon is the visibility polygon * Now we classify the polygons based on being a hole or not */ //filtering out the holes that do not include the center INTPolygons holesNOT = new INTPolygons(); INTPolygons holesIncludingCenter = new INTPolygons(); IntPoint iCenter = ConvertUVToIntPoint(vantagePoint); foreach (INTPolygon item in results) { if (!Clipper.Orientation(item)) { if (Clipper.PointInPolygon(iCenter, item) == 1) { holesIncludingCenter.Add(item); } } else { holesNOT.Add(item); } } if (holesIncludingCenter.Count == 0) { //there is no hole. The shadow polygones should clip the potential field of visibility (i.e. circle) by an subtraction operation INTPolygon circle = createCircle(vantagePoint, viewDepth); //subtraction c.Clear(); c.AddPath(circle, PolyType.ptSubject, true); c.AddPaths(holesNOT, PolyType.ptClip, true); INTPolygons isovistPolygon = new INTPolygons(); c.Execute(ClipType.ctDifference, isovistPolygon); //searching for a polygon that includes the center foreach (INTPolygon item in isovistPolygon) { if (Clipper.PointInPolygon(iCenter, item) == 1) { BarrierPolygon isovist = this.ConvertINTPolygonToBarrierPolygon(item); results = null; c = null; clipperOffset = null; offsetedPolygons = null; circle = null; holesNOT = null; holesIncludingCenter = null; isovistPolygon = null; return(isovist); } } MessageBox.Show(string.Format("Isovist not found!\nNo hole detected\n{0} polygons can be isovist", isovistPolygon.Count.ToString())); } else if (holesIncludingCenter.Count == 1) { INTPolygons isovistPolygon = holesIncludingCenter; foreach (INTPolygon item in isovistPolygon) { if (Clipper.PointInPolygon(iCenter, item) == 1) { item.Reverse(); BarrierPolygon isovist = this.ConvertINTPolygonToBarrierPolygon(item); results = null; c = null; clipperOffset = null; offsetedPolygons = null; holesNOT = null; holesIncludingCenter = null; isovistPolygon = null; return(isovist); } } MessageBox.Show(string.Format("Isovist not found!\nOne hole detected\n{0} polygons can be isovist", isovistPolygon.Count.ToString())); } else if (holesIncludingCenter.Count > 1) { MessageBox.Show("Isovist not found!\nMore than one hole found that can include the vantage point"); } return(null); }
/// <summary> /// Calculates whether the specified point is inside this element. /// </summary> /// <param name="point">The point.</param> /// <returns>True if the point is inside the element, false otherwise.</returns> public override bool Inside(Point point) { return(Clipper.PointInPolygon((TPoint)point, this.GetPath()) != 0); // -1 and +1 are fine, 0 is not. }
// GENERATE LINEAR_REPEATER public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { //Debug.Log("repeaterToolU="+repeaterToolU+", repeaterToolV="+repeaterToolV); //Debug.Log("LINEAR REPEATER: Gentrate"); if (parametricObject == null || !parametricObject.isActive) { return(null); } if (repeaterToolU == null && repeaterToolV == null) { return(null); } preGenerate(); repeaterTool = (zAxis) ? repeaterToolV : repeaterToolU; repeaterTool = repeaterToolU; //Terrain terrain = Terrain.activeTerrain; // NODE_MESH AXParametricObject nodeSrc_po = null; GameObject nodePlugGO = null; if (nodeSrc_p != null) { nodeSrc_po = nodeSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { nodePlugGO = nodeSrc_po.generator.generate(true, initiator_po, isReplica); } } // CELL_MESH AXParametricObject cellSrc_po = null; GameObject cellPlugGO = null; if (cellSrc_p != null) { cellSrc_po = cellSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { cellPlugGO = cellSrc_po.generator.generate(true, initiator_po, isReplica); } } // BAY_SPAN AXParametricObject spanSrc_po = null; GameObject spanPlugGO = null; if (spanUSrc_p != null) { spanSrc_po = spanUSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { spanPlugGO = spanSrc_po.generator.generate(true, initiator_po, isReplica); } } if (nodeSrc_po == null && spanSrc_po == null && cellSrc_po == null) { if (P_Output != null) { P_Output.meshes = null; } return(null); } GameObject go = null; if (makeGameObjects && !parametricObject.combineMeshes) { go = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject); } Paths boundingSolids = null; Paths boundingHoles = null; List <AXMesh> ax_meshes = new List <AXMesh>(); Matrix4x4 localPlacement_mx = Matrix4x4.identity; // ----------------------------------- int max_reps = 150; int cellsU = Mathf.Clamp(repeaterTool.cells, 1, max_reps); float actualBayU = repeaterTool.actualBay; if (float.IsNaN(actualBayU)) { return(null); } shiftU = -cellsU * actualBayU / 2; AXMesh tmpMesh; // BAY SPAN // Spanners are meshers that get replicated and sized to fit the bay... // prepare mesh to iterate in each direction List <AXMesh> ax_meshes_X = new List <AXMesh>(); if (spanUSrc_p != null) { ax_meshes_X = spanUSrc_p.meshes; } /* NEED TO INTEGRATE THIS BACK IN IN THE FUTRE... * if (cell_center_source != null) * { * // Y-AXIS * // For now, only set the boundaries. * // Perhaps later, may want to set other like controls as in Replicant * // 1. cache source object * cell_center_source.cacheParameterValues(); * * * * //bay_center_source.propagateParameterByBinding(1, bayx); * //bay_center_source.propagateParameterByBinding(3, bayz); * * // 2. re_generate with temporary values set by this Replicant * cell_center_source.generateOutputNow (makeGameObjects, parametricObject); * * // 3. Now that the bay_span_source has been regenerted, grab the meshes from the input sources and add them here * AXParameter bc_output_p = cell_center_source.getParameter("Output Mesh"); * foreach (AXMesh amesh in bc_output_p.meshes) * ax_meshes_Y.Add (amesh.Clone(amesh.transMatrix)); * * // 4. restore source object; as though we were never here! * cell_center_source.revertParametersFromCache(); * * } */ // BOUNDING int boundingObjectCount = 0; if (nodeSrc_po != null && nodeSrc_p.meshes != null) { boundingObjectCount += cellsU + 1; if (!doFirstNode) { boundingObjectCount--; } if (!doLastNode) { boundingObjectCount--; } } else if (cellSrc_p != null && cellSrc_p.meshes != null) { boundingObjectCount += cellsU; } if (spanUSrc_p != null && spanUSrc_p.meshes != null) { boundingObjectCount += cellsU; } CombineInstance[] boundsCombinator = new CombineInstance[boundingObjectCount]; // FOR EACH ADDRESS for (int i = 0; i <= cellsU; i++) { //Debug.Log("["+i+"] i*actualBay="+i*actualBay+", perval="+perlval); if (boundingSolids != null) { IntPoint ip = new IntPoint((i * repeaterToolU.actualBay + shiftU) * AXGeometryTools.Utilities.IntPointPrecision, 0); bool exclude = true; if (boundingSolids != null) { foreach (Path path in boundingSolids) { if (Clipper.PointInPolygon(ip, path) == 1 && Clipper.Orientation(path)) { exclude = false; break; } } } if (boundingHoles != null) { foreach (Path hole in boundingHoles) { if (Clipper.PointInPolygon(ip, hole) == 1) { exclude = true; break; } } } if (exclude) { continue; } } //Debug.Log(" ** ** ** * " + nodeSrc_p.meshes); // NODES if (nodeSrc_po != null && nodeSrc_p.meshes != null) { // Debug.Log("nodeSrc_po.getLocalAlignMatrix()"+nodeSrc_po.getLocalAlignMatrix()); if ((i > 0 && i < cellsU) || (i == 0 && doFirstNode) || (i == (cellsU) && doLastNode)) { string this_address = "node_" + i; int ni = doFirstNode ? i : i - 1; // LOCAL_PLACEMENT // localPlacement_mx = localNodeMatrixFromAddress(i); if (float.IsNaN(localPlacement_mx.m00)) { continue; } // AX_MESHES for (int mi = 0; mi < nodeSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = nodeSrc_p.meshes [mi]; //tmpMesh = dep_amesh.CloneTransformed (localPlacement_mx * dep_amesh.transMatrix); tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING MESHES boundsCombinator[ni].mesh = nodeSrc_po.boundsMesh; boundsCombinator[ni].transform = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment; // GAME_OBJECTS if (nodePlugGO != null && makeGameObjects && !parametricObject.combineMeshes) { //Matrix4x4 mx = localPlacement_mx * parametricObject.getTransMatrix() * source.getTransMatrix(); //Debug.Log(nodeSrc_po.getLocalMatrix()); Matrix4x4 mx = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(nodePlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * jitterScale.x, copyGO.transform.localScale.y * jitterScale.y, copyGO.transform.localScale.z * jitterScale.z); AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; } copyGO.name = copyGO.name + "_" + this_address; copyGO.transform.parent = go.transform; } } } // \NODES // CELL CENTERS if (cellSrc_p != null && cellSrc_p.meshes != null && i < cellsU) { string this_address = "cell_" + i; //Debug.Log("Here"); // LOCAL_PLACEMENT localPlacement_mx = localCellMatrixFromAddress(i); // ACTUAL MESHES for (int mi = 0; mi < cellSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = cellSrc_p.meshes [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING MESHES boundsCombinator[i].mesh = cellSrc_po.boundsMesh; boundsCombinator[i].transform = localPlacement_mx * cellSrc_po.generator.localMatrixWithAxisRotationAndAlignment;; // GAME_OBJECTS if (cellPlugGO != null && makeGameObjects && !parametricObject.combineMeshes) { //Matrix4x4 mx = localPlacement_mx * parametricObject.getTransMatrix() * source.getTransMatrix(); Matrix4x4 mx = localPlacement_mx * cellSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(cellPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * jitterScale.x, copyGO.transform.localScale.y * jitterScale.y, copyGO.transform.localScale.z * jitterScale.z); AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; } copyGO.name = copyGO.name + "_" + this_address; copyGO.transform.parent = go.transform; //Debug.Log("LINEAR: " + axgo.consumerAddress); } } // \CELLS // SPANS if (spanUSrc_p != null && spanUSrc_p.meshes != null && i < cellsU) { string this_address = "spanU_" + i; // X-AXIS // LOCAL_PLACEMENT localPlacement_mx = localCellMatrixFromAddress(i); // AX_MESHES // AX_MESHES for (int mi = 0; mi < ax_meshes_X.Count; mi++) { AXMesh dep_amesh = ax_meshes_X [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING MESHES boundsCombinator[i].mesh = spanUSrc_po.boundsMesh; boundsCombinator[i].transform = localPlacement_mx * spanUSrc_po.generator.localMatrixWithAxisRotationAndAlignment; // GAME_OBJECTS if (spanPlugGO != null && makeGameObjects && !parametricObject.combineMeshes) { Matrix4x4 mx = localPlacement_mx * spanSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(spanPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * jitterScale.x, copyGO.transform.localScale.y * jitterScale.y, copyGO.transform.localScale.z * jitterScale.z); AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; } copyGO.name = copyGO.name + "_" + this_address; copyGO.transform.parent = go.transform; } } // \SPANS } //i GameObject.DestroyImmediate(nodePlugGO); GameObject.DestroyImmediate(cellPlugGO); GameObject.DestroyImmediate(spanPlugGO); parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica); setBoundsWithCombinator(boundsCombinator); // Turn ax_meshes into GameObjects if (makeGameObjects) { if (parametricObject.combineMeshes) { go = parametricObject.makeGameObjectsFromAXMeshes(ax_meshes, true); } Matrix4x4 tmx = parametricObject.getLocalMatrix(); go.transform.rotation = AXUtilities.QuaternionFromMatrix(tmx); go.transform.position = AXUtilities.GetPosition(tmx); go.transform.localScale = parametricObject.getLocalScaleAxisRotated(); //AXUtilities.GetScale(tmx); return(go); } return(null); }