public Wire(Scene scene, Line wire, Component input, Component output) : // TODO: Need to add two more checks for appropriate missing output or input.
            base(ComponentType.Wire, null, 3)
        {
            inHitboxes = new InHitbox[inputs.Length];
            hitbox     = new ComponentHitbox();

            Scene = scene;

            if (input != null && output != null)
            {
                inputs[0] = new List <Component>(1)
                {
                    input
                };

                input.outputs.Add(this);

                outputs = new List <Component>(1)
                {
                    output
                };

                OutConnected = scene.WireOutputHitbox;
                InConnected  = scene.WireInputHitbox;
                output.inputs[InConnected.AttachedInputIndex].Add(this);

                inHitboxes[0] = new InHitbox(OutConnected.Position, this, (int)(scene.ScaleFactor * 5f), 0);
                outHitbox     = new OutHitbox(InConnected.Position, this, (int)(scene.ScaleFactor * 5f), 0);
            }

            if (input != null && output == null)
            {
                inputs[0] = new List <Component>(1)
                {
                    input
                };

                input.outputs.Add(this);
                OutConnected = scene.WireOutputHitbox;

                inHitboxes[0] = new InHitbox(OutConnected.Position, this, (int)(scene.ScaleFactor * 5f), 0);
                outHitbox     = new OutHitbox(wire.points[1], this, (int)(scene.ScaleFactor * 5f), 0);
            }

            if (input == null && output != null)
            {
                outputs = new List <Component>(1)
                {
                    output
                };

                InConnected = scene.WireInputHitbox;
                output.inputs[InConnected.AttachedInputIndex].Add(this);

                inHitboxes[0] = new InHitbox(wire.points[0], this, (int)(scene.ScaleFactor * 5f), 0);
                outHitbox     = new OutHitbox(InConnected.Position, this, (int)(scene.ScaleFactor * 5f), 0);
            }

            lines     = new Line[1];
            lines[0]  = wire;
            startLine = new Line((1 / scene.ScaleFactor) * wire.points[0], (1 / scene.ScaleFactor) * wire.points[1]);

            scene.Update();
            Process(scene);
        }
        public override bool Select(Point location, Scene sender)
        {
            Point segment = lines[0].points[1] - lines[0].points[0];
            Point toStart = lines[0].points[0] - location;
            Point toEnd   = lines[0].points[1] - location;

            float segmentLength = Vector.Length(segment);

            float t = -(segment * toStart) / (segmentLength * segmentLength);

            float distance  = 999;
            float threshold = 3;

            OutHitbox o = OutputClicked(location);
            InHitbox  i = InputClicked(location);

            bool result = false;

            if (t > 0 && t < 1)
            {
                float TS      = Vector.Length(toStart);
                float SEdotTS = segment * toStart;

                distance = TS * TS - ((SEdotTS * SEdotTS) / (segmentLength * segmentLength));

                if (distance <= threshold * threshold)
                {
                    result = true;
                }
            }

            if (sender.WirePlacementMode)
            {
                if (sender.WireInput && i != null)
                {
                    result = false;

                    foreach (Component component in inputs[0])
                    {
                        if (component is Wire && component == sender.WireInputComponent)
                        {
                            result = true;
                        }
                    }

                    if (!result)
                    {
                        sender.WireOutputComponent = this;
                        sender.WireInputHitbox     = i;
                    }

                    result = false;
                }
                else if (!sender.WireInput && o != null)
                {
                    result = false;
                    sender.WireInputComponent = this;
                    sender.WireOutputHitbox   = o;
                }
            }
            else if (o != null)
            {
                result = false;
                sender.WireMode(location, this, o, true);
            }

            return(result);
        }